R. David Murray <[email protected]> added the comment:
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/message.py b/Lib/email/message.py
index 3701b30553..d5d4a2385a 100644
--- a/Lib/email/message.py
+++ b/Lib/email/message.py
@@ -982,7 +982,7 @@ def _find_body(self, part, preferencelist):
if subtype in preferencelist:
yield (preferencelist.index(subtype), part)
return
- if maintype != 'multipart':
+ if maintype != 'multipart' or not self.is_multipart():
return
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.
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue42892>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com