[Help]: mailbox classes

Jeff Davis jdavis at empires.org
Thu Sep 19 08:36:34 CEST 2002


Ok, I'll assume your using mbox format, but this is easily adapted for 
maildir, etc.

import mailbox
mbox_file = '/path/to/mbox'

mbox_fp = open(mbox_file)
mbox = mailbox.UnixMailbox(mbox_fp)
msg = mbox.next()

there, now you have a message object (a rfc822.Message object, to be 
exact). Now just import the rfc822 module and do whatever you need. You'll 
probably want to use a loop to process all of the messages.

Regards,
        Jeff
        

> Hi,
> 
> I am trying to extract a message from a unix mailbox file. Python does
> provide few classes for easy and uniform access. So it says! After
> having read the libiary references, I went nowhere.
> 
> Can anyone give me an example as how to use these mailbox classes and
> what is it relationship with email.message classes.
> 
> thanks




More information about the Python-list mailing list