Skip to content

Commit e9c3147

Browse files
committed
python#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.
1 parent 409ea5d commit e9c3147

4 files changed

Lines changed: 16 additions & 7 deletions

File tree

Lib/email/generator.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,8 @@ def _handle_multipart(self, msg):
299299
# body-part
300300
self._fp.write(body_part)
301301
# close-delimiter transport-padding
302-
self.write(self._NL + '--' + boundary + '--')
302+
self.write(self._NL + '--' + boundary + '--' + self._NL)
303303
if msg.epilogue is not None:
304-
self.write(self._NL)
305304
if self._mangle_from_:
306305
epilogue = fcre.sub('>From ', msg.epilogue)
307306
else:

Lib/test/test_email/data/msg_02.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ hello
119119

120120

121121
--__--__----
122+
122123
--192.168.1.2.889.32614.987812255.500.21814
123124
Content-type: text/plain; charset=us-ascii
124125
Content-description: Digest Footer

Lib/test/test_email/test_email.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,7 +1711,8 @@ def test_no_parts_in_a_multipart_with_none_epilogue(self):
17111711
17121712
--BOUNDARY
17131713
1714-
--BOUNDARY--''')
1714+
--BOUNDARY--
1715+
''')
17151716

17161717
def test_no_parts_in_a_multipart_with_empty_epilogue(self):
17171718
outer = MIMEBase('multipart', 'mixed')
@@ -1756,7 +1757,8 @@ def test_one_part_in_a_multipart(self):
17561757
Content-Transfer-Encoding: 7bit
17571758
17581759
hello world
1759-
--BOUNDARY--''')
1760+
--BOUNDARY--
1761+
''')
17601762

17611763
def test_seq_parts_in_a_multipart_with_empty_preamble(self):
17621764
eq = self.ndiffAssertEqual
@@ -1782,7 +1784,8 @@ def test_seq_parts_in_a_multipart_with_empty_preamble(self):
17821784
Content-Transfer-Encoding: 7bit
17831785
17841786
hello world
1785-
--BOUNDARY--''')
1787+
--BOUNDARY--
1788+
''')
17861789

17871790

17881791
def test_seq_parts_in_a_multipart_with_none_preamble(self):
@@ -1808,7 +1811,8 @@ def test_seq_parts_in_a_multipart_with_none_preamble(self):
18081811
Content-Transfer-Encoding: 7bit
18091812
18101813
hello world
1811-
--BOUNDARY--''')
1814+
--BOUNDARY--
1815+
''')
18121816

18131817

18141818
def test_seq_parts_in_a_multipart_with_none_epilogue(self):
@@ -1834,7 +1838,8 @@ def test_seq_parts_in_a_multipart_with_none_epilogue(self):
18341838
Content-Transfer-Encoding: 7bit
18351839
18361840
hello world
1837-
--BOUNDARY--''')
1841+
--BOUNDARY--
1842+
''')
18381843

18391844

18401845
def test_seq_parts_in_a_multipart_with_empty_epilogue(self):

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ Core and Builtins
4848
Library
4949
-------
5050

51+
- Issue #14983: email.generator now always adds a line end after each MIME
52+
boundary marker, instead of doing so only when there is an epilogue. This
53+
fixes an RFC compliance bug and solves an issue with signed MIME parts.
54+
5155
- Issue #20540: Fix a performance regression (vs. Python 3.2) when layering
5256
a multiprocessing Connection over a TCP socket. For small payloads, Nagle's
5357
algorithm would introduce idle delays before the entire transmission of a

0 commit comments

Comments
 (0)