blob: fbaafbb91dc287264448ba8238b91d71cc33fa4d [file] [log] [blame]
Barry Warsaw5e634632001-09-26 05:23:47 +00001\section{\module{email.Iterators} ---
2 Message object tree iterators}
3
4\declaremodule{standard}{email.Iterators}
5\modulesynopsis{Iterate over a message object tree.}
6\sectionauthor{Barry A. Warsaw}{barry@zope.com}
7
8\versionadded{2.2}
9
10Iterating over a message object tree is fairly easy with the
11\method{Message.walk()} method. The \module{email.Iterators} module
12provides some useful higher level iterations over message object
13trees.
14
15\begin{funcdesc}{body_line_iterator}{msg}
16This iterates over all the payloads in all the subparts of \var{msg},
17returning the string payloads line-by-line. It skips over all the
18subpart headers, and it skips over any subpart with a payload that
19isn't a Python string. This is somewhat equivalent to reading the
20flat text representation of the message from a file using
21\method{readline()}, skipping over all the intervening headers.
22\end{funcdesc}
23
24\begin{funcdesc}{typed_subpart_iterator}{msg\optional{,
25 maintype\optional{, subtype}}}
26This iterates over all the subparts of \var{msg}, returning only those
27subparts that match the MIME type specified by \var{maintype} and
28\var{subtype}.
29
30Note that \var{subtype} is optional; if omitted, then subpart MIME
31type matching is done only with the main type. \var{maintype} is
32optional too; it defaults to \code{text}.
33
34Thus, by default \function{typed_subpart_iterator()} returns each
35subpart that has a MIME type of \code{text/*}.
36\end{funcdesc}
37