[Python-checkins] python/dist/src/Lib/email Parser.py,1.17,1.18

bwarsaw@users.sourceforge.net bwarsaw@users.sourceforge.net
Tue, 05 Nov 2002 12:54:39 -0800


Update of /cvsroot/python/python/dist/src/Lib/email
In directory usw-pr-cvs1:/tmp/cvs-serv20317

Modified Files:
	Parser.py 
Log Message:
_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.


Index: Parser.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/email/Parser.py,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** Parser.py	7 Oct 2002 17:27:35 -0000	1.17
--- Parser.py	5 Nov 2002 20:54:37 -0000	1.18
***************
*** 222,228 ****
                          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')
                  else:
                      msgobj = self.parsestr(part)
--- 222,232 ----
                          msgobj = self.parsestr(parthdrs, headersonly=1)
                      # while submsgobj is the message itself
                      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)