]> granicus.if.org Git - python/commitdiff
_parsebody(): A fix for SF bug #631350, where a subobject in a
authorBarry Warsaw <barry@python.org>
Tue, 5 Nov 2002 20:54:37 +0000 (20:54 +0000)
committerBarry Warsaw <barry@python.org>
Tue, 5 Nov 2002 20:54:37 +0000 (20:54 +0000)
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.

Lib/email/Parser.py

index 5fea3c398630bccf460a0fa1b1bfc98705697218..6dfa4d38e6dc7dfdccd3469c225914ba50e312fa 100644 (file)
@@ -221,9 +221,13 @@ class Parser:
                         # msgobj in this case is the "message/rfc822" container
                         msgobj = self.parsestr(parthdrs, headersonly=1)
                     # while submsgobj is the message itself
-                    submsgobj = self.parsestr(part)
-                    msgobj.attach(submsgobj)
                     msgobj.set_default_type('message/rfc822')
+                    maintype = msgobj.get_content_maintype()
+                    if maintype in ('message', 'multipart'):
+                        submsgobj = self.parsestr(part)
+                        msgobj.attach(submsgobj)
+                    else:
+                        msgobj.set_payload(part)
                 else:
                     msgobj = self.parsestr(part)
                 container.preamble = preamble