Mercurial > cpython-lru_cache-weakref
annotate Doc/lib/emailparser.tex @ 25838:8540887bcec6 2.2
Backport of 2.183:
Fix memory leak in add_subclass() found by NealN with valgrind.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 18 Oct 2002 13:42:21 +0000 |
| parents | 13fb4d16f604 |
| children |
| rev | line source |
|---|---|
|
20098
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1 \declaremodule{standard}{email.Parser} |
|
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
2 \modulesynopsis{Parse flat text email messages to produce a message |
|
25559
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
3 object structure.} |
|
20098
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
4 |
|
25559
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
5 Message object structures can be created in one of two ways: they can be |
|
20121
f822b356c3d9
Updates do email package documentation for markup, style, and
Barry Warsaw <barry@python.org>
parents:
20098
diff
changeset
|
6 created from whole cloth by instantiating \class{Message} objects and |
|
25559
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
7 stringing them together via \method{attach()} and |
|
20121
f822b356c3d9
Updates do email package documentation for markup, style, and
Barry Warsaw <barry@python.org>
parents:
20098
diff
changeset
|
8 \method{set_payload()} calls, or they can be created by parsing a flat text |
|
f822b356c3d9
Updates do email package documentation for markup, style, and
Barry Warsaw <barry@python.org>
parents:
20098
diff
changeset
|
9 representation of the email message. |
|
20098
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
10 |
|
20121
f822b356c3d9
Updates do email package documentation for markup, style, and
Barry Warsaw <barry@python.org>
parents:
20098
diff
changeset
|
11 The \module{email} package provides a standard parser that understands |
|
f822b356c3d9
Updates do email package documentation for markup, style, and
Barry Warsaw <barry@python.org>
parents:
20098
diff
changeset
|
12 most email document structures, including MIME documents. You can |
|
f822b356c3d9
Updates do email package documentation for markup, style, and
Barry Warsaw <barry@python.org>
parents:
20098
diff
changeset
|
13 pass the parser a string or a file object, and the parser will return |
|
25559
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
14 to you the root \class{Message} instance of the object structure. For |
|
20121
f822b356c3d9
Updates do email package documentation for markup, style, and
Barry Warsaw <barry@python.org>
parents:
20098
diff
changeset
|
15 simple, non-MIME messages the payload of this root object will likely |
|
20459
c68d1855daa9
Fix a few usage and style-guide conformance issues.
Fred Drake <fdrake@acm.org>
parents:
20374
diff
changeset
|
16 be a string containing the text of the message. For MIME |
|
25559
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
17 messages, the root object will return \code{True} from its |
|
20121
f822b356c3d9
Updates do email package documentation for markup, style, and
Barry Warsaw <barry@python.org>
parents:
20098
diff
changeset
|
18 \method{is_multipart()} method, and the subparts can be accessed via |
|
f822b356c3d9
Updates do email package documentation for markup, style, and
Barry Warsaw <barry@python.org>
parents:
20098
diff
changeset
|
19 the \method{get_payload()} and \method{walk()} methods. |
|
20098
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
20 |
|
20121
f822b356c3d9
Updates do email package documentation for markup, style, and
Barry Warsaw <barry@python.org>
parents:
20098
diff
changeset
|
21 Note that the parser can be extended in limited ways, and of course |
|
f822b356c3d9
Updates do email package documentation for markup, style, and
Barry Warsaw <barry@python.org>
parents:
20098
diff
changeset
|
22 you can implement your own parser completely from scratch. There is |
|
f822b356c3d9
Updates do email package documentation for markup, style, and
Barry Warsaw <barry@python.org>
parents:
20098
diff
changeset
|
23 no magical connection between the \module{email} package's bundled |
|
f822b356c3d9
Updates do email package documentation for markup, style, and
Barry Warsaw <barry@python.org>
parents:
20098
diff
changeset
|
24 parser and the \class{Message} class, so your custom parser can create |
| 22005 | 25 message object trees any way it finds necessary. |
|
20121
f822b356c3d9
Updates do email package documentation for markup, style, and
Barry Warsaw <barry@python.org>
parents:
20098
diff
changeset
|
26 |
|
20374
94983942c94b
Describe the HeaderParser class.
Barry Warsaw <barry@python.org>
parents:
20121
diff
changeset
|
27 The primary parser class is \class{Parser} which parses both the |
|
94983942c94b
Describe the HeaderParser class.
Barry Warsaw <barry@python.org>
parents:
20121
diff
changeset
|
28 headers and the payload of the message. In the case of |
|
94983942c94b
Describe the HeaderParser class.
Barry Warsaw <barry@python.org>
parents:
20121
diff
changeset
|
29 \mimetype{multipart} messages, it will recursively parse the body of |
|
25559
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
30 the container message. Two modes of parsing are supported, |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
31 \emph{strict} parsing, which will usually reject any non-RFC compliant |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
32 message, and \emph{lax} parsing, which attempts to adjust for common |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
33 MIME formatting problems. |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
34 |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
35 The \module{email.Parser} module also provides a second class, called |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
36 \class{HeaderParser} which can be used if you're only interested in |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
37 the headers of the message. \class{HeaderParser} can be much faster in |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
38 these situations, since it does not attempt to parse the message body, |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
39 instead setting the payload to the raw body as a string. |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
40 \class{HeaderParser} has the same API as the \class{Parser} class. |
|
20374
94983942c94b
Describe the HeaderParser class.
Barry Warsaw <barry@python.org>
parents:
20121
diff
changeset
|
41 |
|
20121
f822b356c3d9
Updates do email package documentation for markup, style, and
Barry Warsaw <barry@python.org>
parents:
20098
diff
changeset
|
42 \subsubsection{Parser class API} |
|
20098
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
43 |
|
25559
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
44 \begin{classdesc}{Parser}{\optional{_class\optional{, strict}}} |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
45 The constructor for the \class{Parser} class takes an optional |
|
20459
c68d1855daa9
Fix a few usage and style-guide conformance issues.
Fred Drake <fdrake@acm.org>
parents:
20374
diff
changeset
|
46 argument \var{_class}. This must be a callable factory (such as a |
|
c68d1855daa9
Fix a few usage and style-guide conformance issues.
Fred Drake <fdrake@acm.org>
parents:
20374
diff
changeset
|
47 function or a class), and it is used whenever a sub-message object |
|
c68d1855daa9
Fix a few usage and style-guide conformance issues.
Fred Drake <fdrake@acm.org>
parents:
20374
diff
changeset
|
48 needs to be created. It defaults to \class{Message} (see |
|
c68d1855daa9
Fix a few usage and style-guide conformance issues.
Fred Drake <fdrake@acm.org>
parents:
20374
diff
changeset
|
49 \refmodule{email.Message}). The factory will be called without |
|
20098
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
50 arguments. |
|
25559
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
51 |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
52 The optional \var{strict} flag specifies whether strict or lax parsing |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
53 should be performed. Normally, when things like MIME terminating |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
54 boundaries are missing, or when messages contain other formatting |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
55 problems, the \class{Parser} will raise a |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
56 \exception{MessageParseError}. However, when lax parsing is enabled, |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
57 the \class{Parser} will attempt to work around such broken formatting |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
58 to produce a usable message structure (this doesn't mean |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
59 \exception{MessageParseError}s are never raised; some ill-formatted |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
60 messages just can't be parsed). The \var{strict} flag defaults to |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
61 \code{False} since lax parsing usually provides the most convenient |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
62 behavior. |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
63 |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
64 \versionchanged[The \var{strict} flag was added]{2.2.2} |
|
20098
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
65 \end{classdesc} |
|
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
66 |
|
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
67 The other public \class{Parser} methods are: |
|
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
68 |
|
25559
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
69 \begin{methoddesc}[Parser]{parse}{fp\optional{, headersonly}} |
|
20098
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
70 Read all the data from the file-like object \var{fp}, parse the |
|
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
71 resulting text, and return the root message object. \var{fp} must |
|
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
72 support both the \method{readline()} and the \method{read()} methods |
|
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
73 on file-like objects. |
|
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
74 |
|
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
75 The text contained in \var{fp} must be formatted as a block of \rfc{2822} |
|
25559
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
76 style headers and header continuation lines, optionally preceded by a |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
77 envelope header. The header block is terminated either by the |
|
20098
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
78 end of the data or by a blank line. Following the header block is the |
|
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
79 body of the message (which may contain MIME-encoded subparts). |
|
25559
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
80 |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
81 Optional \var{headersonly} is as with the \method{parse()} method. |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
82 |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
83 \versionchanged[The \var{headersonly} flag was added]{2.2.2} |
|
20098
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
84 \end{methoddesc} |
|
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
85 |
|
25559
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
86 \begin{methoddesc}[Parser]{parsestr}{text\optional{, headersonly}} |
|
20098
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
87 Similar to the \method{parse()} method, except it takes a string |
|
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
88 object instead of a file-like object. Calling this method on a string |
|
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
89 is exactly equivalent to wrapping \var{text} in a \class{StringIO} |
|
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
90 instance first and calling \method{parse()}. |
|
25559
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
91 |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
92 Optional \var{headersonly} is a flag specifying whether to stop |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
93 parsing after reading the headers or not. The default is \code{False}, |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
94 meaning it parses the entire contents of the file. |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
95 |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
96 \versionchanged[The \var{headersonly} flag was added]{2.2.2} |
|
20098
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
97 \end{methoddesc} |
|
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
98 |
|
25559
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
99 Since creating a message object structure from a string or a file |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
100 object is such a common task, two functions are provided as a |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
101 convenience. They are available in the top-level \module{email} |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
102 package namespace. |
|
20098
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
103 |
|
25559
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
104 \begin{funcdesc}{message_from_string}{s\optional{, _class\optional{, strict}}} |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
105 Return a message object structure from a string. This is exactly |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
106 equivalent to \code{Parser().parsestr(s)}. Optional \var{_class} and |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
107 \var{strict} are interpreted as with the \class{Parser} class constructor. |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
108 |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
109 \versionchanged[The \var{strict} flag was added]{2.2.2} |
|
20098
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
110 \end{funcdesc} |
|
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
111 |
|
25559
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
112 \begin{funcdesc}{message_from_file}{fp\optional{, _class\optional{, strict}}} |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
113 Return a message object structure tree from an open file object. This |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
114 is exactly equivalent to \code{Parser().parse(fp)}. Optional |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
115 \var{_class} and \var{strict} are interpreted as with the |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
116 \class{Parser} class constructor. |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
117 |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
118 \versionchanged[The \var{strict} flag was added]{2.2.2} |
|
20098
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
119 \end{funcdesc} |
|
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
120 |
|
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
121 Here's an example of how you might use this at an interactive Python |
|
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
122 prompt: |
|
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
123 |
|
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
124 \begin{verbatim} |
|
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
125 >>> import email |
|
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
126 >>> msg = email.message_from_string(myString) |
|
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
127 \end{verbatim} |
|
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
128 |
|
20121
f822b356c3d9
Updates do email package documentation for markup, style, and
Barry Warsaw <barry@python.org>
parents:
20098
diff
changeset
|
129 \subsubsection{Additional notes} |
|
20098
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
130 |
|
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
131 Here are some notes on the parsing semantics: |
|
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
132 |
|
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
133 \begin{itemize} |
|
20121
f822b356c3d9
Updates do email package documentation for markup, style, and
Barry Warsaw <barry@python.org>
parents:
20098
diff
changeset
|
134 \item Most non-\mimetype{multipart} type messages are parsed as a single |
|
20098
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
135 message object with a string payload. These objects will return |
|
25559
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
136 \code{False} for \method{is_multipart()}. Their |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
137 \method{get_payload()} method will return a string object. |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
138 |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
139 \item All \mimetype{multipart} type messages will be parsed as a |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
140 container message object with a list of sub-message objects for |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
141 their payload. The outer container message will return |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
142 \code{True} for \method{is_multipart()} and their |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
143 \method{get_payload()} method will return the list of |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
144 \class{Message} subparts. |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
145 |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
146 \item Most messages with a content type of \mimetype{message/*} |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
147 (e.g. \mimetype{message/deliver-status} and |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
148 \mimetype{message/rfc822}) will also be parsed as container |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
149 object containing a list payload of length 1. Their |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
150 \method{is_multipart()} method will return \code{True}. The |
|
13fb4d16f604
Backporting of email 2.4 from Python 2.3. Many newly added modules,
Barry Warsaw <barry@python.org>
parents:
22005
diff
changeset
|
151 single element in the list payload will be a sub-message object. |
|
20098
56bdd90c9fd6
The email package documentation, currently organized the way I think
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
152 \end{itemize} |
