combining mailbox and email modules
Bob Horvath
nospam at horvath.com
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 horvath.com>
> 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
>>>>i=mailbox.Maildir("Mail/testmail",email.message_from_file)
>>>>i.next()
>>>
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/__init__.py", line 35, in
message_from_file
return _Parser(_class).parse(fp)
File "/usr/lib/python2.2/email/Parser.py", line 41, in parse
self._parsebody(root, fp)
File "/usr/lib/python2.2/email/Parser.py", line 134, in _parsebody
msgobj = self.parsestr(part)
File "/usr/lib/python2.2/email/Parser.py", line 45, in parsestr
return self.parse(StringIO(text))
File "/usr/lib/python2.2/email/Parser.py", line 40, in parse
self._parseheaders(root, fp)
File "/usr/lib/python2.2/email/Parser.py", line 81, in _parseheaders
raise Errors.HeaderParseError(
email.Errors.HeaderParseError: Not a header, not a continuation
>>>
... and here it the message...
From mickey at verizon.net Tue Aug 20 10:03:52 2002
Return-Path: <mickey at verizon.net>
Delivered-To: bob at horvath.com
Received: from localhost (bert [127.0.0.1])
by horvath.com (Postfix) with ESMTP id 9FE612A21D
for <bob at horvath.com>; Tue, 20 Aug 2002 10:03:51 -0500 (CDT)
Delivered-To: horvath at enteract.com
Received: from imap.enteract.com
by localhost with IMAP (fetchmail-5.9.11)
for bob at horvath.com (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 horvath.com
Received: (qmail 40787 invoked by uid 0); 20 Aug 2002 14:58:53 -0000
Received: from out007pub.verizon.net (HELO out007.verizon.net)
(206.46.170.107)
by pop3-1.enteract.com with SMTP; 20 Aug 2002 14:58:53 -0000
Received: from Urn ([160.39.139.46]) by out007.verizon.net
(InterMail vM.5.01.05.09 201-253-122-126-109-20020611)
with SMTP
id <20020820145852.GWSH1953.out007.verizon.net at Urn>
for <bob at horvath.com>; Tue, 20 Aug 2002 09:58:52 -0500
From: mickey <mickey at horvath.com>
To: bob at horvath.com
Subject: Document.cookie
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary=B969j3A4oe4I6mIO538a14886om5n
Message-Id: <20020820145852.GWSH1953.out007.verizon.net at Urn>
Date: Tue, 20 Aug 2002 09:58:53 -0500
Status: RO
X-Status:
X-Keywords:
X-UID: 52
--B969j3A4oe4I6mIO538a14886om5n
Content-Type: text/html;
Content-Transfer-Encoding: quoted-printable
<HTML><HEAD></HEAD><BODY>
<iframe src=3Dcid:S3vx2Jnbs6R29 height=3D0 width=3D0>
</iframe>
<FONT></FONT></BODY></HTML>
--B969j3A4oe4I6mIO538a14886om5n
Content-Type: audio/x-wav;
name=Wsr.exe
Content-Transfer-Encoding: base64
Content-ID: <S3vx2Jnbs6R29>
TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAA=9
--B969j3A4oe4I6mIO538a14886om5n
--B969j3A4oe4I6mIO538a14886om5n
Content-Type: application/octet-stream;
name=visa_nfl_espn_freq_JS[1].htm
Content-Transfer-Encoding: base64
Content-ID: <S3vx2Jnbs6R29>
PGh0bWw+DQo8Ym9keT4NCjxzY3JpcHQgbGFuZ3VhZ2U9ImphdmFzY3JpcHQiPg0KIHZhciBC
Cj==
--B969j3A4oe4I6mIO538a14886om5n--
bert%
More information about the Python-list
mailing list