diff options
author | Abhilash Raj <maxking@users.noreply.github.com> | 2019-06-25 17:03:19 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2019-06-25 17:03:19 (GMT) |
commit | 02257012f6d3821d816cb6a7e8461a88a05b9a08 (patch) | |
tree | 62ddd6ec0b021a615997180039f90d829ff2edc6 /Lib/test/test_email | |
parent | d7c87d982d4ec4ba201bcee14324ae5e0e90581f (diff) | |
download | cpython-02257012f6d3821d816cb6a7e8461a88a05b9a08.zip cpython-02257012f6d3821d816cb6a7e8461a88a05b9a08.tar.gz cpython-02257012f6d3821d816cb6a7e8461a88a05b9a08.tar.bz2 |
bpo-33972: Fix EmailMessage.iter_attachments raising AttributeError. (GH-14119)
* bpo-33972: Fix EmailMessage.iter_attachments raising AttributeError.
When certain malformed messages have content-type set to 'mulitpart/*' but
still have a single part body, iter_attachments can raise AttributeError. This
patch fixes it by returning a None value instead when the body is single part.
Diffstat (limited to 'Lib/test/test_email')
-rw-r--r-- | Lib/test/test_email/test_message.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/test_email/test_message.py b/Lib/test/test_email/test_message.py index 5dc46e1..fab97d9 100644 --- a/Lib/test/test_email/test_message.py +++ b/Lib/test/test_email/test_message.py @@ -929,6 +929,15 @@ class TestMIMEPart(TestEmailMessageBase, TestEmailBase): m.set_content(content_manager=cm) self.assertNotIn('MIME-Version', m) + def test_string_payload_with_multipart_content_type(self): + msg = message_from_string(textwrap.dedent("""\ + Content-Type: multipart/mixed; charset="utf-8" + + sample text + """), policy=policy.default) + attachments = msg.iter_attachments() + self.assertEqual(list(attachments), []) + if __name__ == '__main__': unittest.main() |