email.iterators
迭代器¶
使用 Message.walk
方法。这个 email.iterators
模块在消息对象树上提供一些有用的高级迭代。
- email.iterators.body_line_iterator(msg, decode=False)¶
这将迭代所有子部分中的所有有效负载 msg ,逐行返回字符串有效负载。它跳过所有子部分标题,并跳过任何具有非python字符串的有效负载的子部分。这在某种程度上相当于从文件中读取消息的纯文本表示,使用
readline()
,跳过所有中间的头。可选的 decode 传递给
Message.get_payload
.
- email.iterators.typed_subpart_iterator(msg, maintype='text', subtype=None)¶
这将遍历 msg ,只返回与指定的mime类型匹配的子部分 主型 和 subtype .
注意 subtype 是可选的;如果省略,则子部分mime类型匹配仅与主类型匹配。 主型 也是可选的;默认为 text .
因此,默认情况下
typed_subpart_iterator()
返回mime类型为的每个子部分 text/* .
以下函数已添加为一个有用的调试工具。它应该 not 被视为包支持的公共接口的一部分。
- email.iterators._structure(msg, fp=None, level=0, include_default=False)¶
打印消息对象结构内容类型的缩进表示形式。例如:
>>> 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
可选的 fp 是要将输出打印到的类似文件的对象。它必须适合 Python 的
print()
功能。 level 内部使用。 include_default 如果为true,则也将打印默认类型。