diff options
author | R David Murray <rdmurray@bitdance.com> | 2012-03-14 18:05:03 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2012-03-14 18:05:03 (GMT) |
commit | 9fd170e2d053bd86592b8728bdd00cf2d2a06d0b (patch) | |
tree | 3bbd815324702f30da3971990a5a6c7641ab52e3 /Lib | |
parent | 525fd5447d0fdd6209a57090af65cbb811ad5999 (diff) | |
download | cpython-9fd170e2d053bd86592b8728bdd00cf2d2a06d0b.zip cpython-9fd170e2d053bd86592b8728bdd00cf2d2a06d0b.tar.gz cpython-9fd170e2d053bd86592b8728bdd00cf2d2a06d0b.tar.bz2 |
#14062: fix BytesParser handling of linesep for Header objects
This also affected smtplib.SMTP.send_message, which calls BytesParser.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/email/generator.py | 2 | ||||
-rw-r--r-- | Lib/email/test/test_email.py | 25 |
2 files changed, 25 insertions, 2 deletions
diff --git a/Lib/email/generator.py b/Lib/email/generator.py index f0e7a95..430ee73 100644 --- a/Lib/email/generator.py +++ b/Lib/email/generator.py @@ -360,7 +360,7 @@ class BytesGenerator(Generator): for h, v in msg._headers: self.write('%s: ' % h) if isinstance(v, Header): - self.write(v.encode(maxlinelen=self._maxheaderlen)+NL) + self.write(v.encode(maxlinelen=self._maxheaderlen)+self._NL) elif _has_surrogates(v): # If we have raw 8bit data in a byte string, we have no idea # what the encoding is. There is no safe way to split this diff --git a/Lib/email/test/test_email.py b/Lib/email/test/test_email.py index f43bb38..5655938 100644 --- a/Lib/email/test/test_email.py +++ b/Lib/email/test/test_email.py @@ -1243,7 +1243,6 @@ List: List-Unsubscribe: =?utf-8?q?_folding_white_space_works?=""")+'\n') - # Test mangling of "From " lines in the body of a message class TestFromMangling(unittest.TestCase): def setUp(self): @@ -3441,6 +3440,30 @@ class Test8BitBytesHandling(unittest.TestCase): g.flatten(msg) self.assertEqual(s.getvalue(), source) + def test_bytes_generator_b_encoding_linesep(self): + # Issue 14062: b encoding was tacking on an extra \n. + m = Message() + # This has enough non-ascii that it should always end up b encoded. + m['Subject'] = Header('žluťoučký kůň') + s = BytesIO() + g = email.generator.BytesGenerator(s) + g.flatten(m, linesep='\r\n') + self.assertEqual( + s.getvalue(), + b'Subject: =?utf-8?b?xb5sdcWlb3XEjWvDvSBrxa/FiA==?=\r\n\r\n') + + def test_generator_b_encoding_linesep(self): + # Since this broke in ByteGenerator, test Generator for completeness. + m = Message() + # This has enough non-ascii that it should always end up b encoded. + m['Subject'] = Header('žluťoučký kůň') + s = StringIO() + g = email.generator.Generator(s) + g.flatten(m, linesep='\r\n') + self.assertEqual( + s.getvalue(), + 'Subject: =?utf-8?b?xb5sdcWlb3XEjWvDvSBrxa/FiA==?=\r\n\r\n') + maxDiff = None |