What am I doing wrong here?

Skip Montanaro skip at pobox.com
Fri Jul 9 15:47:29 EDT 2004


>>>>> "Skip" == Skip Montanaro <skip at pobox.com> writes:

    Skip> Appended to this message is a simple script ...

Doh...  Here it is:

##################################################
import os, mailbox, email, tempfile

s = """\
>From skip Thu Jul  8 14:50:00 -0500 2004
From: Skip Montanaro <skip at pobox.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Message-ID: <16621.42344.801832.350345 at montanaro.dyndns.org>
Date: Thu, 8 Jul 2004 14:50:00 -0500
To: "Paul Watson" <pwatson at redlinepy.com>
Cc: python-list at python.org
Subject: Re: csv reading fields
Newsgroups: comp.lang.python
In-Reply-To: <2l5lknF8umavU1 at uni-berlin.de>
References: <40ed95dd$1_6 at corp.newsgroups.com>
        <2l5lknF8umavU1 at uni-berlin.de>
X-Mailer: VM 7.17 under 21.5  (beta17) "chayote" (+CVS-20040530) XEmacs Lucid
Reply-To: skip at pobox.com


    Paul> I would agree that the documentation in 12.20 should show an
    Paul> explicit example of accessing a single field.

Done...

Skip

"""

fd, name = tempfile.mkstemp()
f = os.fdopen(fd, "w+b")
f.seek(0)
f.write(s)
f.seek(0)
mbox = mailbox.PortableUnixMailbox(f, email.message_from_file)
for msg in mbox:
    print msg.__class__.__name__
    print msg
f.close()
os.unlink(name)
##################################################

Here's the output I get:

##################################################
% python testmbox.py
Message
>From nobody Fri Jul  9 14:45:45 2004


##################################################

Note that it is currently 2:45PM, so the From_ line is generated, not taken
from the input message.  That's not my main problem thought.  Where's my
message?

Skip




More information about the Python-list mailing list