summaryrefslogtreecommitdiffstats
path: root/Doc/includes/email-headers.py
blob: edaac235f35ea86e1014214a46a4848b85c6b616 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Import the email modules we'll need
from email.parser import Parser

#  If the e-mail headers are in a file, uncomment this line:
#headers = Parser().parse(messagefile)

#  Or for parsing headers in a string, use:
headers = Parser().parsestr('From: <user@example.com>\n'
        'To: <someone_else@example.com>\n'
        'Subject: Test message\n'
        '\n'
        'Body would go here\n')

#  Now the header items can be accessed as a dictionary:
print 'To: %s' % headers['to']
print 'From: %s' % headers['from']
print 'Subject: %s' % headers['subject']