summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2016-09-07 17:41:06 (GMT)
committerR David Murray <rdmurray@bitdance.com>2016-09-07 17:41:06 (GMT)
commit91afe7ec9fc82328bc17ab6d7312489dffac2223 (patch)
treef69054645f6be23b685d9c4b2e535d5bdd5625be
parent5223f08e78efcfadb7fe2288fd48bb985d6ca7a7 (diff)
parentc2e2473bc210ff83c2cbc73c4b916893f773b480 (diff)
downloadcpython-91afe7ec9fc82328bc17ab6d7312489dffac2223.zip
cpython-91afe7ec9fc82328bc17ab6d7312489dffac2223.tar.gz
cpython-91afe7ec9fc82328bc17ab6d7312489dffac2223.tar.bz2
Merge: 27988: Make sure iter_attachments does not mutate the payload list.
-rw-r--r--Lib/email/message.py2
-rw-r--r--Lib/test/test_email/test_message.py10
-rw-r--r--Misc/NEWS2
3 files changed, 13 insertions, 1 deletions
diff --git a/Lib/email/message.py b/Lib/email/message.py
index 65bb237..4b04283 100644
--- a/Lib/email/message.py
+++ b/Lib/email/message.py
@@ -1022,7 +1022,7 @@ class MIMEPart(Message):
maintype, subtype = self.get_content_type().split('/')
if maintype != 'multipart' or subtype == 'alternative':
return
- parts = self.get_payload()
+ parts = self.get_payload().copy()
if maintype == 'multipart' and subtype == 'related':
# For related, we treat everything but the root as an attachment.
# The root may be indicated by 'start'; if there's no start or we
diff --git a/Lib/test/test_email/test_message.py b/Lib/test/test_email/test_message.py
index d78049e..4345162 100644
--- a/Lib/test/test_email/test_message.py
+++ b/Lib/test/test_email/test_message.py
@@ -732,6 +732,16 @@ class TestEmailMessageBase:
m.set_param('filename', 'abc.png', 'Content-Disposition')
self.assertTrue(m.is_attachment())
+ def test_iter_attachments_mutation(self):
+ # We had a bug where iter_attachments was mutating the list.
+ m = self._make_message()
+ m.set_content('arbitrary text as main part')
+ m.add_related('more text as a related part')
+ m.add_related('yet more text as a second "attachment"')
+ orig = m.get_payload().copy()
+ self.assertEqual(len(list(m.iter_attachments())), 2)
+ self.assertEqual(m.get_payload(), orig)
+
class TestEmailMessage(TestEmailMessageBase, TestEmailBase):
message = EmailMessage
diff --git a/Misc/NEWS b/Misc/NEWS
index b367306..ef85d1c 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -91,6 +91,8 @@ Core and Builtins
Library
-------
+- Issue 27988: Fix email iter_attachments incorrect mutation of payload list.
+
- Issue #16113: Add SHA-3 and SHAKE support to hashlib module.
- Issue #27776: The :func:`os.urandom` function does now block on Linux 3.17