summaryrefslogtreecommitdiffstats
path: root/Doc/includes/email-headers.py
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/includes/email-headers.py')
-rw-r--r--Doc/includes/email-headers.py23
1 files changed, 8 insertions, 15 deletions
diff --git a/Doc/includes/email-headers.py b/Doc/includes/email-headers.py
index 2c42145..664c3ff 100644
--- a/Doc/includes/email-headers.py
+++ b/Doc/includes/email-headers.py
@@ -1,24 +1,17 @@
# Import the email modules we'll need
-from email.parser import BytesParser, Parser
-from email.policy import default
+from email.parser import Parser
-# If the e-mail headers are in a file, uncomment these two lines:
-# with open(messagefile, 'rb') as fp:
-# headers = BytesParser(policy=default).parse(fp)
+# 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 (this is an uncommon operation), use:
-headers = Parser(policy=default).parsestr(
- 'From: Foo Bar <user@example.com>\n'
+# 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: {}'.format(headers['to']))
-print('From: {}'.format(headers['from']))
-print('Subject: {}'.format(headers['subject']))
-
-# You can also access the parts of the addresses:
-print('Recipient username: {}'.format(headers['to'].addresses[0].username))
-print('Sender name: {}'.format(headers['from'].addresses[0].display_name))
+print 'To: %s' % headers['to']
+print 'From: %s' % headers['from']
+print 'Subject: %s' % headers['subject']