[Pymilter] Malformed attachment problem
Stuart D. Gathman
stuart at bmsi.com
Tue Nov 9 17:57:47 EST 2004
I have been trying to improve the handling of malformed attachments by the
mime.py module. Currently, a malformed attachment (missing boundaries, etc)
gets an exception, and is rejected as spam. However, I keep getting cases
where someone forwards a message (with missing boundaries) as an rfc822
attachment. I don't know whether the sender received the message garbled, and
read it with a tolerant email client, or their email client garbled it
while forwarding.
This usually happens internally (where everyone uses OutHouse), so I added a
feature to pymilter so that a malformed attachment exception does not block
internal mail.
Here is my attempt to postphone parsing of rfc822 attachments until needed:
***************
*** 213,225 ****
except Errors.HeaderParseError:
msg = self._class()
self._parsebody(msg, fp)
! except Errors.BoundaryError:
! part = container.get_payload(decode=True)
! bl = re.compile(r'(?:\r\n|\r|\n){2}')
! parthdrs, part = bl.split(part, 1)
! msg = self.parsestr(parthdrs, headersonly=1)
! msg.set_payload(part)
! container.set_payload([msg])
else:
text = fp.read()
if firstbodyline is not None:
--- 206,212 ----
except Errors.HeaderParseError:
msg = self._class()
self._parsebody(msg, fp)
! container.set_payload([msg])
else:
text = fp.read()
if firstbodyline is not None:
I wanted malformed rfc822 attachments to produce an exception only
when the scan_rfc822 option is turned on. Unfortunately, my test cases
indicate that with this change, malformed attachments are never
detected - even with scan_rfc822 on.
Does anyone have pointers to handling this problem with the email
package? Suggestions? I can make a case for always rejecting malformed
mail - but the whole point of the rfc822 attachment is to be able
to encapsulate mail, malformed or not.
--
Stuart D. Gathman <stuart at bmsi.com>
Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154
"Confutatis maledictis, flamis acribus addictis" - background song for
a Microsoft sponsored "Where do you want to go from here?" commercial.
More information about the Pymilter
mailing list