combining mailbox and email modules

Bob Horvath nospam at
Thu Sep 26 02:14:03 EDT 2002

Matthew Dixon Cowles wrote:
> On Wed, 25 Sep 2002 06:36:29 GMT, Bob Horvath <nospam at>
> wrote:
>>I am having trouble figuring out how to get the mailbox and email
>>modules to play together so that I can use email module functions on
>>every mail in the mailbox.  Is there a way to feed a factory from
>>the email module to mailbox module?
> Yes, there is:
>>>>import mailbox
>>>>import email

OK, I tried that.  Looks like the email package is being picky about 
things where I can't see a problem.

I keep getting the following error:

email.Errors.HeaderParseError: Not a header, not a continuation

Which I assume means a line that doesn't start with a space or tab 
that also does not contain a ':'.

The problem is that it looks good to me.  I've played around with 
it, and if I take out the MIME gunk (It actually is a Klez virus), 
it parses ok.

Here is what happens...

Python 2.2.1 (#1, Sep  7 2002, 14:34:30)
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> import email
 >>> fp = file('large')
 >>> msg = email.message_from_file(fp)
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
   File "/usr/lib/python2.2/email/", line 35, in 
     return _Parser(_class).parse(fp)
   File "/usr/lib/python2.2/email/", line 41, in parse
     self._parsebody(root, fp)
   File "/usr/lib/python2.2/email/", line 134, in _parsebody
     msgobj = self.parsestr(part)
   File "/usr/lib/python2.2/email/", line 45, in parsestr
     return self.parse(StringIO(text))
   File "/usr/lib/python2.2/email/", line 40, in parse
     self._parseheaders(root, fp)
   File "/usr/lib/python2.2/email/", line 81, in _parseheaders
     raise Errors.HeaderParseError(
email.Errors.HeaderParseError: Not a header, not a continuation

... and here it the message...

 From mickey at  Tue Aug 20 10:03:52 2002
Return-Path: <mickey at>
Delivered-To: bob at
Received: from localhost (bert [])
         by (Postfix) with ESMTP id 9FE612A21D
         for <bob at>; Tue, 20 Aug 2002 10:03:51 -0500 (CDT)
Delivered-To: horvath at
Received: from
         by localhost with IMAP (fetchmail-5.9.11)
         for bob at (multi-drop); Tue, 20 Aug 2002 10:03:51 
-0500 (CDT)
Received: (qmail 40801 invoked by alias); 20 Aug 2002 14:58:55 -0000
Delivered-To: alias-horvath_com-bob at
Received: (qmail 40787 invoked by uid 0); 20 Aug 2002 14:58:53 -0000
Received: from (HELO 
   by with SMTP; 20 Aug 2002 14:58:53 -0000
Received: from Urn ([]) by
           (InterMail vM. 201-253-122-126-109-20020611) 
with SMTP
           id < at Urn>
           for <bob at>; Tue, 20 Aug 2002 09:58:52 -0500
From: mickey <mickey at>
To: bob at
Subject: Document.cookie
MIME-Version: 1.0
Content-Type: multipart/alternative;
Message-Id: < at Urn>
Date: Tue, 20 Aug 2002 09:58:53 -0500
Status: RO
X-UID: 52

Content-Type: text/html;
Content-Transfer-Encoding: quoted-printable

<iframe src=3Dcid:S3vx2Jnbs6R29 height=3D0 width=3D0>

Content-Type: audio/x-wav;
Content-Transfer-Encoding: base64
Content-ID: <S3vx2Jnbs6R29>

Content-Type: application/octet-stream;
Content-Transfer-Encoding: base64
Content-ID: <S3vx2Jnbs6R29>



More information about the Python-list mailing list