Movatterモバイル変換


[0]ホーム

URL:


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:12.2.9 Miscellaneous utilitiesUp:12.2 emailNext:12.2.11 Differences from email

12.2.10 Iterators

Iterating over a message object tree is fairly easy with theMessage.walk() method. Theemail.Iterators moduleprovides some useful higher level iterations over message objecttrees.

body_line_iterator(msg[, decode])
This iterates over all the payloads in all the subparts ofmsg,returning the string payloads line-by-line. It skips over all thesubpart headers, and it skips over any subpart with a payload thatisn't a Python string. This is somewhat equivalent to reading theflat text representation of the message from a file usingreadline(), skipping over all the intervening headers.

Optionaldecode is passed through toMessage.get_payload().

typed_subpart_iterator(msg[, maintype[, subtype]])
This iterates over all the subparts ofmsg, returning only thosesubparts that match the MIME type specified bymaintype andsubtype.

Note thatsubtype is optional; if omitted, then subpart MIMEtype matching is done only with the main type.maintype isoptional too; it defaults totext.

Thus, by defaulttyped_subpart_iterator() returns eachsubpart that has a MIME type oftext/*.

The following function has been added as a useful debugging tool. Itshouldnot be considered part of the supported public interfacefor the package.

_structure(msg[, fp[, level]])
Prints an indented representation of the content types of themessage object structure. For example:

>>> msg = email.message_from_file(somefile)>>> _structure(msg)multipart/mixed    text/plain    text/plain    multipart/digest        message/rfc822            text/plain        message/rfc822            text/plain        message/rfc822            text/plain        message/rfc822            text/plain        message/rfc822            text/plain    text/plain

Optionalfp is a file-like object to print the output to. Itmust be suitable for Python's extended print statement.levelis used internally.


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:12.2.9 Miscellaneous utilitiesUp:12.2 emailNext:12.2.11 Differences from email
Release 2.2.3, documentation updated on 30 May 2003.
SeeAbout this document... for information on suggesting changes.
[8]ページ先頭

©2009-2026 Movatter.jp