Barry Warsaw | 5e63463 | 2001-09-26 05:23:47 +0000 | [diff] [blame^] | 1 | \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 | |
| 10 | Iterating over a message object tree is fairly easy with the |
| 11 | \method{Message.walk()} method. The \module{email.Iterators} module |
| 12 | provides some useful higher level iterations over message object |
| 13 | trees. |
| 14 | |
| 15 | \begin{funcdesc}{body_line_iterator}{msg} |
| 16 | This iterates over all the payloads in all the subparts of \var{msg}, |
| 17 | returning the string payloads line-by-line. It skips over all the |
| 18 | subpart headers, and it skips over any subpart with a payload that |
| 19 | isn't a Python string. This is somewhat equivalent to reading the |
| 20 | flat 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}}} |
| 26 | This iterates over all the subparts of \var{msg}, returning only those |
| 27 | subparts that match the MIME type specified by \var{maintype} and |
| 28 | \var{subtype}. |
| 29 | |
| 30 | Note that \var{subtype} is optional; if omitted, then subpart MIME |
| 31 | type matching is done only with the main type. \var{maintype} is |
| 32 | optional too; it defaults to \code{text}. |
| 33 | |
| 34 | Thus, by default \function{typed_subpart_iterator()} returns each |
| 35 | subpart that has a MIME type of \code{text/*}. |
| 36 | \end{funcdesc} |
| 37 | |