[Help]: mailbox classes

François Granger fgranger at alussinan.org
Fri Sep 20 13:27:11 EDT 2002


François Granger <fgranger at alussinan.org> wrote:

> Alex Martelli <aleax at aleax.it> wrote:
> 
> > J. Li wrote:
> > 
> > > Hi,
> > > 
> > > I am trying to extract a message from a unix mailbox file.
> ...
> > 
> > > what is it relationship with email.message classes.
> > 
> > Not much, intrinsically -- the items in a mailbox object by
> > default are rfc822.Message instances.  But you can pass as
> > the second argument to the constructor a factory with a
> > compatible interface, which should let you get email.Message
> > instances instead, if that's what you want.
> 
> email does not handle the unix mailbox properly. It sees only the first
> message.
> 
> I was going the way you suggest by first using mailbox.UnixMailbox, then
> i'd like to pass each message given by the next() method to email for
> further analysis. But this is way over my current level of understanding
> of Python objects and classes. ....

after some thought and some trial and errors, I came with this solution.
I don't like it, it look bad.

def main():
    fp = file(folderfile)
    folder = mailbox.UnixMailbox(fp, factory=email.message_from_file)
    while 1:
        mail = email.message_from_file(fp)
        print mail
        if not folder.next():
            break
        #mail = email.message_from_file(fp)

if __name__ == '__main__':
    main()


-- 
"Ce qui est gratuit ne vaut pas cher" - inconnu



More information about the Python-list mailing list