This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: email bug with message/rfc822
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: barry Nosy List: barry, customdesigned
Priority: normal Keywords:

Created on 2003-08-25 03:17 by customdesigned, last changed 2022-04-10 16:10 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test8 customdesigned, 2003-08-25 03:17 Sample message to break email modules
Messages (3)
msg17943 - (view) Author: Stuart D. Gathman (customdesigned) Date: 2003-08-25 03:17
Attached is a test message that the email module can't
even read in andd write back out.  It drops a whole
section of headers for the message/rfc822 part.  The
old email modules handle this message correctly.

Let me clarify the problem with a short test:

------te.py--------
import email
import sys

msg = email.message_from_file(sys.stdin)
sys.stdout.write(msg.as_string())
-------------------
$ python2 te.py <test8 >test8.out
$ diff test8 test8.out
.... lots of differences that shouldn't be there ....
msg17944 - (view) Author: Stuart D. Gathman (customdesigned) Date: 2003-08-26 02:48
Logged In: YES 
user_id=142072

Here is a fix for this bug.  The problem is that the message
attachment is not being decoded before parsing.

*** Parser.py   Mon Aug 25 22:43:34 2003
--- /usr/lib/python2.2/email/Parser.py  Tue Nov 12 16:50:20 2002
***************
*** 249,262 ****
          elif container.get_main_type() == 'message':
              # Create a container for the payload, but
watch out for there not
              # being any headers left
-             container.set_payload(fp.read())
-           fp = StringIO(container.get_payload(decode=True))
              try:
                  msg = self.parse(fp)
              except Errors.HeaderParseError:
                  msg = self._class()
                  self._parsebody(msg, fp)
!             container.set_payload([msg])
          else:
              container.set_payload(fp.read())
  
--- 249,260 ----
          elif container.get_main_type() == 'message':
              # Create a container for the payload, but
watch out for there not
              # being any headers left
              try:
                  msg = self.parse(fp)
              except Errors.HeaderParseError:
                  msg = self._class()
                  self._parsebody(msg, fp)
!             container.attach(msg)
          else:
              container.set_payload(fp.read())
  
msg17945 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2003-11-21 20:42
Logged In: YES 
user_id=12800

I believe this bug is out of date.  When I tried this in
Python 2.3.2, the only differences between the original file
and the outputted file are in whitespace and wrapped long
lines.  That's not unexpected.  You could eliminate even
these differences by instantiating your own Generator class
and using its .flatten() method, rather than relying on the
msg.as_string() convenience.
History
Date User Action Args
2022-04-10 16:10:49adminsetgithub: 39122
2003-08-25 03:17:52customdesignedcreate