This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author r.david.murray
Recipients barry, iritkatriel, python-dev, r.david.murray, xavier2
Date 2021-05-20.01:49:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Actually, I'm wrong.  The body of a part can be a string, and that's what's going to happen with a malformed body of something claiming to be a multipart. The problem is that there is code that doesn't guard against this possibility.  The following patch against master fixes the bug listed here, as well as iter_parts().  But it causes one test suite failure so it isn't a correct patch as it stands:

diff --git a/Lib/email/ b/Lib/email/
index 3701b30553..d5d4a2385a 100644
--- a/Lib/email/
+++ b/Lib/email/
@@ -982,7 +982,7 @@ def _find_body(self, part, preferencelist):
             if subtype in preferencelist:
                 yield (preferencelist.index(subtype), part)
-        if maintype != 'multipart':
+        if maintype != 'multipart' or not self.is_multipart():
         if subtype != 'related':
             for subpart in part.iter_parts():
@@ -1087,7 +1087,7 @@ def iter_parts(self):
         Return an empty iterator for a non-multipart.
-        if self.get_content_maintype() == 'multipart':
+        if self.is_multipart():
             yield from self.get_payload()
     def get_content(self, *args, content_manager=None, **kw):

Maybe someone can take this and finish it (with tests)...I may or may not have time to get back to this.
Date User Action Args
2021-05-20 01:49:38r.david.murraysetrecipients: + r.david.murray, barry, python-dev, iritkatriel, xavier2
2021-05-20 01:49:38r.david.murraysetmessageid: <>
2021-05-20 01:49:38r.david.murraylinkissue42892 messages
2021-05-20 01:49:37r.david.murraycreate