summaryrefslogtreecommitdiffstats
path: root/Doc/includes/email-headers.py
diff options
context:
space:
mode:
authorSean Reifscheider <jafo@tummy.com>2010-03-19 23:19:55 (GMT)
committerSean Reifscheider <jafo@tummy.com>2010-03-19 23:19:55 (GMT)
commit95ce1fcf8b5a53453477bb24d046497836bab150 (patch)
tree42f0c976e07de09ddfef90cbb54fb0c5fb1bef03 /Doc/includes/email-headers.py
parentcc1d06b3aefc2d23f876be8f030dc606f926a7cf (diff)
downloadcpython-95ce1fcf8b5a53453477bb24d046497836bab150.zip
cpython-95ce1fcf8b5a53453477bb24d046497836bab150.tar.gz
cpython-95ce1fcf8b5a53453477bb24d046497836bab150.tar.bz2
Adding an example of reproducing the rfc822.Message() parsing.
Diffstat (limited to 'Doc/includes/email-headers.py')
-rw-r--r--Doc/includes/email-headers.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Doc/includes/email-headers.py b/Doc/includes/email-headers.py
new file mode 100644
index 0000000..edaac23
--- /dev/null
+++ b/Doc/includes/email-headers.py
@@ -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']