Iterating over a message object tree is fairly easy with theMessage.walk() method. Theemail.iterators moduleprovides some useful higher level iterations over message objecttrees.
| msg[, decode]) |
Optionaldecode is passed through toMessage.get_payload().
| msg[, maintype[, subtype]]) |
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.
| msg[, fp[, level]]) |
>>> 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.