S
Samuel Wright
Hi Guys
Using Python 2.3 here, trying to parse a MBOX email file using the code below:
------------------------
mailboxfile = 'emails.txt'
import email
import email.Errors, email.Parser, email.Message
import mailbox
def msgfactory(fp):
try:
return email.message_from_file(fp)
except email.Errors.MessageParseError:
# Don't return None since that will
# stop the mailbox iterator
return ''
def main():
fp = open(mailboxfile, 'r')
mbox = mailbox.UnixMailbox(fp, msgfactory)
for msg in mbox:
print msg
for part in msg.walk():
print part
if __name__=="__main__":
main()
Using Python 2.3 here, trying to parse a MBOX email file using the code below:
------------------------
mailboxfile = 'emails.txt'
import email
import email.Errors, email.Parser, email.Message
import mailbox
def msgfactory(fp):
try:
return email.message_from_file(fp)
except email.Errors.MessageParseError:
# Don't return None since that will
# stop the mailbox iterator
return ''
def main():
fp = open(mailboxfile, 'r')
mbox = mailbox.UnixMailbox(fp, msgfactory)
for msg in mbox:
print msg
for part in msg.walk():
print part
if __name__=="__main__":
main()