diff options
author | andrei kulakov <andrei.avk@gmail.com> | 2021-07-30 17:05:49 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-30 17:05:49 (GMT) |
commit | e3f877c32d7cccb734f45310f26beeec793364ce (patch) | |
tree | b00453971c06bf746c6822657ddeb1f5a9e61a29 /Lib/test | |
parent | 4bd9caafb64589288e5171087070bde726178c58 (diff) | |
download | cpython-e3f877c32d7cccb734f45310f26beeec793364ce.zip cpython-e3f877c32d7cccb734f45310f26beeec793364ce.tar.gz cpython-e3f877c32d7cccb734f45310f26beeec793364ce.tar.bz2 |
bpo-42892: fix email multipart attribute error (GH-26903)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_email/test_message.py | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/Lib/test/test_email/test_message.py b/Lib/test/test_email/test_message.py index 7aaf780..920a3d6 100644 --- a/Lib/test/test_email/test_message.py +++ b/Lib/test/test_email/test_message.py @@ -487,10 +487,14 @@ class TestEmailMessageBase: self.assertEqual(list(m.iter_attachments()), attachments) def message_as_iter_parts(self, body_parts, attachments, parts, msg): + def _is_multipart_msg(msg): + return 'Content-Type: multipart' in msg + m = self._str_msg(msg) allparts = list(m.walk()) parts = [allparts[n] for n in parts] - self.assertEqual(list(m.iter_parts()), parts) + iter_parts = list(m.iter_parts()) if _is_multipart_msg(msg) else [] + self.assertEqual(iter_parts, parts) class _TestContentManager: def get_content(self, msg, *args, **kw): @@ -923,6 +927,34 @@ class TestEmailMessage(TestEmailMessageBase, TestEmailBase): b'123456789-123456789\n 123456789 Hello ' b'=?utf-8?q?W=C3=B6rld!?= 123456789 123456789\n\n') + def test_get_body_malformed(self): + """test for bpo-42892""" + msg = textwrap.dedent("""\ + Message-ID: <674392CA.4347091@email.au> + Date: Wed, 08 Nov 2017 08:50:22 +0700 + From: Foo Bar <email@email.au> + MIME-Version: 1.0 + To: email@email.com <email@email.com> + Subject: Python Email + Content-Type: multipart/mixed; + boundary="------------879045806563892972123996" + X-Global-filter:Messagescannedforspamandviruses:passedalltests + + This is a multi-part message in MIME format. + --------------879045806563892972123996 + Content-Type: text/plain; charset=ISO-8859-1; format=flowed + Content-Transfer-Encoding: 7bit + + Your message is ready to be sent with the following file or link + attachments: + XU89 - 08.11.2017 + """) + m = self._str_msg(msg) + # In bpo-42892, this would raise + # AttributeError: 'str' object has no attribute 'is_attachment' + m.get_body() + + class TestMIMEPart(TestEmailMessageBase, TestEmailBase): # Doing the full test run here may seem a bit redundant, since the two # classes are almost identical. But what if they drift apart? So we do |