Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5c9130e

Browse files
committed
_parsebody(): A fix for SF bug #631350, where a subobject in a
multipart/digest isn't a message/rfc822. This is legal, but counter to recommended practice in RFC 2046, $5.1.5. The fix is to look at the content type after setting the default content type. If the maintype is then message or multipart, attach the parsed subobject, otherwise use set_payload() to set the data of the other object.
1 parent 00e6a02 commit 5c9130e

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

Lib/email/Parser.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,13 @@ def _parsebody(self, container, fp):
221221
# msgobj in this case is the "message/rfc822" container
222222
msgobj = self.parsestr(parthdrs, headersonly=1)
223223
# while submsgobj is the message itself
224-
submsgobj = self.parsestr(part)
225-
msgobj.attach(submsgobj)
226224
msgobj.set_default_type('message/rfc822')
225+
maintype = msgobj.get_content_maintype()
226+
if maintype in ('message', 'multipart'):
227+
submsgobj = self.parsestr(part)
228+
msgobj.attach(submsgobj)
229+
else:
230+
msgobj.set_payload(part)
227231
else:
228232
msgobj = self.parsestr(part)
229233
container.preamble = preamble

0 commit comments

Comments
 (0)