Mercurial > cpython-lru_cache-weakref
view Doc/includes/email-headers.py @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | a5f796fb61a1 |
| children | 74d81a3a0d56 |
line wrap: on
line source
# 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(open(messagefile, 'r')) # 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']
