[Help]: mailbox classes
Huaiyu Zhu
huaiyu at gauss.almadan.ibm.com
Fri Sep 20 14:34:41 EDT 2002
J. Li <jylimd at yahoo.com> wrote:
>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
I just figured this out yesterday following examples in spambayes project.
The documentation is very fuzzy, but this works for me:
from mailbox import PortableUnixMailbox as MB
from email import message_from_file as get_msg
def get_mbox(mfile):
return MB(file(mfile), get_msg)
if __name__ == '__main__':
mbox = get_mbox('test.mail')
msgs = list(mbox)
msg = msgs[2]
print msg['Subject']
print msg
Huaiyu
More information about the Python-list
mailing list