mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Merge: #14645: Generator now emits correct linesep for all parts.
Previously the parts of the message retained whatever linesep they had on read, which means if the messages weren't read in univeral newline mode, the line endings could well be inconsistent. In general sending it via smtplib would result in them getting fixed, but it is better to generate them correctly to begin with. Also, the new send_message method of smtplib does not do the fixup, so that method is producing rfc-invalid output without this fix.
This commit is contained in:
commit
addb0be63e
3 changed files with 57 additions and 4 deletions
|
@ -3111,6 +3111,40 @@ multipart/report
|
|||
email.utils.make_msgid(domain='testdomain-string')[-19:],
|
||||
'@testdomain-string>')
|
||||
|
||||
def test_Generator_linend(self):
|
||||
# Issue 14645.
|
||||
with openfile('msg_26.txt', newline='\n') as f:
|
||||
msgtxt = f.read()
|
||||
msgtxt_nl = msgtxt.replace('\r\n', '\n')
|
||||
msg = email.message_from_string(msgtxt)
|
||||
s = StringIO()
|
||||
g = email.generator.Generator(s)
|
||||
g.flatten(msg)
|
||||
self.assertEqual(s.getvalue(), msgtxt_nl)
|
||||
|
||||
def test_BytesGenerator_linend(self):
|
||||
# Issue 14645.
|
||||
with openfile('msg_26.txt', newline='\n') as f:
|
||||
msgtxt = f.read()
|
||||
msgtxt_nl = msgtxt.replace('\r\n', '\n')
|
||||
msg = email.message_from_string(msgtxt_nl)
|
||||
s = BytesIO()
|
||||
g = email.generator.BytesGenerator(s)
|
||||
g.flatten(msg, linesep='\r\n')
|
||||
self.assertEqual(s.getvalue().decode('ascii'), msgtxt)
|
||||
|
||||
def test_BytesGenerator_linend_with_non_ascii(self):
|
||||
# Issue 14645.
|
||||
with openfile('msg_26.txt', 'rb') as f:
|
||||
msgtxt = f.read()
|
||||
msgtxt = msgtxt.replace(b'with attachment', b'fo\xf6')
|
||||
msgtxt_nl = msgtxt.replace(b'\r\n', b'\n')
|
||||
msg = email.message_from_bytes(msgtxt_nl)
|
||||
s = BytesIO()
|
||||
g = email.generator.BytesGenerator(s)
|
||||
g.flatten(msg, linesep='\r\n')
|
||||
self.assertEqual(s.getvalue(), msgtxt)
|
||||
|
||||
|
||||
# Test the iterator/generators
|
||||
class TestIterators(TestEmailBase):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue