Index: Lib/email/test/data/msg_45.txt =================================================================== --- Lib/email/test/data/msg_45.txt (revision 0) +++ Lib/email/test/data/msg_45.txt (revision 0) @@ -0,0 +1,24 @@ +MIME-Version: 1.0 +Content-type: multipart/mixed; boundary="boundary" + +This is a message with multiple parts in MIME format. +--boundary +X-Appcfg-File: static/foo%2Bbar +X-Appcfg-Hash: 864f52dc_bf5d1a45_15e2b611_29746d47_835e27e2 +Content-Type: application/octet-stream +Content-Length: 6 +Content-Transfer-Encoding: 8bit + +echo + +--boundary +X-Appcfg-File: static/foo%2Bbar +X-Appcfg-Hash: 864f52dc_bf5d1a45_15e2b611_29746d47_835e27e2 +Content-Type: application/octet-stream +Content-Length: 6 +Content-Transfer-Encoding: 8bit + +echo + +--boundary-- + Index: Lib/email/test/test_email.py =================================================================== --- Lib/email/test/test_email.py (revision 74440) +++ Lib/email/test/test_email.py (working copy) @@ -179,6 +179,18 @@ self.assertRaises(Errors.HeaderParseError, msg.set_boundary, 'BOUNDARY') + def test_nl_before_boundary_belongs_to_boundary(self): + eq = self.assertEqual + msg = self._msgobj('msg_45.txt') + # The first subpart just contains the line 'echo' followed by + # a blank line, so by RFC 2046 that blank line nl belongs to the + # boundary. + eq(msg.get_payload(0).get_payload(), "echo\n") + # The second subpart has a \r before the newline following the + # echo. Issue 6681 was that this caused two newlines to get + # swallowed instead of just the last one before the boundary. + eq(msg.get_payload(1).get_payload(), "echo\r\n") + def test_get_decoded_payload(self): eq = self.assertEqual msg = self._msgobj('msg_10.txt') Index: Lib/email/feedparser.py =================================================================== --- Lib/email/feedparser.py (revision 74440) +++ Lib/email/feedparser.py (working copy) @@ -366,7 +366,7 @@ else: payload = self._last.get_payload() if isinstance(payload, basestring): - mo = NLCRE_eol.search(payload) + mo = NLCRE_eol.search(payload[-2:]) if mo: payload = payload[:-len(mo.group(0))] self._last.set_payload(payload)