summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_email
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2014-02-08 16:48:20 (GMT)
committerR David Murray <rdmurray@bitdance.com>2014-02-08 16:48:20 (GMT)
commit905c8c3d8dfe081d91e399aa5fd93d1659655264 (patch)
tree898bc50c4048cc85caddcd74af36237e0768475e /Lib/test/test_email
parent7c389e2404b97b5e48c02e2735229eef30e3f1cf (diff)
downloadcpython-905c8c3d8dfe081d91e399aa5fd93d1659655264.zip
cpython-905c8c3d8dfe081d91e399aa5fd93d1659655264.tar.gz
cpython-905c8c3d8dfe081d91e399aa5fd93d1659655264.tar.bz2
#19772: Do not mutate message when downcoding to 7bit.
This is a bit of an ugly hack because of the way generator pieces together the output message. The deepcopys aren't too expensive, though, because we know it is only called on messages that are not multiparts, and the payload (the thing that could be large) is an immutable object. Test and preliminary work on patch by Vajrasky Kok.
Diffstat (limited to 'Lib/test/test_email')
-rw-r--r--Lib/test/test_email/test_email.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py
index 4157a06..73ec2a6 100644
--- a/Lib/test/test_email/test_email.py
+++ b/Lib/test/test_email/test_email.py
@@ -3495,7 +3495,7 @@ Here's the message body
self.assertTrue(msg.get_payload(0).get_payload().endswith('\r\n'))
-class Test8BitBytesHandling(unittest.TestCase):
+class Test8BitBytesHandling(TestEmailBase):
# In Python3 all input is string, but that doesn't work if the actual input
# uses an 8bit transfer encoding. To hack around that, in email 5.1 we
# decode byte streams using the surrogateescape error handler, and
@@ -3748,6 +3748,16 @@ class Test8BitBytesHandling(unittest.TestCase):
email.generator.Generator(out).flatten(msg)
self.assertEqual(out.getvalue(), self.non_latin_bin_msg_as7bit_wrapped)
+ def test_str_generator_should_not_mutate_msg_when_handling_8bit(self):
+ msg = email.message_from_bytes(self.non_latin_bin_msg)
+ out = BytesIO()
+ BytesGenerator(out).flatten(msg)
+ orig_value = out.getvalue()
+ Generator(StringIO()).flatten(msg) # Should not mutate msg!
+ out = BytesIO()
+ BytesGenerator(out).flatten(msg)
+ self.assertEqual(out.getvalue(), orig_value)
+
def test_bytes_generator_with_unix_from(self):
# The unixfrom contains a current date, so we can't check it
# literally. Just make sure the first word is 'From' and the