Message393996
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. |
|
Date |
User |
Action |
Args |
2021-05-20 01:49:38 | r.david.murray | set | recipients:
+ r.david.murray, barry, python-dev, iritkatriel, xavier2 |
2021-05-20 01:49:38 | r.david.murray | set | messageid: <1621475378.12.0.0925965021233.issue42892@roundup.psfhosted.org> |
2021-05-20 01:49:38 | r.david.murray | link | issue42892 messages |
2021-05-20 01:49:37 | r.david.murray | create | |
|