[ python-Bugs-836293 ] email generator can give bad output

SourceForge.net noreply at sourceforge.net
Fri Nov 21 11:38:16 EST 2003

Bugs item #836293, was opened at 2003-11-05 01:26
Message generated for change (Comment added) made by bwarsaw
You can respond by visiting: 

Category: Python Library
Group: Python 2.3
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: John Draper (crunch)
Assigned to: Barry A. Warsaw (bwarsaw)
Summary: email generator can give bad output

Initial Comment:
#!/usr/bin/env python
#Feedback to crunch at shopip.com
#Python 2.3.2 under OpenBSD 3.4 i386
import email

print r"""
Example of Python email generator bug.
If a MIME message is missing the terminating line, the
generator creates one for it -only it forgets to add the
\n\n to it. This causes the following message to be
concatenated to the first.

#s1 is MIME missing terminating line;
#s2 is a proper MIME message.
s1="""Received: by spameater (
From: "Victor Virus" <security at microsoft.com>
To: <poorsap at host.net>
Subject: Unterminated MIME to corrupt your mbox!
MIME-Version: 1.0
Content-Type: multipart/mixed;boundary="xxxx"

Content-Type: text/plain;

This is an unterminated MIME, like many viruses
generate. I don't care about rights of viruses,
but I do care if improper handling of MIME causes
following messages to be lost.


s2=s1+"""--xxxx--\n\n""" #Create properly terminator
print str(msg1)+str(msg2)
print "p.s. Notice how the first message runs into the"
print "      second message."
print "      By adding the missing '--', this won't happen."


>Comment By: Barry A. Warsaw (bwarsaw)
Date: 2003-11-21 11:38

Logged In: YES 

This really isn't a bug in the email package, since it's
doing what is expected of it.  The MIME RFC actually
attaches newlines to the front of any boundary and does not
specify any required newlines after the terminator.  If you
look carefully at msg1 and msg2, you'll find that for the
latter, all those extra newlines get assigned to the
.epilogue which, like the .preamble is text outside the MIME

If you want to use  the output of the Generator to create a
Unix style mbox format file, you'll need to either add the
extra newlines to the epilogue yourself, or checked the
str() of msg1 to see if it contains the number of newlines
your external (read: mbox) format requires.


You can respond by visiting: 

More information about the Python-bugs-list mailing list