[ python-Feature Requests-815563 ] bug with ill-formed rfc822
attachments
SourceForge.net
noreply at sourceforge.net
Fri Nov 21 15:52:29 EST 2003
Feature Requests item #815563, was opened at 2003-09-30 22:32
Message generated for change (Comment added) made by customdesigned
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=815563&group_id=5470
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Stuart D. Gathman (customdesigned)
Assigned to: Nobody/Anonymous (nobody)
Summary: bug with ill-formed rfc822 attachments
Initial Comment:
The following proglet gets an except with the attached
message:
-----te.py--------
import email
import sys
msg = email.message_from_file(sys.stdin)
sys.stdout.write(msg.as_string())
------------------
python2 te.py <failingmsg
Traceback (most recent call last):
File "te.py", line 4, in ?
msg = email.message_from_file(sys.stdin)
File "/usr/lib/python2.2/email/__init__.py", line 63,
in message_from_file
return Parser(_class, strict=strict).parse(fp)
File "/usr/lib/python2.2/email/Parser.py", line 64,
in parse
self._parsebody(root, fp, firstbodyline)
File "/usr/lib/python2.2/email/Parser.py", line 239,
in _parsebody
msgobj = self.parsestr(part)
File "/usr/lib/python2.2/email/Parser.py", line 75,
in parsestr
return self.parse(StringIO(text),
headersonly=headersonly)
File "/usr/lib/python2.2/email/Parser.py", line 64,
in parse
self._parsebody(root, fp, firstbodyline)
File "/usr/lib/python2.2/email/Parser.py", line 264,
in _parsebody
msg = self.parse(fp)
File "/usr/lib/python2.2/email/Parser.py", line 64,
in parse
self._parsebody(root, fp, firstbodyline)
File "/usr/lib/python2.2/email/Parser.py", line 205,
in _parsebody
raise Errors.BoundaryError(
email.Errors.BoundaryError: No terminating boundary and
no trailing empty line
-------------------
The message/rfc822 attachment really is missing the
boundary. However, that is why it is being returned as
an attachment in the first place! Is it illegal for
message/rfc822 attachments to have invalid MIME
construction?
I suggest that a message attachment that fails MIME
boundary decoding, should become a plain rfc822 object,
or perhaps a text object. I don't know.
Anyway, I get tons of messages with this property that
have to be processed by my Python milter.
----------------------------------------------------------------------
>Comment By: Stuart D. Gathman (customdesigned)
Date: 2003-11-21 15:52
Message:
Logged In: YES
user_id=142072
Your disposition makes sense.
Since all messages with invalid MIME boundaries are either
invalid themselves, or bounces or forwards of invalid
messages, my work around is to issue an SMTP reject:
if exc_type == email.Errors.BoundaryError:
self.setreply('554','5.7.7',
'Boundary error in your message, are you a
spammer?')
For 2.4, I recommend that rfc822 attachments be parsed
independently of the enclosing message. If the attachment
is invalid, turn it into a plain rfc822 message object or a
string.
Although the rfc822 module is deprecated, I find it very
useful to represent mail that may or may not correctly
follow MIME standards. Examples include forwarded spam
(using the new innoculation RFC), and generic mailbox
processing. I suggest retaining rfc822 as a 'featureless'
message with only headers and body.
----------------------------------------------------------------------
Comment By: Barry A. Warsaw (bwarsaw)
Date: 2003-11-21 15:36
Message:
Logged In: YES
user_id=12800
I'm moving this to a feature request for Python 2.4.
There's little that we can do about this in Python 2.3 since
the lax parser is only so good at guessing the intent of
ill-formed messages. email 2.x can't do what you suggest
because that would be a new feature and can't be introduced
into Python 2.3. The email-sig is chartered with developing
an improved parser for Python 2.4 that might be able to
handle this.
In the meantime, you could probably derive your own Parser
class that might be able to worm around this problem in an
application specific way.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=815563&group_id=5470
More information about the Python-bugs-list
mailing list