[Help]: mailbox classes
fgranger at alussinan.org
Fri Sep 20 19:27:11 CEST 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
> 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.
fp = file(folderfile)
folder = mailbox.UnixMailbox(fp, factory=email.message_from_file)
mail = email.message_from_file(fp)
if not folder.next():
#mail = email.message_from_file(fp)
if __name__ == '__main__':
"Ce qui est gratuit ne vaut pas cher" - inconnu
More information about the Python-list