Mercurial > cpython-lru_cache-weakref
annotate 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 |
| rev | line source |
|---|---|
|
59745
fe4115692f76
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 |
|
fe4115692f76
Adding an example of reproducing the rfc822.Message() parsing.
Sean Reifscheider <jafo@tummy.com>
parents:
diff
changeset
|
2 from email.parser import Parser |
|
fe4115692f76
Adding an example of reproducing the rfc822.Message() parsing.
Sean Reifscheider <jafo@tummy.com>
parents:
diff
changeset
|
3 |
|
fe4115692f76
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: |
|
59747
a5f796fb61a1
Fixing the file call in the rfc822.Message replacement example.
Sean Reifscheider <jafo@tummy.com>
parents:
59745
diff
changeset
|
5 #headers = Parser().parse(open(messagefile, 'r')) |
|
59745
fe4115692f76
Adding an example of reproducing the rfc822.Message() parsing.
Sean Reifscheider <jafo@tummy.com>
parents:
diff
changeset
|
6 |
|
fe4115692f76
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: |
|
fe4115692f76
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' |
|
fe4115692f76
Adding an example of reproducing the rfc822.Message() parsing.
Sean Reifscheider <jafo@tummy.com>
parents:
diff
changeset
|
9 'To: <someone_else@example.com>\n' |
|
fe4115692f76
Adding an example of reproducing the rfc822.Message() parsing.
Sean Reifscheider <jafo@tummy.com>
parents:
diff
changeset
|
10 'Subject: Test message\n' |
|
fe4115692f76
Adding an example of reproducing the rfc822.Message() parsing.
Sean Reifscheider <jafo@tummy.com>
parents:
diff
changeset
|
11 '\n' |
|
fe4115692f76
Adding an example of reproducing the rfc822.Message() parsing.
Sean Reifscheider <jafo@tummy.com>
parents:
diff
changeset
|
12 'Body would go here\n') |
|
fe4115692f76
Adding an example of reproducing the rfc822.Message() parsing.
Sean Reifscheider <jafo@tummy.com>
parents:
diff
changeset
|
13 |
|
fe4115692f76
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: |
|
fe4115692f76
Adding an example of reproducing the rfc822.Message() parsing.
Sean Reifscheider <jafo@tummy.com>
parents:
diff
changeset
|
15 print 'To: %s' % headers['to'] |
|
fe4115692f76
Adding an example of reproducing the rfc822.Message() parsing.
Sean Reifscheider <jafo@tummy.com>
parents:
diff
changeset
|
16 print 'From: %s' % headers['from'] |
|
fe4115692f76
Adding an example of reproducing the rfc822.Message() parsing.
Sean Reifscheider <jafo@tummy.com>
parents:
diff
changeset
|
17 print 'Subject: %s' % headers['subject'] |
