mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
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.
This commit is contained in:
parent
d7c87d982d
commit
02257012f6
3 changed files with 21 additions and 1 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue