[Python-checkins] cpython (2.7): #14983: always add a line end after a MIME boundary marker.

r.david.murray python-checkins at python.org
Sat Feb 8 23:56:38 CET 2014


http://hg.python.org/cpython/rev/d579866d6419
changeset:   89067:d579866d6419
branch:      2.7
parent:      89052:d4f9efd4be7d
user:        R David Murray <rdmurray at bitdance.com>
date:        Sat Feb 08 17:54:12 2014 -0500
summary:
  #14983: always add a line end after a MIME boundary marker.

This is more RFC compliant (see issue) and fixes a problem with
signature verifiers rejecting the part when signed.  There is some
amount of backward compatibility concern here since it changes
the output, but the RFC issue coupled with fixing the problem
with signature verifiers seems worth the small risk of breaking
code that depends on the current incorrect output.

files:
  Lib/email/generator.py               |   3 +--
  Lib/email/test/data/msg_02.txt       |   1 +
  Lib/email/test/test_email.py         |  15 ++++++++++-----
  Lib/email/test/test_email_renamed.py |  15 ++++++++++-----
  Misc/NEWS                            |   4 ++++
  5 files changed, 26 insertions(+), 12 deletions(-)


diff --git a/Lib/email/generator.py b/Lib/email/generator.py
--- a/Lib/email/generator.py
+++ b/Lib/email/generator.py
@@ -231,9 +231,8 @@
             # body-part
             self._fp.write(body_part)
         # close-delimiter transport-padding
-        self._fp.write('\n--' + boundary + '--')
+        self._fp.write('\n--' + boundary + '--' + NL)
         if msg.epilogue is not None:
-            print >> self._fp
             if self._mangle_from_:
                 epilogue = fcre.sub('>From ', msg.epilogue)
             else:
diff --git a/Lib/email/test/data/msg_02.txt b/Lib/email/test/data/msg_02.txt
--- a/Lib/email/test/data/msg_02.txt
+++ b/Lib/email/test/data/msg_02.txt
@@ -119,6 +119,7 @@
 
 
 --__--__----
+
 --192.168.1.2.889.32614.987812255.500.21814
 Content-type: text/plain; charset=us-ascii
 Content-description: Digest Footer
diff --git a/Lib/email/test/test_email.py b/Lib/email/test/test_email.py
--- a/Lib/email/test/test_email.py
+++ b/Lib/email/test/test_email.py
@@ -1206,7 +1206,8 @@
 
 --BOUNDARY
 
---BOUNDARY--''')
+--BOUNDARY--
+''')
 
     def test_no_parts_in_a_multipart_with_empty_epilogue(self):
         outer = MIMEBase('multipart', 'mixed')
@@ -1251,7 +1252,8 @@
 Content-Transfer-Encoding: 7bit
 
 hello world
---BOUNDARY--''')
+--BOUNDARY--
+''')
 
     def test_seq_parts_in_a_multipart_with_empty_preamble(self):
         eq = self.ndiffAssertEqual
@@ -1277,7 +1279,8 @@
 Content-Transfer-Encoding: 7bit
 
 hello world
---BOUNDARY--''')
+--BOUNDARY--
+''')
 
 
     def test_seq_parts_in_a_multipart_with_none_preamble(self):
@@ -1303,7 +1306,8 @@
 Content-Transfer-Encoding: 7bit
 
 hello world
---BOUNDARY--''')
+--BOUNDARY--
+''')
 
 
     def test_seq_parts_in_a_multipart_with_none_epilogue(self):
@@ -1329,7 +1333,8 @@
 Content-Transfer-Encoding: 7bit
 
 hello world
---BOUNDARY--''')
+--BOUNDARY--
+''')
 
 
     def test_seq_parts_in_a_multipart_with_empty_epilogue(self):
diff --git a/Lib/email/test/test_email_renamed.py b/Lib/email/test/test_email_renamed.py
--- a/Lib/email/test/test_email_renamed.py
+++ b/Lib/email/test/test_email_renamed.py
@@ -1146,7 +1146,8 @@
 
 --BOUNDARY
 
---BOUNDARY--''')
+--BOUNDARY--
+''')
 
     def test_no_parts_in_a_multipart_with_empty_epilogue(self):
         outer = MIMEBase('multipart', 'mixed')
@@ -1191,7 +1192,8 @@
 Content-Transfer-Encoding: 7bit
 
 hello world
---BOUNDARY--''')
+--BOUNDARY--
+''')
 
     def test_seq_parts_in_a_multipart_with_empty_preamble(self):
         eq = self.ndiffAssertEqual
@@ -1217,7 +1219,8 @@
 Content-Transfer-Encoding: 7bit
 
 hello world
---BOUNDARY--''')
+--BOUNDARY--
+''')
 
 
     def test_seq_parts_in_a_multipart_with_none_preamble(self):
@@ -1243,7 +1246,8 @@
 Content-Transfer-Encoding: 7bit
 
 hello world
---BOUNDARY--''')
+--BOUNDARY--
+''')
 
 
     def test_seq_parts_in_a_multipart_with_none_epilogue(self):
@@ -1269,7 +1273,8 @@
 Content-Transfer-Encoding: 7bit
 
 hello world
---BOUNDARY--''')
+--BOUNDARY--
+''')
 
 
     def test_seq_parts_in_a_multipart_with_empty_epilogue(self):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -42,6 +42,10 @@
 Library
 -------
 
+- Issue #14983: email.generator now always adds a line end after each MIME
+  boundary marker, instead of doing so only when there is an epilogue.  This
+  fixes an RFC compliance bug and solves an issue with signed MIME parts.
+
 - Issue #20013: Some imap servers disconnect if the current mailbox is
   deleted, and imaplib did not handle that case gracefully.  Now it
   handles the 'bye' correctly.

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list