Skip to content

Instantly share code, notes, and snippets.

@seajosh
Created November 19, 2012 04:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seajosh/4109022 to your computer and use it in GitHub Desktop.
Save seajosh/4109022 to your computer and use it in GitHub Desktop.
the 'hello, world' of email processing
#!/usr/bin/env python2.7
# the 'hello, world' of email processing
# open an mbox data file and print the email body
# example mbox files => http://pig.apache.org/mail/user/
# mbox => http://en.wikipedia.org/wiki/Mbox
import mailbox
box = mailbox.mbox(path='/tmp/200710')
for key,msg in box.items():
email = ''
if (msg.is_multipart()):
for part in msg.walk():
if 'text/plain' == msg.get_content_type():
email = part.get_payload(decode=True)
else:
email = msg.get_payload(decode=True)
print('%s\n\n' % email)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment