diff options
| author | bwarsaw | 2002-08-29 17:17:33 +0000 |
|---|---|---|
| committer | bwarsaw | 2002-08-29 17:17:33 +0000 |
| commit | a554ebe6a034aa4b2f8d66d0f8c48eec427de347 (patch) | |
| tree | 0143afbe131b19c6cc241db3c96f6ec0da90dab4 | |
| parent | 96b2a458409f8445f4978b74b082eea87263d88d (diff) | |
| download | mailman-a554ebe6a034aa4b2f8d66d0f8c48eec427de347.tar.gz mailman-a554ebe6a034aa4b2f8d66d0f8c48eec427de347.tar.zst mailman-a554ebe6a034aa4b2f8d66d0f8c48eec427de347.zip | |
Some fixes for problems identified by Peer Heinlein. It is possible
that the digest may contain unparseable messages, e.g. with missing
start boundaries. Instead of crashing, such messages should simply be
ignored. If lax parsing can't grok it, it has a high likelihood of
being spam.
Specific changes here:
_safeparser(): New helper factory for PortableUnixMailbox, which
returns the empty string if a MessageParseError occurs. Note that ''
is used instead of None because the latter will stop the Mailbox's
default iterator (in Python 2.2).
Mailbox.__init__(): Use the _safeparser() function instead of
email.message_from_file().
scrubber(): We can use _safeparser() here and simply not scrub the
empty string return value.
| -rw-r--r-- | Mailman/Mailbox.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/Mailman/Mailbox.py b/Mailman/Mailbox.py index 9fa3189b0..8ab085cca 100644 --- a/Mailman/Mailbox.py +++ b/Mailman/Mailbox.py @@ -23,15 +23,24 @@ import mailbox import email from email.Generator import Generator from email.Parser import Parser +from email.Errors import MessageParseError from Mailman import mm_cfg from Mailman.Message import Message + +def _safeparser(fp): + try: + return email.message_from_file(fp, Message) + except MessageParseError: + # Don't return None since that will stop a mailbox iterator + return '' + class Mailbox(mailbox.PortableUnixMailbox): def __init__(self, fp): - mailbox.PortableUnixMailbox.__init__(self, fp, email.message_from_file) + mailbox.PortableUnixMailbox.__init__(self, fp, _safeparser) # msg should be an rfc822 message or a subclass. def AppendMessage(self, msg): @@ -64,8 +73,9 @@ def _archfactory(mailbox): # a reference to the mailing list. Nested scopes would help here, BTW, # but we can't rely on them being around (e.g. Python 2.0). def scrubber(fp, mailbox=mailbox): - p = Parser(Message) - msg = p.parse(fp) + msg = _safeparser(fp) + if msg == '': + return msg return mailbox.scrub(msg) return scrubber |
