blob: edaac235f35ea86e1014214a46a4848b85c6b616 [file] [log] [blame]
Sean Reifscheider95ce1fc2010-03-19 23:19:55 +00001# Import the email modules we'll need
2from email.parser import Parser
3
4# If the e-mail headers are in a file, uncomment this line:
5#headers = Parser().parse(messagefile)
6
7# Or for parsing headers in a string, use:
8headers = Parser().parsestr('From: <user@example.com>\n'
9 'To: <someone_else@example.com>\n'
10 'Subject: Test message\n'
11 '\n'
12 'Body would go here\n')
13
14# Now the header items can be accessed as a dictionary:
15print 'To: %s' % headers['to']
16print 'From: %s' % headers['from']
17print 'Subject: %s' % headers['subject']