[spambayes-dev] More message munging

Mark Hammond mhammond at skippinet.com.au
Wed Jun 4 13:25:33 EDT 2003

For those who don't follow the checkins.  This is following from Tim P's
message about hacks to get the email package to recognise the message.

I made the following patch to Outlook, and should we decide on a "choke
point", the patch below should be included in some form.  After checking it
in, I noticed:

* If the first header is "Content-Type", my patch will fail to fix the
* A better solution may be to fall back to the "rfc822" module.  It is
pretty dumb about mime, and should be easy to use to perform better header
translations before feeding into the email package (or indeed, the
rfc822.Message object may be able to be used in place of the email package

But I'm not going to bother with either of them for Outlook.


-----Original Message-----
From: spambayes-checkins-bounces at python.org
[mailto:spambayes-checkins-bounces at python.org]On Behalf Of Mark Hammond
Sent: Wednesday, 4 June 2003 11:47 AM
To: spambayes-checkins at python.org
Subject: [Spambayes-checkins] spambayes/Outlook2000

Update of /cvsroot/spambayes/spambayes/Outlook2000
In directory sc8-pr-cvs1:/tmp/cvs-serv20925

Modified Files:
Log Message:
Get even more brutal with the message when the email package still barfs.

Index: msgstore.py
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/msgstore.py,v
retrieving revision 1.44
retrieving revision 1.45
diff -C2 -d -r1.44 -r1.45
*** msgstore.py	20 May 2003 00:30:45 -0000	1.44
--- msgstore.py	4 Jun 2003 01:47:13 -0000	1.45
*** 666,670 ****
                  # structure, just the words it contains, so no harm and
                  # much good in trying to suppress this error.
!                 msg = email.message_from_string(text + "\n\n")
              print "FAILED to create email.message from: ", `text`
--- 666,687 ----
                  # structure, just the words it contains, so no harm and
                  # much good in trying to suppress this error.
!                 try:
!                     msg = email.message_from_string(text + "\n\n")
!                 except email.Errors.BoundaryError:
!                     # But even this doesn't get *everything*.  We can
still see:
!                     #  "multipart message with no defined boundary"
!                     # so now it is time to turn into a butcher - hack out
!                     # the Content-Type header, so we see it as plain text.
!                     butcher_pos = text.lower().find("\ncontent-type: ")
!                     if butcher_pos < 0:
!                         # This error just just gunna get caught below
!                         raise RuntimeError(
!                             "email package croaked with boundary error,
but "
!                             "there appears to be no 'Content-Type'
!                     # Put it back together, skipping the original "\n" but
!                     # leaving the header leaving
"\nSpamBayes-Content-Type: "
!                     butchered = text[:butcher_pos] + "\nSpamBayes-" + \
!                                 text[butcher_pos+1:] + "\n\n"
!                     msg = email.message_from_string(butchered)
              print "FAILED to create email.message from: ", `text`

Spambayes-checkins mailing list
Spambayes-checkins at python.org

More information about the spambayes-dev mailing list