Movatterモバイル変換


[0]ホーム

URL:


Up one LevelPython Library ReferenceContentsModule IndexIndex

7.1.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.


Up one LevelPython Library ReferenceContentsModule IndexIndex

Release 2.5.2, documentation updated on 21st February, 2008.
SeeAbout this document... for information on suggesting changes.
[8]ページ先頭

©2009-2025 Movatter.jp