mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Adding an example of reproducing the rfc822.Message() parsing.
This commit is contained in:
parent
cc1d06b3ae
commit
95ce1fcf8b
2 changed files with 23 additions and 0 deletions
17
Doc/includes/email-headers.py
Normal file
17
Doc/includes/email-headers.py
Normal file
|
@ -0,0 +1,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']
|
Loading…
Add table
Add a link
Reference in a new issue