annotate Doc/includes/email-headers.py @ 79691:05c8928362ee

Merge __next__ method link fixes with 3.3.
author Ezio Melotti <ezio.melotti@gmail.com>
date Fri, 12 Oct 2012 13:46:37 +0300
parents 74d81a3a0d56
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
59746
9acb7c156075 Adding an example of reproducing the rfc822.Message() parsing.
Sean Reifscheider <jafo@tummy.com>
parents:
diff changeset
1 # Import the email modules we'll need
9acb7c156075 Adding an example of reproducing the rfc822.Message() parsing.
Sean Reifscheider <jafo@tummy.com>
parents:
diff changeset
2 from email.parser import Parser
9acb7c156075 Adding an example of reproducing the rfc822.Message() parsing.
Sean Reifscheider <jafo@tummy.com>
parents:
diff changeset
3
9acb7c156075 Adding an example of reproducing the rfc822.Message() parsing.
Sean Reifscheider <jafo@tummy.com>
parents:
diff changeset
4 # If the e-mail headers are in a file, uncomment this line:
59748
706957d6ecdf Fixing the file call in the rfc822.Message replacement example.
Sean Reifscheider <jafo@tummy.com>
parents: 59746
diff changeset
5 #headers = Parser().parse(open(messagefile, 'r'))
59746
9acb7c156075 Adding an example of reproducing the rfc822.Message() parsing.
Sean Reifscheider <jafo@tummy.com>
parents:
diff changeset
6
9acb7c156075 Adding an example of reproducing the rfc822.Message() parsing.
Sean Reifscheider <jafo@tummy.com>
parents:
diff changeset
7 # Or for parsing headers in a string, use:
9acb7c156075 Adding an example of reproducing the rfc822.Message() parsing.
Sean Reifscheider <jafo@tummy.com>
parents:
diff changeset
8 headers = Parser().parsestr('From: <user@example.com>\n'
9acb7c156075 Adding an example of reproducing the rfc822.Message() parsing.
Sean Reifscheider <jafo@tummy.com>
parents:
diff changeset
9 'To: <someone_else@example.com>\n'
9acb7c156075 Adding an example of reproducing the rfc822.Message() parsing.
Sean Reifscheider <jafo@tummy.com>
parents:
diff changeset
10 'Subject: Test message\n'
9acb7c156075 Adding an example of reproducing the rfc822.Message() parsing.
Sean Reifscheider <jafo@tummy.com>
parents:
diff changeset
11 '\n'
9acb7c156075 Adding an example of reproducing the rfc822.Message() parsing.
Sean Reifscheider <jafo@tummy.com>
parents:
diff changeset
12 'Body would go here\n')
9acb7c156075 Adding an example of reproducing the rfc822.Message() parsing.
Sean Reifscheider <jafo@tummy.com>
parents:
diff changeset
13
9acb7c156075 Adding an example of reproducing the rfc822.Message() parsing.
Sean Reifscheider <jafo@tummy.com>
parents:
diff changeset
14 # Now the header items can be accessed as a dictionary:
65473
74d81a3a0d56 Syntax fixes for examples in the Doc/includes
Senthil Kumaran <orsenthil@gmail.com>
parents: 59748
diff changeset
15 print('To: %s' % headers['to'])
74d81a3a0d56 Syntax fixes for examples in the Doc/includes
Senthil Kumaran <orsenthil@gmail.com>
parents: 59748
diff changeset
16 print('From: %s' % headers['from'])
74d81a3a0d56 Syntax fixes for examples in the Doc/includes
Senthil Kumaran <orsenthil@gmail.com>
parents: 59748
diff changeset
17 print('Subject: %s' % headers['subject'])