Created
November 19, 2012 04:44
-
-
Save seajosh/4109022 to your computer and use it in GitHub Desktop.
the 'hello, world' of email processing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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