Merged revisions 82011 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k

................
  r82011 | r.david.murray | 2010-06-15 22:19:40 -0400 (Tue, 15 Jun 2010) | 17 lines

  Merged revisions 81675 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk

  ........
    r81675 | r.david.murray | 2010-06-03 11:43:20 -0400 (Thu, 03 Jun 2010) | 10 lines

    #5610: use \Z not $ so we don't eat extra chars when body part ends with \r\n.

    If a body part ended with \r\n, feedparser, using '$' to terminate its
    search for the newline, would match on the \r\n, and think that it needed
    to strip two characters in order to account for the line end before the
    boundary.  That made it chop one too many characters off the end of
    the body part.  Using \Z makes the match correct.

    Patch and test by Tony Nelson.
  ........
................
diff --git a/Lib/email/test/test_email.py b/Lib/email/test/test_email.py
index 395e200..0ded3d9 100644
--- a/Lib/email/test/test_email.py
+++ b/Lib/email/test/test_email.py
@@ -2584,6 +2584,24 @@
         eq(headers, ['A', 'B', 'CC'])
         eq(msg.get_payload(), 'body')
 
+    def test_CRLFLF_at_end_of_part(self):
+        # issue 5610: feedparser should not eat two chars from body part ending
+        # with "\r\n\n".
+        m = (
+            "From: foo@bar.com\n"
+            "To: baz\n"
+            "Mime-Version: 1.0\n"
+            "Content-Type: multipart/mixed; boundary=BOUNDARY\n"
+            "\n"
+            "--BOUNDARY\n"
+            "Content-Type: text/plain\n"
+            "\n"
+            "body ending with CRLF newline\r\n"
+            "\n"
+            "--BOUNDARY--\n"
+          )
+        msg = email.message_from_string(m)
+        self.assertTrue(msg.get_payload(0).get_payload().endswith('\r\n'))
 
 
 class TestBase64(unittest.TestCase):