462 lines
36 KiB
HTML
462 lines
36 KiB
HTML
|
||
<!DOCTYPE html>
|
||
|
||
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
|
||
<head>
|
||
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||
|
||
<title>poplib --- POP3 协议客户端 — Python 3.8.20 文档</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
||
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
|
||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||
|
||
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
|
||
<script src="../_static/jquery.js"></script>
|
||
<script src="../_static/underscore.js"></script>
|
||
<script src="../_static/doctools.js"></script>
|
||
<script src="../_static/language_data.js"></script>
|
||
<script src="../_static/translations.js"></script>
|
||
|
||
<script src="../_static/sidebar.js"></script>
|
||
|
||
<link rel="search" type="application/opensearchdescription+xml"
|
||
title="在 Python 3.8.20 文档 中搜索"
|
||
href="../_static/opensearch.xml"/>
|
||
<link rel="author" title="关于这些文档" href="../about.html" />
|
||
<link rel="index" title="索引" href="../genindex.html" />
|
||
<link rel="search" title="搜索" href="../search.html" />
|
||
<link rel="copyright" title="版权所有" href="../copyright.html" />
|
||
<link rel="next" title="imaplib --- IMAP4 协议客户端" href="imaplib.html" />
|
||
<link rel="prev" title="ftplib --- FTP 协议客户端" href="ftplib.html" />
|
||
<link rel="canonical" href="https://docs.python.org/3/library/poplib.html" />
|
||
|
||
|
||
|
||
|
||
|
||
<style>
|
||
@media only screen {
|
||
table.full-width-table {
|
||
width: 100%;
|
||
}
|
||
}
|
||
</style>
|
||
<link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
|
||
<script type="text/javascript" src="../_static/copybutton.js"></script>
|
||
<script type="text/javascript" src="../_static/menu.js"></script>
|
||
|
||
</head>
|
||
<body>
|
||
<div class="mobile-nav">
|
||
<input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
|
||
aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
|
||
<label for="menuToggler" class="toggler__label">
|
||
<span></span>
|
||
</label>
|
||
<nav class="nav-content" role="navigation">
|
||
<a href="https://www.python.org/" class="nav-logo">
|
||
<img src="../_static/py.svg" alt="Logo"/>
|
||
</a>
|
||
<div class="version_switcher_placeholder"></div>
|
||
<form role="search" class="search" action="../search.html" method="get">
|
||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
|
||
<path fill-rule="nonzero"
|
||
d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z" fill="#444"></path>
|
||
</svg>
|
||
<input type="text" name="q" aria-label="快速搜索"/>
|
||
<input type="submit" value="转向"/>
|
||
</form>
|
||
</nav>
|
||
<div class="menu-wrapper">
|
||
<nav class="menu" role="navigation" aria-label="main navigation">
|
||
<div class="language_switcher_placeholder"></div>
|
||
<h3><a href="../contents.html">目录</a></h3>
|
||
<ul>
|
||
<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">poplib</span></code> --- POP3 协议客户端</a><ul>
|
||
<li><a class="reference internal" href="#pop3-objects">POP3 对象</a></li>
|
||
<li><a class="reference internal" href="#pop3-example">POP3 示例</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
<h4>上一个主题</h4>
|
||
<p class="topless"><a href="ftplib.html"
|
||
title="上一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ftplib</span></code> --- FTP 协议客户端</a></p>
|
||
<h4>下一个主题</h4>
|
||
<p class="topless"><a href="imaplib.html"
|
||
title="下一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">imaplib</span></code> --- IMAP4 协议客户端</a></p>
|
||
<div role="note" aria-label="source link">
|
||
<h3>本页</h3>
|
||
<ul class="this-page-menu">
|
||
<li><a href="../bugs.html">报告 Bug</a></li>
|
||
<li>
|
||
<a href="https://github.com/python/cpython/blob/3.8/Doc/library/poplib.rst"
|
||
rel="nofollow">显示源代码
|
||
</a>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</nav>
|
||
</div>
|
||
</div>
|
||
|
||
<div id="outdated-warning" style="padding: .5em; text-align: center; background-color: #FFBABA; color: #6A0E0E;">
|
||
这个文档所针对的是一个已不再受支持的 Python 旧版本。
|
||
你应当升级版本,并阅读
|
||
<a href="/3/library/poplib.html"> Python 当前稳定版本的文档</a>.
|
||
</div>
|
||
|
||
<div class="related" role="navigation" aria-label="related navigation">
|
||
<h3>导航</h3>
|
||
<ul>
|
||
<li class="right" style="margin-right: 10px">
|
||
<a href="../genindex.html" title="总目录"
|
||
accesskey="I">索引</a></li>
|
||
<li class="right" >
|
||
<a href="../py-modindex.html" title="Python 模块索引"
|
||
>模块</a> |</li>
|
||
<li class="right" >
|
||
<a href="imaplib.html" title="imaplib --- IMAP4 协议客户端"
|
||
accesskey="N">下一页</a> |</li>
|
||
<li class="right" >
|
||
<a href="ftplib.html" title="ftplib --- FTP 协议客户端"
|
||
accesskey="P">上一页</a> |</li>
|
||
|
||
<li><img src="../_static/py.svg" alt="python logo" style="vertical-align: middle; margin-top: -1px"/></li>
|
||
<li><a href="https://www.python.org/">Python</a> »</li>
|
||
<li class="switchers">
|
||
<div class="language_switcher_placeholder"></div>
|
||
<div class="version_switcher_placeholder"></div>
|
||
</li>
|
||
<li>
|
||
|
||
</li>
|
||
<li id="cpython-language-and-version">
|
||
<a href="../index.html">3.8.20 Documentation</a> »
|
||
</li>
|
||
|
||
<li class="nav-item nav-item-1"><a href="index.html" >Python 标准库</a> »</li>
|
||
<li class="nav-item nav-item-2"><a href="internet.html" accesskey="U">互联网协议和支持</a> »</li>
|
||
<li class="right">
|
||
|
||
|
||
<div class="inline-search" role="search">
|
||
<form class="inline-search" action="../search.html" method="get">
|
||
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
|
||
<input type="submit" value="转向" />
|
||
<input type="hidden" name="check_keywords" value="yes" />
|
||
<input type="hidden" name="area" value="default" />
|
||
</form>
|
||
</div>
|
||
|
|
||
</li>
|
||
|
||
</ul>
|
||
</div>
|
||
|
||
<div class="document">
|
||
<div class="documentwrapper">
|
||
<div class="bodywrapper">
|
||
<div class="body" role="main">
|
||
|
||
<section id="module-poplib">
|
||
<span id="poplib-pop3-protocol-client"></span><h1><a class="reference internal" href="#module-poplib" title="poplib: POP3 protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">poplib</span></code></a> --- POP3 协议客户端<a class="headerlink" href="#module-poplib" title="永久链接至标题">¶</a></h1>
|
||
<p><strong>源代码:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.8/Lib/poplib.py">Lib/poplib.py</a></p>
|
||
<hr class="docutils" id="index-0" />
|
||
<p>本模块定义了一个 <a class="reference internal" href="#poplib.POP3" title="poplib.POP3"><code class="xref py py-class docutils literal notranslate"><span class="pre">POP3</span></code></a> 类,该类封装了到 POP3 服务器的连接过程,并实现了 <span class="target" id="index-13"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc1939.html"><strong>RFC 1939</strong></a> 中定义的协议。<a class="reference internal" href="#poplib.POP3" title="poplib.POP3"><code class="xref py py-class docutils literal notranslate"><span class="pre">POP3</span></code></a> 类同时支持 <span class="target" id="index-14"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc1939.html"><strong>RFC 1939</strong></a> 中最小的和可选的命令集。<a class="reference internal" href="#poplib.POP3" title="poplib.POP3"><code class="xref py py-class docutils literal notranslate"><span class="pre">POP3</span></code></a> 类还支持在 <span class="target" id="index-15"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2595.html"><strong>RFC 2595</strong></a> 中引入的 <code class="docutils literal notranslate"><span class="pre">STLS</span></code> 命令,用于在已建立的连接上启用加密通信。</p>
|
||
<p>本模块额外提供一个 <a class="reference internal" href="#poplib.POP3_SSL" title="poplib.POP3_SSL"><code class="xref py py-class docutils literal notranslate"><span class="pre">POP3_SSL</span></code></a> 类,在连接到 POP3 服务器时,该类为使用 SSL 作为底层协议层提供了支持。</p>
|
||
<p>注意,尽管 POP3 具有广泛的支持,但它已经过时。POP3 服务器的实现质量差异很大,而且大多很糟糕。如果邮件服务器支持 IMAP,则最好使用 <a class="reference internal" href="imaplib.html#imaplib.IMAP4" title="imaplib.IMAP4"><code class="xref py py-class docutils literal notranslate"><span class="pre">imaplib.IMAP4</span></code></a> 类,因为 IMAP 服务器一般实现得更好。</p>
|
||
<p><a class="reference internal" href="#module-poplib" title="poplib: POP3 protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">poplib</span></code></a> 模块提供了两个类:</p>
|
||
<dl class="class">
|
||
<dt id="poplib.POP3">
|
||
<em class="property">class </em><code class="sig-prename descclassname">poplib.</code><code class="sig-name descname">POP3</code><span class="sig-paren">(</span><em class="sig-param">host</em>, <em class="sig-param">port=POP3_PORT</em><span class="optional">[</span>, <em class="sig-param">timeout</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>本类实现实际的 POP3 协议。实例初始化时,连接就会建立。如果省略 <em>port</em>,则使用标准 POP3 端口(110)。可选参数 <em>timeout</em> 指定连接尝试的超时时间(以秒为单位,如果未指定超时,将使用全局默认超时设置)。</p>
|
||
<p class="audit-hook">引发一个 <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">审计事件</span></a> <code class="docutils literal notranslate"><span class="pre">poplib.connect</span></code> 并附带参数 <code class="docutils literal notranslate"><span class="pre">self</span></code>, <code class="docutils literal notranslate"><span class="pre">host</span></code>, <code class="docutils literal notranslate"><span class="pre">port</span></code>。</p>
|
||
<p class="audit-hook">引发一个 <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">审计事件</span></a> <code class="docutils literal notranslate"><span class="pre">poplib.putline</span></code>,附带参数 <code class="docutils literal notranslate"><span class="pre">self</span></code>, <code class="docutils literal notranslate"><span class="pre">line</span></code>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="class">
|
||
<dt id="poplib.POP3_SSL">
|
||
<em class="property">class </em><code class="sig-prename descclassname">poplib.</code><code class="sig-name descname">POP3_SSL</code><span class="sig-paren">(</span><em class="sig-param">host</em>, <em class="sig-param">port=POP3_SSL_PORT</em>, <em class="sig-param">keyfile=None</em>, <em class="sig-param">certfile=None</em>, <em class="sig-param">timeout=None</em>, <em class="sig-param">context=None</em><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3_SSL" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>一个 <a class="reference internal" href="#poplib.POP3" title="poplib.POP3"><code class="xref py py-class docutils literal notranslate"><span class="pre">POP3</span></code></a> 的子类,它使用经 SSL 加密的套接字连接到服务器。如果端口 <em>port</em> 未指定,则使用 995,它是标准的 POP3-over-SSL 端口。<em>timeout</em> 的作用与 <a class="reference internal" href="#poplib.POP3" title="poplib.POP3"><code class="xref py py-class docutils literal notranslate"><span class="pre">POP3</span></code></a> 构造函数中的相同。<em>context</em> 是一个可选的 <a class="reference internal" href="ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">ssl.SSLContext</span></code></a> 对象,该对象可以将 SSL 配置选项、证书和私钥打包放入一个单独的(可以长久存在的)结构中。请阅读 <a class="reference internal" href="ssl.html#ssl-security"><span class="std std-ref">安全考量</span></a> 以获取最佳实践。</p>
|
||
<p><em>keyfile</em> 和 <em>certfile</em> 是可以代替 <em>context</em> 的传统方案,它们可以分别指向 PEM 格式的私钥和证书链文件,用于进行 SSL 连接。</p>
|
||
<p class="audit-hook">引发一个 <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">审计事件</span></a> <code class="docutils literal notranslate"><span class="pre">poplib.connect</span></code> 并附带参数 <code class="docutils literal notranslate"><span class="pre">self</span></code>, <code class="docutils literal notranslate"><span class="pre">host</span></code>, <code class="docutils literal notranslate"><span class="pre">port</span></code>。</p>
|
||
<p class="audit-hook">引发一个 <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">审计事件</span></a> <code class="docutils literal notranslate"><span class="pre">poplib.putline</span></code>,附带参数 <code class="docutils literal notranslate"><span class="pre">self</span></code>, <code class="docutils literal notranslate"><span class="pre">line</span></code>。</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">在 3.2 版更改: </span>添加了 <em>context</em> 参数。</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">在 3.4 版更改: </span>本类现在支持使用 <a class="reference internal" href="ssl.html#ssl.SSLContext.check_hostname" title="ssl.SSLContext.check_hostname"><code class="xref py py-attr docutils literal notranslate"><span class="pre">ssl.SSLContext.check_hostname</span></code></a> 和 <em>服务器名称指示</em> (参阅 <a class="reference internal" href="ssl.html#ssl.HAS_SNI" title="ssl.HAS_SNI"><code class="xref py py-data docutils literal notranslate"><span class="pre">ssl.HAS_SNI</span></code></a>)进行主机名检查。</p>
|
||
</div>
|
||
<div class="deprecated">
|
||
<p><span class="versionmodified deprecated">3.6 版后已移除: </span><em>keyfile</em> 和 <em>certfile</em> 已弃用并转而推荐 <em>context</em>。 请改用 <a class="reference internal" href="ssl.html#ssl.SSLContext.load_cert_chain" title="ssl.SSLContext.load_cert_chain"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ssl.SSLContext.load_cert_chain()</span></code></a> 或让 <a class="reference internal" href="ssl.html#ssl.create_default_context" title="ssl.create_default_context"><code class="xref py py-func docutils literal notranslate"><span class="pre">ssl.create_default_context()</span></code></a> 为你选择系统所信任的 CA 证书。</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<p>定义了一个异常,它是作为 <a class="reference internal" href="#module-poplib" title="poplib: POP3 protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">poplib</span></code></a> 模块的属性定义的:</p>
|
||
<dl class="exception">
|
||
<dt id="poplib.error_proto">
|
||
<em class="property">exception </em><code class="sig-prename descclassname">poplib.</code><code class="sig-name descname">error_proto</code><a class="headerlink" href="#poplib.error_proto" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>此模块的所有错误都将引发本异常(来自 <a class="reference internal" href="socket.html#module-socket" title="socket: Low-level networking interface."><code class="xref py py-mod docutils literal notranslate"><span class="pre">socket</span></code></a> 模块的错误不会被捕获)。异常的原因将以字符串的形式传递给构造函数。</p>
|
||
</dd></dl>
|
||
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">参见</p>
|
||
<dl class="simple">
|
||
<dt><a class="reference internal" href="imaplib.html#module-imaplib" title="imaplib: IMAP4 protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">imaplib</span></code></a> 模块</dt><dd><p>标准的 Python IMAP 模块。</p>
|
||
</dd>
|
||
<dt><a class="reference external" href="http://www.catb.org/~esr/fetchmail/fetchmail-FAQ.html">有关 Fetchmail 的常见问题</a></dt><dd><p><strong class="program">fetchmail</strong> POP/IMAP 客户端的“常见问题”收集了 POP3 服务器之间的差异和 RFC 不兼容的信息,如果要编写基于 POP 协议的应用程序,这可能会很有用。</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
<section id="pop3-objects">
|
||
<span id="id1"></span><h2>POP3 对象<a class="headerlink" href="#pop3-objects" title="永久链接至标题">¶</a></h2>
|
||
<p>所有 POP3 命令均以同名的方法表示,小写,大多数方法返回的是服务器发送的响应文本。</p>
|
||
<p><a class="reference internal" href="#poplib.POP3" title="poplib.POP3"><code class="xref py py-class docutils literal notranslate"><span class="pre">POP3</span></code></a> 实例具有下列方法:</p>
|
||
<dl class="method">
|
||
<dt id="poplib.POP3.set_debuglevel">
|
||
<code class="sig-prename descclassname">POP3.</code><code class="sig-name descname">set_debuglevel</code><span class="sig-paren">(</span><em class="sig-param">level</em><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.set_debuglevel" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>设置实例的调试级别,它控制着调试信息的数量。默认值 <code class="docutils literal notranslate"><span class="pre">0</span></code> 不产生调试信息。值 <code class="docutils literal notranslate"><span class="pre">1</span></code> 产生中等数量的调试信息,通常每个请求产生一行。大于或等于 <code class="docutils literal notranslate"><span class="pre">2</span></code> 的值产生的调试信息最多,FTP 控制连接上发送和接收的每一行都将被记录下来。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="method">
|
||
<dt id="poplib.POP3.getwelcome">
|
||
<code class="sig-prename descclassname">POP3.</code><code class="sig-name descname">getwelcome</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.getwelcome" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>返回 POP3 服务器发送的问候语字符串。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="method">
|
||
<dt id="poplib.POP3.capa">
|
||
<code class="sig-prename descclassname">POP3.</code><code class="sig-name descname">capa</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.capa" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>查询服务器支持的功能,这些功能在 <span class="target" id="index-16"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2449.html"><strong>RFC 2449</strong></a> 中有说明。返回一个 <code class="docutils literal notranslate"><span class="pre">{'name':</span> <span class="pre">['param'...]}</span></code> 形式的字典。</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.4 新版功能.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="method">
|
||
<dt id="poplib.POP3.user">
|
||
<code class="sig-prename descclassname">POP3.</code><code class="sig-name descname">user</code><span class="sig-paren">(</span><em class="sig-param">username</em><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.user" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>发送 user 命令,返回的响应应该指示需要一个密码。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="method">
|
||
<dt id="poplib.POP3.pass_">
|
||
<code class="sig-prename descclassname">POP3.</code><code class="sig-name descname">pass_</code><span class="sig-paren">(</span><em class="sig-param">password</em><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.pass_" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>发送密码,响应包括邮件数和邮箱大小。注意:在调用 <code class="xref py py-meth docutils literal notranslate"><span class="pre">quit()</span></code> 前,服务器上的邮箱都是锁定的。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="method">
|
||
<dt id="poplib.POP3.apop">
|
||
<code class="sig-prename descclassname">POP3.</code><code class="sig-name descname">apop</code><span class="sig-paren">(</span><em class="sig-param">user</em>, <em class="sig-param">secret</em><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.apop" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>使用更安全的 APOP 身份验证登录到 POP3 服务器。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="method">
|
||
<dt id="poplib.POP3.rpop">
|
||
<code class="sig-prename descclassname">POP3.</code><code class="sig-name descname">rpop</code><span class="sig-paren">(</span><em class="sig-param">user</em><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.rpop" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>使用 RPOP 身份验证(类似于 Unix r-命令)登录到 POP3 服务器。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="method">
|
||
<dt id="poplib.POP3.stat">
|
||
<code class="sig-prename descclassname">POP3.</code><code class="sig-name descname">stat</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.stat" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>获取邮箱状态。结果为 2 个整数组成的元组:<code class="docutils literal notranslate"><span class="pre">(message</span> <span class="pre">count,</span> <span class="pre">mailbox</span> <span class="pre">size)</span></code>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="method">
|
||
<dt id="poplib.POP3.list">
|
||
<code class="sig-prename descclassname">POP3.</code><code class="sig-name descname">list</code><span class="sig-paren">(</span><span class="optional">[</span><em class="sig-param">which</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.list" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>请求消息列表,结果的形式为 <code class="docutils literal notranslate"><span class="pre">(response,</span> <span class="pre">['mesg_num</span> <span class="pre">octets',</span> <span class="pre">...],</span> <span class="pre">octets)</span></code>。如果设置了 <em>which</em>,它表示需要列出的消息。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="method">
|
||
<dt id="poplib.POP3.retr">
|
||
<code class="sig-prename descclassname">POP3.</code><code class="sig-name descname">retr</code><span class="sig-paren">(</span><em class="sig-param">which</em><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.retr" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>检索编号为 <em>which</em> 的整条消息,并设置其已读标志位。结果的形式为 <code class="docutils literal notranslate"><span class="pre">(response,</span> <span class="pre">['line',</span> <span class="pre">...],</span> <span class="pre">octets)</span></code>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="method">
|
||
<dt id="poplib.POP3.dele">
|
||
<code class="sig-prename descclassname">POP3.</code><code class="sig-name descname">dele</code><span class="sig-paren">(</span><em class="sig-param">which</em><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.dele" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>将编号为 <em>which</em> 的消息标记为待删除。在多数服务器上,删除操作直到 QUIT 才会实际执行(主要例外是 Eudora QPOP,它在断开连接时执行删除,故意违反了 RFC)。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="method">
|
||
<dt id="poplib.POP3.rset">
|
||
<code class="sig-prename descclassname">POP3.</code><code class="sig-name descname">rset</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.rset" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>移除邮箱中的所有待删除标记。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="method">
|
||
<dt id="poplib.POP3.noop">
|
||
<code class="sig-prename descclassname">POP3.</code><code class="sig-name descname">noop</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.noop" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>什么都不做。可以用于保持活动状态。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="method">
|
||
<dt id="poplib.POP3.quit">
|
||
<code class="sig-prename descclassname">POP3.</code><code class="sig-name descname">quit</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.quit" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>登出:提交更改,解除邮箱锁定,断开连接。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="method">
|
||
<dt id="poplib.POP3.top">
|
||
<code class="sig-prename descclassname">POP3.</code><code class="sig-name descname">top</code><span class="sig-paren">(</span><em class="sig-param">which</em>, <em class="sig-param">howmuch</em><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.top" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>检索编号为 <em>which</em> 的消息,范围是消息头加上消息头往后数 <em>howmuch</em> 行。结果的形式为 <code class="docutils literal notranslate"><span class="pre">(response,</span> <span class="pre">['line',</span> <span class="pre">...],</span> <span class="pre">octets)</span></code>。</p>
|
||
<p>本方法使用 POP3 TOP 命令,不同于 RETR 命令,它不设置邮件的已读标志位。不幸的是,TOP 在 RFC 中说明不清晰,且在小众的服务器软件中往往不可用。信任并使用它之前,请先手动对目标 POP3 服务器测试本方法。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="method">
|
||
<dt id="poplib.POP3.uidl">
|
||
<code class="sig-prename descclassname">POP3.</code><code class="sig-name descname">uidl</code><span class="sig-paren">(</span><em class="sig-param">which=None</em><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.uidl" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>返回消息摘要(唯一 ID)列表。如果指定了 <em>which</em>,那么结果将包含那条消息的唯一 ID,形式为 <code class="docutils literal notranslate"><span class="pre">'response</span> <span class="pre">mesgnum</span> <span class="pre">uid</span></code>,如果未指定,那么结果为列表 <code class="docutils literal notranslate"><span class="pre">(response,</span> <span class="pre">['mesgnum</span> <span class="pre">uid',</span> <span class="pre">...],</span> <span class="pre">octets)</span></code>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="method">
|
||
<dt id="poplib.POP3.utf8">
|
||
<code class="sig-prename descclassname">POP3.</code><code class="sig-name descname">utf8</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.utf8" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>尝试切换至 UTF-8 模式。成功则返回服务器的响应,失败则引发 <a class="reference internal" href="#poplib.error_proto" title="poplib.error_proto"><code class="xref py py-class docutils literal notranslate"><span class="pre">error_proto</span></code></a> 异常。在 <span class="target" id="index-17"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc6856.html"><strong>RFC 6856</strong></a> 中有说明。</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.5 新版功能.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="method">
|
||
<dt id="poplib.POP3.stls">
|
||
<code class="sig-prename descclassname">POP3.</code><code class="sig-name descname">stls</code><span class="sig-paren">(</span><em class="sig-param">context=None</em><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.stls" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>在活动连接上开启 TLS 会话,在 <span class="target" id="index-18"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2595.html"><strong>RFC 2595</strong></a> 中有说明。仅在用户身份验证前允许这样做。</p>
|
||
<p><em>context</em> 参数是一个 <a class="reference internal" href="ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">ssl.SSLContext</span></code></a> 对象,该对象可以将 SSL 配置选项、证书和私钥打包放入一个单独的(可以长久存在的)结构中。请阅读 <a class="reference internal" href="ssl.html#ssl-security"><span class="std std-ref">安全考量</span></a> 以获取最佳实践。</p>
|
||
<p>此方法支持通过 <a class="reference internal" href="ssl.html#ssl.SSLContext.check_hostname" title="ssl.SSLContext.check_hostname"><code class="xref py py-attr docutils literal notranslate"><span class="pre">ssl.SSLContext.check_hostname</span></code></a> 和 <em>服务器名称指示</em> (参见 <a class="reference internal" href="ssl.html#ssl.HAS_SNI" title="ssl.HAS_SNI"><code class="xref py py-data docutils literal notranslate"><span class="pre">ssl.HAS_SNI</span></code></a>) 进行主机名检查。</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.4 新版功能.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<p><a class="reference internal" href="#poplib.POP3_SSL" title="poplib.POP3_SSL"><code class="xref py py-class docutils literal notranslate"><span class="pre">POP3_SSL</span></code></a> 实例没有额外方法。该子类的接口与其父类的相同。</p>
|
||
</section>
|
||
<section id="pop3-example">
|
||
<span id="id2"></span><h2>POP3 示例<a class="headerlink" href="#pop3-example" title="永久链接至标题">¶</a></h2>
|
||
<p>以下是一个最短示例(不带错误检查),该示例将打开邮箱,检索并打印所有消息:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">getpass</span><span class="o">,</span> <span class="nn">poplib</span>
|
||
|
||
<span class="n">M</span> <span class="o">=</span> <span class="n">poplib</span><span class="o">.</span><span class="n">POP3</span><span class="p">(</span><span class="s1">'localhost'</span><span class="p">)</span>
|
||
<span class="n">M</span><span class="o">.</span><span class="n">user</span><span class="p">(</span><span class="n">getpass</span><span class="o">.</span><span class="n">getuser</span><span class="p">())</span>
|
||
<span class="n">M</span><span class="o">.</span><span class="n">pass_</span><span class="p">(</span><span class="n">getpass</span><span class="o">.</span><span class="n">getpass</span><span class="p">())</span>
|
||
<span class="n">numMessages</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">M</span><span class="o">.</span><span class="n">list</span><span class="p">()[</span><span class="mi">1</span><span class="p">])</span>
|
||
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">numMessages</span><span class="p">):</span>
|
||
<span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="n">M</span><span class="o">.</span><span class="n">retr</span><span class="p">(</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">)[</span><span class="mi">1</span><span class="p">]:</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="n">j</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>模块的最后有一段测试,其中包含的用法示例更加广泛。</p>
|
||
</section>
|
||
</section>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||
<div class="sphinxsidebarwrapper">
|
||
<h3><a href="../contents.html">目录</a></h3>
|
||
<ul>
|
||
<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">poplib</span></code> --- POP3 协议客户端</a><ul>
|
||
<li><a class="reference internal" href="#pop3-objects">POP3 对象</a></li>
|
||
<li><a class="reference internal" href="#pop3-example">POP3 示例</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
<h4>上一个主题</h4>
|
||
<p class="topless"><a href="ftplib.html"
|
||
title="上一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ftplib</span></code> --- FTP 协议客户端</a></p>
|
||
<h4>下一个主题</h4>
|
||
<p class="topless"><a href="imaplib.html"
|
||
title="下一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">imaplib</span></code> --- IMAP4 协议客户端</a></p>
|
||
<div role="note" aria-label="source link">
|
||
<h3>本页</h3>
|
||
<ul class="this-page-menu">
|
||
<li><a href="../bugs.html">报告 Bug</a></li>
|
||
<li>
|
||
<a href="https://github.com/python/cpython/blob/3.8/Doc/library/poplib.rst"
|
||
rel="nofollow">显示源代码
|
||
</a>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="clearer"></div>
|
||
</div>
|
||
<div class="related" role="navigation" aria-label="related navigation">
|
||
<h3>导航</h3>
|
||
<ul>
|
||
<li class="right" style="margin-right: 10px">
|
||
<a href="../genindex.html" title="总目录"
|
||
>索引</a></li>
|
||
<li class="right" >
|
||
<a href="../py-modindex.html" title="Python 模块索引"
|
||
>模块</a> |</li>
|
||
<li class="right" >
|
||
<a href="imaplib.html" title="imaplib --- IMAP4 协议客户端"
|
||
>下一页</a> |</li>
|
||
<li class="right" >
|
||
<a href="ftplib.html" title="ftplib --- FTP 协议客户端"
|
||
>上一页</a> |</li>
|
||
|
||
<li><img src="../_static/py.svg" alt="python logo" style="vertical-align: middle; margin-top: -1px"/></li>
|
||
<li><a href="https://www.python.org/">Python</a> »</li>
|
||
<li class="switchers">
|
||
<div class="language_switcher_placeholder"></div>
|
||
<div class="version_switcher_placeholder"></div>
|
||
</li>
|
||
<li>
|
||
|
||
</li>
|
||
<li id="cpython-language-and-version">
|
||
<a href="../index.html">3.8.20 Documentation</a> »
|
||
</li>
|
||
|
||
<li class="nav-item nav-item-1"><a href="index.html" >Python 标准库</a> »</li>
|
||
<li class="nav-item nav-item-2"><a href="internet.html" >互联网协议和支持</a> »</li>
|
||
<li class="right">
|
||
|
||
|
||
<div class="inline-search" role="search">
|
||
<form class="inline-search" action="../search.html" method="get">
|
||
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
|
||
<input type="submit" value="转向" />
|
||
<input type="hidden" name="check_keywords" value="yes" />
|
||
<input type="hidden" name="area" value="default" />
|
||
</form>
|
||
</div>
|
||
|
|
||
</li>
|
||
|
||
</ul>
|
||
</div>
|
||
<div class="footer">
|
||
© <a href="../copyright.html">版权所有</a> 2001-2024, Python Software Foundation.
|
||
<br />
|
||
This page is licensed under the Python Software Foundation License Version 2.
|
||
<br />
|
||
Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
|
||
<br />
|
||
|
||
<br />
|
||
|
||
The Python Software Foundation is a non-profit corporation.
|
||
<a href="https://www.python.org/psf/donations/">Please donate.</a>
|
||
<br />
|
||
<br />
|
||
|
||
最后更新于 12月 09, 2024.
|
||
<a href="https://docs.python.org/3/bugs.html">Found a bug</a>?
|
||
<br />
|
||
|
||
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 2.4.4.
|
||
</div>
|
||
|
||
</body>
|
||
</html> |