mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-08 23:14:06 +08:00
1 line
54 KiB
HTML
1 line
54 KiB
HTML
<div class="body" role="main"><div class="section" id="module-email"><h1><span class="yiyi-st" id="yiyi-10">19.1。 <a class="reference internal" href="#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages, including MIME documents."><code class="xref py py-mod docutils literal"><span class="pre">email</span></code></a> - 电子邮件和MIME处理包</span></h1><p><span class="yiyi-st" id="yiyi-11"><strong>源代码:</strong> <a class="reference external" href="https://hg.python.org/cpython/file/3.5/Lib/email/__init__.py">Lib / email / __ init __。py</a></span></p><p><span class="yiyi-st" id="yiyi-12"><a class="reference internal" href="#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages, including MIME documents."><code class="xref py py-mod docutils literal"><span class="pre">email</span></code></a>包是用于管理电子邮件(包括MIME和其他<span class="target" id="index-0"></span> <a class="rfc reference external" href="https://tools.ietf.org/html/rfc2822.html"><strong>RFC 2822</strong></a>的邮件文档)的库。</span><span class="yiyi-st" id="yiyi-13">具体来说,<em>不是</em>旨在向SMTP(<span class="target" id="index-1"></span> <a class="rfc reference external" href="https://tools.ietf.org/html/rfc2821.html"><strong>RFC 2821</strong></a>),NNTP或其他服务器发送任何电子邮件;那些是诸如<a class="reference internal" href="smtplib.html#module-smtplib" title="smtplib: SMTP protocol client (requires sockets)."><code class="xref py py-mod docutils literal"><span class="pre">smtplib</span></code></a>和<a class="reference internal" href="nntplib.html#module-nntplib" title="nntplib: NNTP protocol client (requires sockets)."><code class="xref py py-mod docutils literal"><span class="pre">nntplib</span></code></a>之类的模块的功能。</span><span class="yiyi-st" id="yiyi-14">The <a class="reference internal" href="#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages, including MIME documents."><code class="xref py py-mod docutils literal"><span class="pre">email</span></code></a> package attempts to be as RFC-compliant as possible, supporting in addition to <span class="target" id="index-2"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2822.html"><strong>RFC 2822</strong></a>, such MIME-related RFCs as <span class="target" id="index-3"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2045.html"><strong>RFC 2045</strong></a>, <span class="target" id="index-4"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2046.html"><strong>RFC 2046</strong></a>, <span class="target" id="index-5"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2047.html"><strong>RFC 2047</strong></a>, and <span class="target" id="index-6"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2231.html"><strong>RFC 2231</strong></a>.</span></p><p><span class="yiyi-st" id="yiyi-15"><a class="reference internal" href="#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages, including MIME documents."><code class="xref py py-mod docutils literal"><span class="pre">email</span></code></a>包的主要区别功能是它分割来自内部<em>对象模型</em>电子邮件表示的电子邮件消息的解析和生成。</span><span class="yiyi-st" id="yiyi-16">使用<a class="reference internal" href="#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages, including MIME documents."><code class="xref py py-mod docutils literal"><span class="pre">email</span></code></a>包的应用程序主要处理对象;您可以向消息添加子对象,从消息中删除子对象,完全重新排列内容等。</span><span class="yiyi-st" id="yiyi-17">有一个单独的解析器和一个单独的生成器处理从平面文本到对象模型的转换,然后再回到平面文本。</span><span class="yiyi-st" id="yiyi-18">对于一些常见的MIME对象类型,还有一些方便的子类,以及一些杂项实用程序,它们帮助提取和解析消息字段值,创建符合RFC的日期等常见任务。</span></p><p><span class="yiyi-st" id="yiyi-19">以下部分描述了<a class="reference internal" href="#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages, including MIME documents."><code class="xref py py-mod docutils literal"><span class="pre">email</span></code></a>包的功能。</span><span class="yiyi-st" id="yiyi-20">排序遵循应用中常见的进展:电子邮件消息从文件或其他源读取为平面文本,解析文本以产生电子邮件消息的对象结构,操纵该结构,最后,对象树被渲染回平面文本。</span></p><p><span class="yiyi-st" id="yiyi-21">用完整的布料制造物体结构是完全可行的。</span><span class="yiyi-st" id="yiyi-22">完全从头开始。</span><span class="yiyi-st" id="yiyi-23">从那里,可以采取与上面类似的进展。</span></p><p><span class="yiyi-st" id="yiyi-24">还包括<a class="reference internal" href="#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages, including MIME documents."><code class="xref py py-mod docutils literal"><span class="pre">email</span></code></a>包提供的所有类和模块的详细规范,使用<a class="reference internal" href="#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages, including MIME documents."><code class="xref py py-mod docutils literal"><span class="pre">email</span></code></a>包时可能遇到的异常类,一些辅助实用程序和几个例子。</span><span class="yiyi-st" id="yiyi-25">对于旧版<code class="xref py py-mod docutils literal"><span class="pre">mimelib</span></code>包或<a class="reference internal" href="#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages, including MIME documents."><code class="xref py py-mod docutils literal"><span class="pre">email</span></code></a>包的早期版本的用户,提供了有关差异和移植的部分。</span></p><p><span class="yiyi-st" id="yiyi-26"><a class="reference internal" href="#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages, including MIME documents."><code class="xref py py-mod docutils literal"><span class="pre">email</span></code></a>包文档的内容:</span></p><div class="toctree-wrapper compound"><ul><li class="toctree-l1"><span class="yiyi-st" id="yiyi-27"><a class="reference internal" href="email.message.html">19.1.1. <code class="docutils literal"><span class="pre">email.message</span></code>:表示电子邮件</a></span></li><li class="toctree-l1"><span class="yiyi-st" id="yiyi-31"><a class="reference internal" href="email.parser.html">19.1.2. <code class="docutils literal"><span class="pre">email.parser</span></code>:解析电子邮件</a></span><ul><li class="toctree-l2"><span class="yiyi-st" id="yiyi-28"><a class="reference internal" href="email.parser.html#feedparser-api"> 19.1.2.1. FeedParser API</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-29"><a class="reference internal" href="email.parser.html#parser-class-api">19.1.2.2.解析器类API</a></span></li><li class="toctree-l2"><span class="yiyi-st" id="yiyi-30"><a class="reference internal" href="email.parser.html#additional-notes">19.1.2.3.其他注意事项</a></span></li></ul></li><li class="toctree-l1"><span class="yiyi-st" id="yiyi-32"><a class="reference internal" href="email.generator.html">19.1.3. <code class="docutils literal"><span class="pre">email.generator</span></code>:生成MIME文档</a></span></li><li class="toctree-l1"><span class="yiyi-st" id="yiyi-33"><a class="reference internal" href="email.policy.html">19.1.4. <code class="docutils literal"><span class="pre">email.policy</span></code>:Policy Objects</a></span></li><li class="toctree-l1"><span class="yiyi-st" id="yiyi-34"><a class="reference internal" href="email.headerregistry.html">19.1.5. <code class="docutils literal"><span class="pre">email.headerregistry</span></code>:自定义标题对象</a></span></li><li class="toctree-l1"><span class="yiyi-st" id="yiyi-36"><a class="reference internal" href="email.contentmanager.html">19.1.6. <code class="docutils literal"><span class="pre">email.contentmanager</span></code>:管理MIME内容</a></span><ul><li class="toctree-l2"><span class="yiyi-st" id="yiyi-35"><a class="reference internal" href="email.contentmanager.html#content-manager-instances">19.1.6.1.内容管理器实例</a></span></li></ul></li><li class="toctree-l1"><span class="yiyi-st" id="yiyi-37"><a class="reference internal" href="email.mime.html">19.1.7. <code class="docutils literal"><span class="pre">email.mime</span></code>:从头开始创建电子邮件和MIME对象</a></span></li><li class="toctree-l1"><span class="yiyi-st" id="yiyi-38"><a class="reference internal" href="email.header.html">19.1.8. <code class="docutils literal"><span class="pre">email.header</span></code>:国际化标头</a></span></li><li class="toctree-l1"><span class="yiyi-st" id="yiyi-39"><a class="reference internal" href="email.charset.html">19.1.9. <code class="docutils literal"><span class="pre">email.charset</span></code>:表示字符集</a></span></li><li class="toctree-l1"><span class="yiyi-st" id="yiyi-40"><a class="reference internal" href="email.encoders.html">19.1.10. <code class="docutils literal"><span class="pre">email.encoders</span></code>:Encoders</a></span></li><li class="toctree-l1"><span class="yiyi-st" id="yiyi-41"><a class="reference internal" href="email.errors.html">19.1.11. <code class="docutils literal"><span class="pre">email.errors</span></code>:异常和缺陷类</a></span></li><li class="toctree-l1"><span class="yiyi-st" id="yiyi-42"><a class="reference internal" href="email.util.html">19.1.12. <code class="docutils literal"><span class="pre">email.utils</span></code>:其他实用程序</a></span></li><li class="toctree-l1"><span class="yiyi-st" id="yiyi-43"><a class="reference internal" href="email.iterators.html">19.1.13. <code class="docutils literal"><span class="pre">email.iterators</span></code>:Iterators</a></span></li><li class="toctree-l1"><span class="yiyi-st" id="yiyi-45"><a class="reference internal" href="email-examples.html"> 19.1.14. <code class="docutils literal"><span class="pre">email</span></code>:示例</a></span><ul><li class="toctree-l2"><span class="yiyi-st" id="yiyi-44"><a class="reference internal" href="email-examples.html#examples-using-the-provisional-api">19.1.14.1.使用临时API</a>的示例</span></li></ul></li></ul></div><div class="admonition seealso"><p class="first admonition-title"><span class="yiyi-st" id="yiyi-46">也可以看看</span></p><dl class="last docutils"><dt><span class="yiyi-st" id="yiyi-47">模块<a class="reference internal" href="smtplib.html#module-smtplib" title="smtplib: SMTP protocol client (requires sockets)."><code class="xref py py-mod docutils literal"><span class="pre">smtplib</span></code></a></span></dt><dd><span class="yiyi-st" id="yiyi-48">SMTP协议客户端</span></dd><dt><span class="yiyi-st" id="yiyi-49">模块<a class="reference internal" href="nntplib.html#module-nntplib" title="nntplib: NNTP protocol client (requires sockets)."><code class="xref py py-mod docutils literal"><span class="pre">nntplib</span></code></a></span></dt><dd><span class="yiyi-st" id="yiyi-50">NNTP协议客户端</span></dd></dl></div><div class="section" id="package-history"><h2><span class="yiyi-st" id="yiyi-51">19.1.15. </span><span class="yiyi-st" id="yiyi-52">包历史</span></h2><p><span class="yiyi-st" id="yiyi-53">此表描述了电子邮件包的发布历史记录,对应于软件包发布的Python版本。</span><span class="yiyi-st" id="yiyi-54">为了本文档的目的,当您看到有关更改或添加的版本的说明时,这些更改是指在电子邮件包版本中进行的更改,<em>而不是</em>。</span><span class="yiyi-st" id="yiyi-55">此表还描述了每个版本的软件包的Python兼容性。</span></p><table border="1" class="docutils"><thead valign="bottom"><tr class="row-odd"><th class="head"><span class="yiyi-st" id="yiyi-56">电子邮件版本</span></th><th class="head"><span class="yiyi-st" id="yiyi-57">分布式</span></th><th class="head"><span class="yiyi-st" id="yiyi-58">兼容</span></th></tr></thead><tbody valign="top"><tr class="row-even"><td><span class="yiyi-st" id="yiyi-59"><code class="xref py py-const docutils literal"><span class="pre">1.x</span></code></span></td><td><span class="yiyi-st" id="yiyi-60">Python 2.2.0到Python 2.2.1</span></td><td><span class="yiyi-st" id="yiyi-61"><em>不再支持</em></span></td></tr><tr class="row-odd"><td><span class="yiyi-st" id="yiyi-62"><code class="xref py py-const docutils literal"><span class="pre">2.5</span></code></span></td><td><span class="yiyi-st" id="yiyi-63">Python 2.2.2+和Python 2.3</span></td><td><span class="yiyi-st" id="yiyi-64">Python 2.1到2.5</span></td></tr><tr class="row-even"><td><span class="yiyi-st" id="yiyi-65"><code class="xref py py-const docutils literal"><span class="pre">3.0</span></code></span></td><td><span class="yiyi-st" id="yiyi-66">Python 2.4和Python 2.5</span></td><td><span class="yiyi-st" id="yiyi-67">Python 2.3到2.6</span></td></tr><tr class="row-odd"><td><span class="yiyi-st" id="yiyi-68"><code class="xref py py-const docutils literal"><span class="pre">4.0</span></code></span></td><td><span class="yiyi-st" id="yiyi-69">Python 2.5到Python 2.7</span></td><td><span class="yiyi-st" id="yiyi-70">Python 2.3到2.7</span></td></tr><tr class="row-even"><td><span class="yiyi-st" id="yiyi-71"><code class="xref py py-const docutils literal"><span class="pre">5.0</span></code></span></td><td><span class="yiyi-st" id="yiyi-72">Python 3.0和Python 3.1</span></td><td><span class="yiyi-st" id="yiyi-73">Python 3.0到3.2</span></td></tr><tr class="row-odd"><td><span class="yiyi-st" id="yiyi-74"><code class="xref py py-const docutils literal"><span class="pre">5.1</span></code></span></td><td><span class="yiyi-st" id="yiyi-75">Python 3.2</span></td><td><span class="yiyi-st" id="yiyi-76">Python 3.2</span></td></tr></tbody></table><p><span class="yiyi-st" id="yiyi-77">5.1版之后(Python 3.2),电子邮件包不再具有与Python版本分开的版本。</span><span class="yiyi-st" id="yiyi-78">(有关更改的详细信息,请参阅各个Python版本的<a class="reference internal" href="../whatsnew/index.html#whatsnew-index"><span>What’s New in Python</span></a>文档。)</span></p><p><span class="yiyi-st" id="yiyi-79">以下是<a class="reference internal" href="#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages, including MIME documents."><code class="xref py py-mod docutils literal"><span class="pre">email</span></code></a>版本5.1和版本5.0之间的主要区别:</span></p><ul class="simple"><li><span class="yiyi-st" id="yiyi-80">可以再次解析包含非ASCII字节的消息,并且如果包含非ASCII字节的数据未被修改,则再现这样的消息。</span></li><li><span class="yiyi-st" id="yiyi-81">新功能<a class="reference internal" href="email.parser.html#email.message_from_bytes" title="email.message_from_bytes"><code class="xref py py-func docutils literal"><span class="pre">message_from_bytes()</span></code></a>和<a class="reference internal" href="email.parser.html#email.message_from_binary_file" title="email.message_from_binary_file"><code class="xref py py-func docutils literal"><span class="pre">message_from_binary_file()</span></code></a>和新类<a class="reference internal" href="email.parser.html#email.parser.BytesFeedParser" title="email.parser.BytesFeedParser"><code class="xref py py-class docutils literal"><span class="pre">BytesFeedParser</span></code></a>和<a class="reference internal" href="email.parser.html#email.parser.BytesParser" title="email.parser.BytesParser"><code class="xref py py-class docutils literal"><span class="pre">BytesParser</span></code></a>允许二进制消息数据解析为模型对象。</span></li><li><span class="yiyi-st" id="yiyi-82">给定模型输入的字节,<a class="reference internal" href="email.message.html#email.message.Message.get_payload" title="email.message.Message.get_payload"><code class="xref py py-meth docutils literal"><span class="pre">get_payload()</span></code></a>将默认使用<code class="docutils literal"><span class="pre">8bit</span></code>来解码具有<em class="mailheader">内容传输编码</em>的消息体在MIME头中指定的字符集,并返回结果字符串。</span></li><li><span class="yiyi-st" id="yiyi-83">给定模型的输入字节,<a class="reference internal" href="email.generator.html#email.generator.Generator" title="email.generator.Generator"><code class="xref py py-class docutils literal"><span class="pre">Generator</span></code></a>将转换具有8位的<em class="mailheader">内容传输编码</em>的消息体,而是具有7位内容传输编码。</span></li><li><span class="yiyi-st" id="yiyi-84">新类<a class="reference internal" href="email.generator.html#email.generator.BytesGenerator" title="email.generator.BytesGenerator"><code class="xref py py-class docutils literal"><span class="pre">BytesGenerator</span></code></a>生成字节作为输出,保留用于构建模型的输入中存在的任何未更改的非ASCII数据,包括具有<em class="mailheader">内容传输编码 t3 > 8bit。</em></span></li></ul><p><span class="yiyi-st" id="yiyi-85">以下是<a class="reference internal" href="#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages, including MIME documents."><code class="xref py py-mod docutils literal"><span class="pre">email</span></code></a>版本5.0和版本4之间的主要区别:</span></p><ul class="simple"><li><span class="yiyi-st" id="yiyi-86">所有操作都在Unicode字符串上。</span><span class="yiyi-st" id="yiyi-87">文本输入必须是字符串,文本输出是字符串。</span><span class="yiyi-st" id="yiyi-88">输出限于ASCII字符集,因此可以编码为ASCII用于传输。</span><span class="yiyi-st" id="yiyi-89">输入也限于ASCII;这是一个公认的电子邮件5.0的限制,意味着它只能用于解析7bit干净的电子邮件。</span></li></ul><p><span class="yiyi-st" id="yiyi-90">以下是<a class="reference internal" href="#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages, including MIME documents."><code class="xref py py-mod docutils literal"><span class="pre">email</span></code></a>版本4和版本3之间的主要区别:</span></p><ul><li><p class="first"><span class="yiyi-st" id="yiyi-91">所有模块已根据<span class="target" id="index-7"></span> <a class="pep reference external" href="https://www.python.org/dev/peps/pep-0008"><strong>PEP 8</strong></a>标准重命名。</span><span class="yiyi-st" id="yiyi-92">例如,版本3模块<code class="xref py py-mod docutils literal"><span class="pre">email.Message</span></code>在版本4中已重命名为<a class="reference internal" href="email.message.html#module-email.message" title="email.message: The base class representing email messages."><code class="xref py py-mod docutils literal"><span class="pre">email.message</span></code></a>。</span></p></li><li><p class="first"><span class="yiyi-st" id="yiyi-93">添加了新的子包<a class="reference internal" href="email.mime.html#module-email.mime" title="email.mime: Build MIME messages."><code class="xref py py-mod docutils literal"><span class="pre">email.mime</span></code></a>,并且所有版本3 <code class="xref py py-mod docutils literal"><span class="pre">email.MIME*</span></code>模块已重命名并位于<a class="reference internal" href="email.mime.html#module-email.mime" title="email.mime: Build MIME messages."><code class="xref py py-mod docutils literal"><span class="pre">email.mime</span></code></a>子包中。</span><span class="yiyi-st" id="yiyi-94">例如,版本3模块<code class="xref py py-mod docutils literal"><span class="pre">email.MIMEText</span></code>已重命名为<code class="xref py py-mod docutils literal"><span class="pre">email.mime.text</span></code>。</span></p><p><span class="yiyi-st" id="yiyi-95"><em>请注意,版本3名称将继续工作,直到Python 2.6</em>。</span></p></li><li><p class="first"><span class="yiyi-st" id="yiyi-96">添加了<code class="xref py py-mod docutils literal"><span class="pre">email.mime.application</span></code>模块,其中包含<a class="reference internal" href="email.mime.html#email.mime.application.MIMEApplication" title="email.mime.application.MIMEApplication"><code class="xref py py-class docutils literal"><span class="pre">MIMEApplication</span></code></a>类。</span></p></li><li><p class="first"><span class="yiyi-st" id="yiyi-97">已在版本3中弃用的方法已删除。</span><span class="yiyi-st" id="yiyi-98">这些包括<code class="xref py py-meth docutils literal"><span class="pre">Generator.__call__()</span></code>,<code class="xref py py-meth docutils literal"><span class="pre">Message.get_type()</span></code>,<code class="xref py py-meth docutils literal"><span class="pre">Message.get_main_type()</span></code>,<code class="xref py py-meth docutils literal"><span class="pre">Message.get_subtype()</span></code>。</span></p></li><li><p class="first"><span class="yiyi-st" id="yiyi-99">为<span class="target" id="index-8"></span> <a class="rfc reference external" href="https://tools.ietf.org/html/rfc2231.html"><strong>RFC 2231</strong></a>支持添加了修正,可以更改<a class="reference internal" href="email.message.html#email.message.Message.get_param" title="email.message.Message.get_param"><code class="xref py py-func docutils literal"><span class="pre">Message.get_param</span></code></a>和朋友的一些返回类型。</span><span class="yiyi-st" id="yiyi-100">在某些情况下,用于返回3元组的值现在返回简单字符串(具体来说,如果所有扩展参数段都未编码,则不需要指定语言和字符集,因此返回类型现在是一个简单的字符串)。</span><span class="yiyi-st" id="yiyi-101">另外,%编码用于对编码和非编码段进行;现在仅对编码的段进行这种解码。</span></p></li></ul><p><span class="yiyi-st" id="yiyi-102">以下是<a class="reference internal" href="#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages, including MIME documents."><code class="xref py py-mod docutils literal"><span class="pre">email</span></code></a>版本3和版本2之间的主要区别:</span></p><ul class="simple"><li><span class="yiyi-st" id="yiyi-103">引入了<a class="reference internal" href="email.parser.html#email.parser.FeedParser" title="email.parser.FeedParser"><code class="xref py py-class docutils literal"><span class="pre">FeedParser</span></code></a>类,并且<a class="reference internal" href="email.parser.html#email.parser.FeedParser" title="email.parser.FeedParser"><code class="xref py py-class docutils literal"><span class="pre">FeedParser</span></code></a>中实现了<a class="reference internal" href="email.parser.html#email.parser.Parser" title="email.parser.Parser"><code class="xref py py-class docutils literal"><span class="pre">Parser</span></code></a>类。</span><span class="yiyi-st" id="yiyi-104">因此,所有解析都是非严格的,解析将尽最大努力不要引发异常。</span><span class="yiyi-st" id="yiyi-105">解析邮件时发现的问题存储在邮件的<em>defect</em>属性中。</span></li><li><span class="yiyi-st" id="yiyi-106">删除了在版本2中生成<a class="reference internal" href="exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal"><span class="pre">DeprecationWarning</span></code></a>的API的所有方面。</span><span class="yiyi-st" id="yiyi-107">These include the <em>_encoder</em> argument to the <a class="reference internal" href="email.mime.html#email.mime.text.MIMEText" title="email.mime.text.MIMEText"><code class="xref py py-class docutils literal"><span class="pre">MIMEText</span></code></a> constructor, the <code class="xref py py-meth docutils literal"><span class="pre">Message.add_payload()</span></code> method, the <code class="xref py py-func docutils literal"><span class="pre">Utils.dump_address_pair()</span></code> function, and the functions <code class="xref py py-func docutils literal"><span class="pre">Utils.decode()</span></code> and <code class="xref py py-func docutils literal"><span class="pre">Utils.encode()</span></code>.</span></li><li><span class="yiyi-st" id="yiyi-108">New <a class="reference internal" href="exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal"><span class="pre">DeprecationWarning</span></code></a>s have been added to: <code class="xref py py-meth docutils literal"><span class="pre">Generator.__call__()</span></code>, <code class="xref py py-meth docutils literal"><span class="pre">Message.get_type()</span></code>, <code class="xref py py-meth docutils literal"><span class="pre">Message.get_main_type()</span></code>, <code class="xref py py-meth docutils literal"><span class="pre">Message.get_subtype()</span></code>, and the <em>strict</em> argument to the <a class="reference internal" href="email.parser.html#email.parser.Parser" title="email.parser.Parser"><code class="xref py py-class docutils literal"><span class="pre">Parser</span></code></a> class. </span><span class="yiyi-st" id="yiyi-109">这些都将在未来的版本中删除。</span></li><li><span class="yiyi-st" id="yiyi-110">支持早于2.3的Pythons已删除。</span></li></ul><p><span class="yiyi-st" id="yiyi-111">以下是<a class="reference internal" href="#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages, including MIME documents."><code class="xref py py-mod docutils literal"><span class="pre">email</span></code></a>版本2和版本1之间的差异:</span></p><ul><li><p class="first"><span class="yiyi-st" id="yiyi-112">已添加<code class="xref py py-mod docutils literal"><span class="pre">email.Header</span></code>和<code class="xref py py-mod docutils literal"><span class="pre">email.Charset</span></code>模块。</span></p></li><li><p class="first"><span class="yiyi-st" id="yiyi-113"><a class="reference internal" href="email.message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal"><span class="pre">Message</span></code></a>实例的pickle格式已更改。</span><span class="yiyi-st" id="yiyi-114">由于这是从来没有(仍然没有)正式定义,这不被认为是一个向后的不兼容性。</span><span class="yiyi-st" id="yiyi-115">但是,如果您的应用程序选择并取消选择<a class="reference internal" href="email.message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal"><span class="pre">Message</span></code></a>实例,请注意在<a class="reference internal" href="#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages, including MIME documents."><code class="xref py py-mod docutils literal"><span class="pre">email</span></code></a>版本2中,<a class="reference internal" href="email.message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal"><span class="pre">Message</span></code></a>实例现在具有专用变量<em>_charset 和<em>_default_type</em>。</em></span></p></li><li><p class="first"><span class="yiyi-st" id="yiyi-116"><a class="reference internal" href="email.message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal"><span class="pre">Message</span></code></a>类中的几个方法已被弃用,或者它们的签名已更改。</span><span class="yiyi-st" id="yiyi-117">此外,还增加了许多新的方法。</span><span class="yiyi-st" id="yiyi-118">有关详细信息,请参阅<a class="reference internal" href="email.message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal"><span class="pre">Message</span></code></a>类的文档。</span><span class="yiyi-st" id="yiyi-119">更改应该完全向后兼容。</span></p></li><li><p class="first"><span class="yiyi-st" id="yiyi-120">面对<em class="mimetype">message / rfc822</em>内容类型,对象结构已更改。</span><span class="yiyi-st" id="yiyi-121">在<a class="reference internal" href="#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages, including MIME documents."><code class="xref py py-mod docutils literal"><span class="pre">email</span></code></a>版本1中,这种类型将由标量有效载荷表示,即</span><span class="yiyi-st" id="yiyi-122">容器消息的<a class="reference internal" href="email.message.html#email.message.Message.is_multipart" title="email.message.Message.is_multipart"><code class="xref py py-meth docutils literal"><span class="pre">is_multipart()</span></code></a>返回false,<a class="reference internal" href="email.message.html#email.message.Message.get_payload" title="email.message.Message.get_payload"><code class="xref py py-meth docutils literal"><span class="pre">get_payload()</span></code></a>不是列表对象,而是单个<a class="reference internal" href="email.message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal"><span class="pre">Message</span></code></a></span></p><p><span class="yiyi-st" id="yiyi-123">此结构与程序包的其余部分不一致,因此更改了<em class="mimetype">message / rfc822</em>内容类型的对象表示。</span><span class="yiyi-st" id="yiyi-124">In <a class="reference internal" href="#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages, including MIME documents."><code class="xref py py-mod docutils literal"><span class="pre">email</span></code></a> version 2, the container <em>does</em> return <code class="docutils literal"><span class="pre">True</span></code> from <a class="reference internal" href="email.message.html#email.message.Message.is_multipart" title="email.message.Message.is_multipart"><code class="xref py py-meth docutils literal"><span class="pre">is_multipart()</span></code></a>, and <a class="reference internal" href="email.message.html#email.message.Message.get_payload" title="email.message.Message.get_payload"><code class="xref py py-meth docutils literal"><span class="pre">get_payload()</span></code></a> returns a list containing a single <a class="reference internal" href="email.message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal"><span class="pre">Message</span></code></a> item.</span></p><p><span class="yiyi-st" id="yiyi-125">注意,这是一个不能完全保持向后兼容性的地方。</span><span class="yiyi-st" id="yiyi-126">但是,如果您已经测试了<a class="reference internal" href="email.message.html#email.message.Message.get_payload" title="email.message.Message.get_payload"><code class="xref py py-meth docutils literal"><span class="pre">get_payload()</span></code></a>的返回类型,则应该没问题。</span><span class="yiyi-st" id="yiyi-127">您只需要确保您的代码不会对内容类型为<em class="mimetype">message / rfc822的容器执行<a class="reference internal" href="email.message.html#email.message.Message.set_payload" title="email.message.Message.set_payload"><code class="xref py py-meth docutils literal"><span class="pre">set_payload()</span></code></a>和<a class="reference internal" href="email.message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal"><span class="pre">Message</span></code></a> t6>。</em></span></p></li><li><p class="first"><span class="yiyi-st" id="yiyi-128">添加了<a class="reference internal" href="email.parser.html#email.parser.Parser" title="email.parser.Parser"><code class="xref py py-class docutils literal"><span class="pre">Parser</span></code></a>构造函数的<em>strict</em>参数,并且它的<a class="reference internal" href="email.parser.html#email.parser.Parser.parse" title="email.parser.Parser.parse"><code class="xref py py-meth docutils literal"><span class="pre">parse()</span></code></a>和<a class="reference internal" href="email.parser.html#email.parser.Parser.parsestr" title="email.parser.Parser.parsestr"><code class="xref py py-meth docutils literal"><span class="pre">parsestr()</span></code></a>方法增长了<em> headersonly</em>参数。</span><span class="yiyi-st" id="yiyi-129"><em>strict</em>标记也已添加到函数<a class="reference internal" href="email.parser.html#email.message_from_file" title="email.message_from_file"><code class="xref py py-func docutils literal"><span class="pre">email.message_from_file()</span></code></a>和<a class="reference internal" href="email.parser.html#email.message_from_string" title="email.message_from_string"><code class="xref py py-func docutils literal"><span class="pre">email.message_from_string()</span></code></a>中。</span></p></li><li><p class="first"><span class="yiyi-st" id="yiyi-130"><code class="xref py py-meth docutils literal"><span class="pre">Generator.__call__()</span></code>已弃用;请使用<a class="reference internal" href="email.generator.html#email.generator.Generator.flatten" title="email.generator.Generator.flatten"><code class="xref py py-meth docutils literal"><span class="pre">Generator.flatten</span></code></a>。</span><span class="yiyi-st" id="yiyi-131"><a class="reference internal" href="email.generator.html#email.generator.Generator" title="email.generator.Generator"><code class="xref py py-class docutils literal"><span class="pre">Generator</span></code></a>类也生长了<a class="reference internal" href="email.generator.html#email.generator.Generator.clone" title="email.generator.Generator.clone"><code class="xref py py-meth docutils literal"><span class="pre">clone()</span></code></a>方法。</span></p></li><li><p class="first"><span class="yiyi-st" id="yiyi-132">添加了<a class="reference internal" href="email.generator.html#module-email.generator" title="email.generator: Generate flat text email messages from a message structure."><code class="xref py py-mod docutils literal"><span class="pre">email.generator</span></code></a>模块中的<a class="reference internal" href="email.generator.html#email.generator.DecodedGenerator" title="email.generator.DecodedGenerator"><code class="xref py py-class docutils literal"><span class="pre">DecodedGenerator</span></code></a>类。</span></p></li><li><p class="first"><span class="yiyi-st" id="yiyi-133">已添加中间基类<a class="reference internal" href="email.mime.html#email.mime.nonmultipart.MIMENonMultipart" title="email.mime.nonmultipart.MIMENonMultipart"><code class="xref py py-class docutils literal"><span class="pre">MIMENonMultipart</span></code></a>和<a class="reference internal" href="email.mime.html#email.mime.multipart.MIMEMultipart" title="email.mime.multipart.MIMEMultipart"><code class="xref py py-class docutils literal"><span class="pre">MIMEMultipart</span></code></a>,并插入到大多数其他MIME相关派生类的类层次结构中。</span></p></li><li><p class="first"><span class="yiyi-st" id="yiyi-134"><a class="reference internal" href="email.mime.html#email.mime.text.MIMEText" title="email.mime.text.MIMEText"><code class="xref py py-class docutils literal"><span class="pre">MIMEText</span></code></a>构造函数的<em>_encoder</em>参数已被弃用。</span><span class="yiyi-st" id="yiyi-135">现在,基于<em>_charset</em>参数隐式地进行编码。</span></p></li><li><p class="first"><span class="yiyi-st" id="yiyi-136"><code class="xref py py-mod docutils literal"><span class="pre">email.Utils</span></code>模块中的以下函数已弃用:<code class="xref py py-func docutils literal"><span class="pre">dump_address_pairs()</span></code>,<code class="xref py py-func docutils literal"><span class="pre">decode()</span></code>和<code class="xref py py-func docutils literal"><span class="pre">encode()</span></code></span><span class="yiyi-st" id="yiyi-137">以下函数已添加到模块:<code class="xref py py-func docutils literal"><span class="pre">make_msgid()</span></code>,<code class="xref py py-func docutils literal"><span class="pre">decode_rfc2231()</span></code>,<code class="xref py py-func docutils literal"><span class="pre">encode_rfc2231()</span></code>和<code class="xref py py-func docutils literal"><span class="pre">decode_params()</span></code>。</span></p></li><li><p class="first"><span class="yiyi-st" id="yiyi-138">已添加非公开函数<code class="xref py py-func docutils literal"><span class="pre">email.Iterators._structure()</span></code>。</span></p></li></ul></div><div class="section" id="differences-from-mimelib"><h2><span class="yiyi-st" id="yiyi-139">19.1.16. </span><span class="yiyi-st" id="yiyi-140">与<code class="xref py py-mod docutils literal"><span class="pre">mimelib</span></code> 的区别</span></h2><p><span class="yiyi-st" id="yiyi-141"><a class="reference internal" href="#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages, including MIME documents."><code class="xref py py-mod docutils literal"><span class="pre">email</span></code></a>包最初原型化为一个名为<a class="reference external" href="http://mimelib.sourceforge.net/">mimelib</a>的独立库。</span><span class="yiyi-st" id="yiyi-142">已进行更改,以使方法名称更加一致,并且已添加或删除一些方法或模块。</span><span class="yiyi-st" id="yiyi-143">一些方法的语义也改变了。</span><span class="yiyi-st" id="yiyi-144">在大多数情况下,<code class="xref py py-mod docutils literal"><span class="pre">mimelib</span></code>中提供的任何功能在<a class="reference internal" href="#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages, including MIME documents."><code class="xref py py-mod docutils literal"><span class="pre">email</span></code></a>包中仍然可用,但通常采用不同的方式。</span><span class="yiyi-st" id="yiyi-145"><code class="xref py py-mod docutils literal"><span class="pre">mimelib</span></code>包与<a class="reference internal" href="#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages, including MIME documents."><code class="xref py py-mod docutils literal"><span class="pre">email</span></code></a>包之间的向后兼容性不是优先级。</span></p><p><span class="yiyi-st" id="yiyi-146">以下简要说明<code class="xref py py-mod docutils literal"><span class="pre">mimelib</span></code>和<a class="reference internal" href="#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages, including MIME documents."><code class="xref py py-mod docutils literal"><span class="pre">email</span></code></a>包之间的区别,以及如何移植应用程序的提示。</span></p><p><span class="yiyi-st" id="yiyi-147">当然,两个包之间最明显的区别是包名称已更改为<a class="reference internal" href="#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages, including MIME documents."><code class="xref py py-mod docutils literal"><span class="pre">email</span></code></a>。</span><span class="yiyi-st" id="yiyi-148">此外,顶级包具有以下区别:</span></p><ul class="simple"><li><span class="yiyi-st" id="yiyi-149"><code class="xref py py-func docutils literal"><span class="pre">messageFromString()</span></code>已重命名为<a class="reference internal" href="email.parser.html#email.message_from_string" title="email.message_from_string"><code class="xref py py-func docutils literal"><span class="pre">message_from_string()</span></code></a>。</span></li><li><span class="yiyi-st" id="yiyi-150"><code class="xref py py-func docutils literal"><span class="pre">messageFromFile()</span></code>已重命名为<a class="reference internal" href="email.parser.html#email.message_from_file" title="email.message_from_file"><code class="xref py py-func docutils literal"><span class="pre">message_from_file()</span></code></a>。</span></li></ul><p><span class="yiyi-st" id="yiyi-151"><a class="reference internal" href="email.message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal"><span class="pre">Message</span></code></a>类有以下区别:</span></p><ul class="simple"><li><span class="yiyi-st" id="yiyi-152">方法<code class="xref py py-meth docutils literal"><span class="pre">asString()</span></code>已重命名为<a class="reference internal" href="email.message.html#email.message.Message.as_string" title="email.message.Message.as_string"><code class="xref py py-meth docutils literal"><span class="pre">as_string()</span></code></a>。</span></li><li><span class="yiyi-st" id="yiyi-153">方法<code class="xref py py-meth docutils literal"><span class="pre">ismultipart()</span></code>已重命名为<a class="reference internal" href="email.message.html#email.message.Message.is_multipart" title="email.message.Message.is_multipart"><code class="xref py py-meth docutils literal"><span class="pre">is_multipart()</span></code></a>。</span></li><li><span class="yiyi-st" id="yiyi-154"><a class="reference internal" href="email.message.html#email.message.Message.get_payload" title="email.message.Message.get_payload"><code class="xref py py-meth docutils literal"><span class="pre">get_payload()</span></code></a>方法已生成<em>解码</em>可选参数。</span></li><li><span class="yiyi-st" id="yiyi-155">方法<code class="xref py py-meth docutils literal"><span class="pre">getall()</span></code>已重命名为<a class="reference internal" href="email.message.html#email.message.Message.get_all" title="email.message.Message.get_all"><code class="xref py py-meth docutils literal"><span class="pre">get_all()</span></code></a>。</span></li><li><span class="yiyi-st" id="yiyi-156">方法<code class="xref py py-meth docutils literal"><span class="pre">addheader()</span></code>已重命名为<a class="reference internal" href="email.message.html#email.message.Message.add_header" title="email.message.Message.add_header"><code class="xref py py-meth docutils literal"><span class="pre">add_header()</span></code></a>。</span></li><li><span class="yiyi-st" id="yiyi-157">方法<code class="xref py py-meth docutils literal"><span class="pre">gettype()</span></code>已重命名为<code class="xref py py-meth docutils literal"><span class="pre">get_type()</span></code>。</span></li><li><span class="yiyi-st" id="yiyi-158">方法<code class="xref py py-meth docutils literal"><span class="pre">getmaintype()</span></code>已重命名为<code class="xref py py-meth docutils literal"><span class="pre">get_main_type()</span></code>。</span></li><li><span class="yiyi-st" id="yiyi-159">方法<code class="xref py py-meth docutils literal"><span class="pre">getsubtype()</span></code>已重命名为<code class="xref py py-meth docutils literal"><span class="pre">get_subtype()</span></code>。</span></li><li><span class="yiyi-st" id="yiyi-160">方法<code class="xref py py-meth docutils literal"><span class="pre">getparams()</span></code>已重命名为<a class="reference internal" href="email.message.html#email.message.Message.get_params" title="email.message.Message.get_params"><code class="xref py py-meth docutils literal"><span class="pre">get_params()</span></code></a>。</span><span class="yiyi-st" id="yiyi-161">此外,<code class="xref py py-meth docutils literal"><span class="pre">getparams()</span></code>返回字符串列表,<a class="reference internal" href="email.message.html#email.message.Message.get_params" title="email.message.Message.get_params"><code class="xref py py-meth docutils literal"><span class="pre">get_params()</span></code></a>返回一个2元组列表,实际上参数的键/ <code class="docutils literal"><span class="pre">'='</span></code>符号。</span></li><li><span class="yiyi-st" id="yiyi-162">方法<code class="xref py py-meth docutils literal"><span class="pre">getparam()</span></code>已重命名为<a class="reference internal" href="email.message.html#email.message.Message.get_param" title="email.message.Message.get_param"><code class="xref py py-meth docutils literal"><span class="pre">get_param()</span></code></a>。</span></li><li><span class="yiyi-st" id="yiyi-163">方法<code class="xref py py-meth docutils literal"><span class="pre">getcharsets()</span></code>已重命名为<a class="reference internal" href="email.message.html#email.message.Message.get_charsets" title="email.message.Message.get_charsets"><code class="xref py py-meth docutils literal"><span class="pre">get_charsets()</span></code></a>。</span></li><li><span class="yiyi-st" id="yiyi-164">方法<code class="xref py py-meth docutils literal"><span class="pre">getfilename()</span></code>已重命名为<a class="reference internal" href="email.message.html#email.message.Message.get_filename" title="email.message.Message.get_filename"><code class="xref py py-meth docutils literal"><span class="pre">get_filename()</span></code></a>。</span></li><li><span class="yiyi-st" id="yiyi-165">方法<code class="xref py py-meth docutils literal"><span class="pre">getboundary()</span></code>已重命名为<a class="reference internal" href="email.message.html#email.message.Message.get_boundary" title="email.message.Message.get_boundary"><code class="xref py py-meth docutils literal"><span class="pre">get_boundary()</span></code></a>。</span></li><li><span class="yiyi-st" id="yiyi-166">方法<code class="xref py py-meth docutils literal"><span class="pre">setboundary()</span></code>已重命名为<a class="reference internal" href="email.message.html#email.message.Message.set_boundary" title="email.message.Message.set_boundary"><code class="xref py py-meth docutils literal"><span class="pre">set_boundary()</span></code></a>。</span></li><li><span class="yiyi-st" id="yiyi-167">方法<code class="xref py py-meth docutils literal"><span class="pre">getdecodedpayload()</span></code>已删除。</span><span class="yiyi-st" id="yiyi-168">要获得类似的功能,请将值1传递给<a class="reference internal" href="email.message.html#email.message.Message.get_payload" title="email.message.Message.get_payload"><code class="xref py py-meth docutils literal"><span class="pre">get_payload()</span></code></a>方法的<em>decode</em>标志。</span></li><li><span class="yiyi-st" id="yiyi-169">方法<code class="xref py py-meth docutils literal"><span class="pre">getpayloadastext()</span></code>已删除。</span><span class="yiyi-st" id="yiyi-170">类似的功能由<a class="reference internal" href="email.generator.html#module-email.generator" title="email.generator: Generate flat text email messages from a message structure."><code class="xref py py-mod docutils literal"><span class="pre">email.generator</span></code></a>模块中的<a class="reference internal" href="email.generator.html#email.generator.DecodedGenerator" title="email.generator.DecodedGenerator"><code class="xref py py-class docutils literal"><span class="pre">DecodedGenerator</span></code></a>类支持。</span></li><li><span class="yiyi-st" id="yiyi-171">方法<code class="xref py py-meth docutils literal"><span class="pre">getbodyastext()</span></code>已删除。</span><span class="yiyi-st" id="yiyi-172">您可以通过在<a class="reference internal" href="email.iterators.html#module-email.iterators" title="email.iterators: Iterate over a message object tree."><code class="xref py py-mod docutils literal"><span class="pre">email.iterators</span></code></a>模块中创建<a class="reference internal" href="email.iterators.html#email.iterators.typed_subpart_iterator" title="email.iterators.typed_subpart_iterator"><code class="xref py py-func docutils literal"><span class="pre">typed_subpart_iterator()</span></code></a>的迭代器来获得类似的功能。</span></li></ul><p><span class="yiyi-st" id="yiyi-173"><a class="reference internal" href="email.parser.html#email.parser.Parser" title="email.parser.Parser"><code class="xref py py-class docutils literal"><span class="pre">Parser</span></code></a>类在其公共接口中没有差异。</span><span class="yiyi-st" id="yiyi-174">它有一些额外的智能识别<em class="mimetype">消息/交付状态</em>类型消息,它表示为<a class="reference internal" href="email.message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal"><span class="pre">Message</span></code></a>实例包含单独的<a class="reference internal" href="email.message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal"><span class="pre">Message</span></code></a>子部分传送状态通知<a class="footnote-reference" href="#id2" id="id1">[1]</a>中的标题块。</span></p><p><span class="yiyi-st" id="yiyi-175"><a class="reference internal" href="email.generator.html#email.generator.Generator" title="email.generator.Generator"><code class="xref py py-class docutils literal"><span class="pre">Generator</span></code></a>类在其公共接口上没有差异。</span><span class="yiyi-st" id="yiyi-176">在<a class="reference internal" href="email.generator.html#module-email.generator" title="email.generator: Generate flat text email messages from a message structure."><code class="xref py py-mod docutils literal"><span class="pre">email.generator</span></code></a>模块中有一个新类,名为<a class="reference internal" href="email.generator.html#email.generator.DecodedGenerator" title="email.generator.DecodedGenerator"><code class="xref py py-class docutils literal"><span class="pre">DecodedGenerator</span></code></a>,它提供了以前在<code class="xref py py-meth docutils literal"><span class="pre">Message.getpayloadastext()</span></code></span></p><p><span class="yiyi-st" id="yiyi-177">以下模块和类已更改:</span></p><ul><li><p class="first"><span class="yiyi-st" id="yiyi-178"><a class="reference internal" href="email.mime.html#email.mime.base.MIMEBase" title="email.mime.base.MIMEBase"><code class="xref py py-class docutils literal"><span class="pre">MIMEBase</span></code></a>类构造函数参数<em>_major</em>和<em>_minor</em>分别更改为<em>_maintype</em>和<em>_subtype</em> 。</span></p></li><li><p class="first"><span class="yiyi-st" id="yiyi-179"><code class="docutils literal"><span class="pre">Image</span></code>类/模块已重命名为<code class="docutils literal"><span class="pre">MIMEImage</span></code>。</span><span class="yiyi-st" id="yiyi-180"><em>_minor</em>参数已重命名为<em>_subtype</em>。</span></p></li><li><p class="first"><span class="yiyi-st" id="yiyi-181"><code class="docutils literal"><span class="pre">Text</span></code>类/模块已重命名为<code class="docutils literal"><span class="pre">MIMEText</span></code>。</span><span class="yiyi-st" id="yiyi-182"><em>_minor</em>参数已重命名为<em>_subtype</em>。</span></p></li><li><p class="first"><span class="yiyi-st" id="yiyi-183"><code class="docutils literal"><span class="pre">MessageRFC822</span></code>类/模块已重命名为<code class="docutils literal"><span class="pre">MIMEMessage</span></code>。</span><span class="yiyi-st" id="yiyi-184">请注意,<code class="xref py py-mod docutils literal"><span class="pre">mimelib</span></code>的早期版本称为此类/模块<code class="docutils literal"><span class="pre">RFC822</span></code>,但是与某些不区分大小写的Python标准库模块<code class="xref py py-mod docutils literal"><span class="pre">rfc822</span></code>文件系统。</span></p><p><span class="yiyi-st" id="yiyi-185">此外,<a class="reference internal" href="email.mime.html#email.mime.message.MIMEMessage" title="email.mime.message.MIMEMessage"><code class="xref py py-class docutils literal"><span class="pre">MIMEMessage</span></code></a>类现在表示主类型为<em class="mimetype">消息</em>的任何类型的MIME消息。</span><span class="yiyi-st" id="yiyi-186">它采用可选参数<em>_subtype</em>,用于设置MIME子类型。</span><span class="yiyi-st" id="yiyi-187"><em>_subtype</em>默认为<em class="mimetype">rfc822</em>。</span></p></li></ul><p><span class="yiyi-st" id="yiyi-188"><code class="xref py py-mod docutils literal"><span class="pre">mimelib</span></code>在其<code class="xref py py-mod docutils literal"><span class="pre">address</span></code>和<code class="xref py py-mod docutils literal"><span class="pre">date</span></code>模块中提供了一些实用程序函数。</span><span class="yiyi-st" id="yiyi-189">所有这些功能都已移至<a class="reference internal" href="email.util.html#module-email.utils" title="email.utils: Miscellaneous email package utilities."><code class="xref py py-mod docutils literal"><span class="pre">email.utils</span></code></a>模块。</span></p><p><span class="yiyi-st" id="yiyi-190"><code class="docutils literal"><span class="pre">MsgReader</span></code>类/模块已删除。</span><span class="yiyi-st" id="yiyi-191">其功能在<a class="reference internal" href="email.iterators.html#module-email.iterators" title="email.iterators: Iterate over a message object tree."><code class="xref py py-mod docutils literal"><span class="pre">email.iterators</span></code></a>模块中的<a class="reference internal" href="email.iterators.html#email.iterators.body_line_iterator" title="email.iterators.body_line_iterator"><code class="xref py py-func docutils literal"><span class="pre">body_line_iterator()</span></code></a>函数中得到最密切支持。</span></p><p class="rubric"><span class="yiyi-st" id="yiyi-192">脚注</span></p><table class="docutils footnote" frame="void" id="id2" rules="none"><tbody valign="top"><tr><td class="label"><span class="yiyi-st" id="yiyi-193"><a class="fn-backref" href="#id1"> [1] T0></a></span></td><td><span class="yiyi-st" id="yiyi-194">传递状态通知(DSN)在<span class="target" id="index-9"></span> <a class="rfc reference external" href="https://tools.ietf.org/html/rfc1894.html"><strong>RFC 1894</strong></a>中定义。</span></td></tr></tbody></table></div></div></div> |