What am I doing wrong here?

Ludovico Magnocavallo ludo at asiatica.org
Sat Jul 10 19:43:39 EDT 2004


Skip Montanaro wrote:

> 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?

Running a (slightly modified but essentially identical version of your 
script I get nothing, but if I remove the > escape from the first From 
the script behaves as it should.

 From /usr/lib/python2.3/mailbox.py:126

# the only portable, reliable way to find message delimiters in a BSD (i.e
# Unix mailbox) style folder is to search for "\n\nFrom .*\n", or at the
# beginning of the file, "^From .*\n".

This is the script I used:

-------------------------------------------------

#!/usr/bin/python

import email, mailbox
from cStringIO import StringIO

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

"""

mbox = mailbox.PortableUnixMailbox(StringIO(s), email.message_from_file)
for msg in mbox:
     print msg.__class__.__name__
     print msg
--------------------------------------------------------------------------

Ludo



More information about the Python-list mailing list