Email package and mailbox module
Chirag Wazir
cwazir at yahoo.com
Tue Jan 14 22:16:06 EST 2003
Here's a bit of code to do this:
##############################################################
import cStringIO, mailbox
# read the entire mailbox into memory
mailboxFile = concat(r'C:\Work\PocoMail\Mail\Backup.mbx', 'r')
mailboxString = cStringIO.StringIO(mailboxFile.read())
mailboxFile.close()
# process each mail
for mail in mailbox.PortableUnixMailbox(mailboxString):
# show the headers
for h in mail.headers:
print h,
# show the body
mail.rewindbody()
print mail.fp.read(),
##############################################################
Chirag Wazir
http://chirag.freeshell.org
Chris Keyes <chrisk at nipltd.com> wrote:
> I'm currently trying to extract email messages from a mailbox file
> ....
> I want both the body and the headers (basically to index the contents of
> the message)....
More information about the Python-list
mailing list