gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

595 lines
43KB

  1. <!DOCTYPE html>
  2. <html lang="en" data-content_root="../">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <meta property="og:title" content="poplib — POP3 protocol client" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/library/poplib.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Source code: Lib/poplib.py This module defines a class, POP3, which encapsulates a connection to a POP3 server and implements the protocol as defined in RFC 1939. The POP3 class supports both the m..." />
  11. <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
  12. <meta property="og:image:alt" content="Python documentation" />
  13. <meta name="description" content="Source code: Lib/poplib.py This module defines a class, POP3, which encapsulates a connection to a POP3 server and implements the protocol as defined in RFC 1939. The POP3 class supports both the m..." />
  14. <meta property="og:image:width" content="200" />
  15. <meta property="og:image:height" content="200" />
  16. <meta name="theme-color" content="#3776ab" />
  17. <title>poplib — POP3 protocol client &#8212; Python 3.12.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
  18. <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
  19. <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=bb723527" />
  20. <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=b20cc3f5" />
  21. <script src="../_static/documentation_options.js?v=2c828074"></script>
  22. <script src="../_static/doctools.js?v=888ff710"></script>
  23. <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
  24. <script src="../_static/sidebar.js"></script>
  25. <link rel="search" type="application/opensearchdescription+xml"
  26. title="Search within Python 3.12.3 documentation"
  27. href="../_static/opensearch.xml"/>
  28. <link rel="author" title="About these documents" href="../about.html" />
  29. <link rel="index" title="Index" href="../genindex.html" />
  30. <link rel="search" title="Search" href="../search.html" />
  31. <link rel="copyright" title="Copyright" href="../copyright.html" />
  32. <link rel="next" title="imaplib — IMAP4 protocol client" href="imaplib.html" />
  33. <link rel="prev" title="ftplib — FTP protocol client" href="ftplib.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/library/poplib.html" />
  35. <style>
  36. @media only screen {
  37. table.full-width-table {
  38. width: 100%;
  39. }
  40. }
  41. </style>
  42. <link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
  43. <link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
  44. <script type="text/javascript" src="../_static/copybutton.js"></script>
  45. <script type="text/javascript" src="../_static/menu.js"></script>
  46. <script type="text/javascript" src="../_static/search-focus.js"></script>
  47. <script type="text/javascript" src="../_static/themetoggle.js"></script>
  48. </head>
  49. <body>
  50. <div class="mobile-nav">
  51. <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
  52. aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
  53. <nav class="nav-content" role="navigation">
  54. <label for="menuToggler" class="toggler__label">
  55. <span></span>
  56. </label>
  57. <span class="nav-items-wrapper">
  58. <a href="https://www.python.org/" class="nav-logo">
  59. <img src="../_static/py.svg" alt="Python logo"/>
  60. </a>
  61. <span class="version_switcher_placeholder"></span>
  62. <form role="search" class="search" action="../search.html" method="get">
  63. <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
  64. <path fill-rule="nonzero" fill="currentColor" 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"></path>
  65. </svg>
  66. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  67. <input type="submit" value="Go"/>
  68. </form>
  69. </span>
  70. </nav>
  71. <div class="menu-wrapper">
  72. <nav class="menu" role="navigation" aria-label="main navigation">
  73. <div class="language_switcher_placeholder"></div>
  74. <label class="theme-selector-label">
  75. Theme
  76. <select class="theme-selector" oninput="activateTheme(this.value)">
  77. <option value="auto" selected>Auto</option>
  78. <option value="light">Light</option>
  79. <option value="dark">Dark</option>
  80. </select>
  81. </label>
  82. <div>
  83. <h3><a href="../contents.html">Table of Contents</a></h3>
  84. <ul>
  85. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">poplib</span></code> — POP3 protocol client</a><ul>
  86. <li><a class="reference internal" href="#pop3-objects">POP3 Objects</a></li>
  87. <li><a class="reference internal" href="#pop3-example">POP3 Example</a></li>
  88. </ul>
  89. </li>
  90. </ul>
  91. </div>
  92. <div>
  93. <h4>Previous topic</h4>
  94. <p class="topless"><a href="ftplib.html"
  95. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ftplib</span></code> — FTP protocol client</a></p>
  96. </div>
  97. <div>
  98. <h4>Next topic</h4>
  99. <p class="topless"><a href="imaplib.html"
  100. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">imaplib</span></code> — IMAP4 protocol client</a></p>
  101. </div>
  102. <div role="note" aria-label="source link">
  103. <h3>This Page</h3>
  104. <ul class="this-page-menu">
  105. <li><a href="../bugs.html">Report a Bug</a></li>
  106. <li>
  107. <a href="https://github.com/python/cpython/blob/main/Doc/library/poplib.rst"
  108. rel="nofollow">Show Source
  109. </a>
  110. </li>
  111. </ul>
  112. </div>
  113. </nav>
  114. </div>
  115. </div>
  116. <div class="related" role="navigation" aria-label="related navigation">
  117. <h3>Navigation</h3>
  118. <ul>
  119. <li class="right" style="margin-right: 10px">
  120. <a href="../genindex.html" title="General Index"
  121. accesskey="I">index</a></li>
  122. <li class="right" >
  123. <a href="../py-modindex.html" title="Python Module Index"
  124. >modules</a> |</li>
  125. <li class="right" >
  126. <a href="imaplib.html" title="imaplib — IMAP4 protocol client"
  127. accesskey="N">next</a> |</li>
  128. <li class="right" >
  129. <a href="ftplib.html" title="ftplib — FTP protocol client"
  130. accesskey="P">previous</a> |</li>
  131. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  132. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  133. <li class="switchers">
  134. <div class="language_switcher_placeholder"></div>
  135. <div class="version_switcher_placeholder"></div>
  136. </li>
  137. <li>
  138. </li>
  139. <li id="cpython-language-and-version">
  140. <a href="../index.html">3.12.3 Documentation</a> &#187;
  141. </li>
  142. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  143. <li class="nav-item nav-item-2"><a href="internet.html" accesskey="U">Internet Protocols and Support</a> &#187;</li>
  144. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">poplib</span></code> — POP3 protocol client</a></li>
  145. <li class="right">
  146. <div class="inline-search" role="search">
  147. <form class="inline-search" action="../search.html" method="get">
  148. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  149. <input type="submit" value="Go" />
  150. </form>
  151. </div>
  152. |
  153. </li>
  154. <li class="right">
  155. <label class="theme-selector-label">
  156. Theme
  157. <select class="theme-selector" oninput="activateTheme(this.value)">
  158. <option value="auto" selected>Auto</option>
  159. <option value="light">Light</option>
  160. <option value="dark">Dark</option>
  161. </select>
  162. </label> |</li>
  163. </ul>
  164. </div>
  165. <div class="document">
  166. <div class="documentwrapper">
  167. <div class="bodywrapper">
  168. <div class="body" role="main">
  169. <section id="module-poplib">
  170. <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 protocol client<a class="headerlink" href="#module-poplib" title="Link to this heading">¶</a></h1>
  171. <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/poplib.py">Lib/poplib.py</a></p>
  172. <hr class="docutils" id="index-0" />
  173. <p>This module defines a class, <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>, which encapsulates a connection to a
  174. POP3 server and implements the protocol as defined in <span class="target" id="index-1"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc1939.html"><strong>RFC 1939</strong></a>. The
  175. <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> class supports both the minimal and optional command sets from
  176. <span class="target" id="index-2"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc1939.html"><strong>RFC 1939</strong></a>. The <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> class also supports the <code class="docutils literal notranslate"><span class="pre">STLS</span></code> command introduced
  177. in <span class="target" id="index-3"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc2595.html"><strong>RFC 2595</strong></a> to enable encrypted communication on an already established connection.</p>
  178. <p>Additionally, this module provides a class <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>, which provides
  179. support for connecting to POP3 servers that use SSL as an underlying protocol
  180. layer.</p>
  181. <p>Note that POP3, though widely supported, is obsolescent. The implementation
  182. quality of POP3 servers varies widely, and too many are quite poor. If your
  183. mailserver supports IMAP, you would be better off using the
  184. <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> class, as IMAP servers tend to be better implemented.</p>
  185. <div class="availability docutils container">
  186. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: not Emscripten, not WASI.</p>
  187. <p>This module does not work or is not available on WebAssembly platforms
  188. <code class="docutils literal notranslate"><span class="pre">wasm32-emscripten</span></code> and <code class="docutils literal notranslate"><span class="pre">wasm32-wasi</span></code>. See
  189. <a class="reference internal" href="intro.html#wasm-availability"><span class="std std-ref">WebAssembly platforms</span></a> for more information.</p>
  190. </div>
  191. <p>The <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> module provides two classes:</p>
  192. <dl class="py class">
  193. <dt class="sig sig-object py" id="poplib.POP3">
  194. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">poplib.</span></span><span class="sig-name descname"><span class="pre">POP3</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">host</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">port=POP3_PORT</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">timeout</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3" title="Link to this definition">¶</a></dt>
  195. <dd><p>This class implements the actual POP3 protocol. The connection is created when
  196. the instance is initialized. If <em>port</em> is omitted, the standard POP3 port (110)
  197. is used. The optional <em>timeout</em> parameter specifies a timeout in seconds for the
  198. connection attempt (if not specified, the global default timeout setting will
  199. be used).</p>
  200. <p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">poplib.connect</span></code> with arguments <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>
  201. <p class="audit-hook"><p>All commands will raise an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a>
  202. <code class="docutils literal notranslate"><span class="pre">poplib.putline</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">self</span></code> and <code class="docutils literal notranslate"><span class="pre">line</span></code>,
  203. where <code class="docutils literal notranslate"><span class="pre">line</span></code> is the bytes about to be sent to the remote host.</p>
  204. </p>
  205. <div class="versionchanged">
  206. <p><span class="versionmodified changed">Changed in version 3.9: </span>If the <em>timeout</em> parameter is set to be zero, it will raise a
  207. <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-class docutils literal notranslate"><span class="pre">ValueError</span></code></a> to prevent the creation of a non-blocking socket.</p>
  208. </div>
  209. </dd></dl>
  210. <dl class="py class">
  211. <dt class="sig sig-object py" id="poplib.POP3_SSL">
  212. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">poplib.</span></span><span class="sig-name descname"><span class="pre">POP3_SSL</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">host</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">port</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">POP3_SSL_PORT</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">timeout</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">context</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3_SSL" title="Link to this definition">¶</a></dt>
  213. <dd><p>This is a subclass of <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> that connects to the server over an SSL
  214. encrypted socket. If <em>port</em> is not specified, 995, the standard POP3-over-SSL
  215. port is used. <em>timeout</em> works as in the <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> constructor.
  216. <em>context</em> is an optional <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> object which allows
  217. bundling SSL configuration options, certificates and private keys into a
  218. single (potentially long-lived) structure. Please read <a class="reference internal" href="ssl.html#ssl-security"><span class="std std-ref">Security considerations</span></a>
  219. for best practices.</p>
  220. <p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">poplib.connect</span></code> with arguments <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>
  221. <p class="audit-hook"><p>All commands will raise an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a>
  222. <code class="docutils literal notranslate"><span class="pre">poplib.putline</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">self</span></code> and <code class="docutils literal notranslate"><span class="pre">line</span></code>,
  223. where <code class="docutils literal notranslate"><span class="pre">line</span></code> is the bytes about to be sent to the remote host.</p>
  224. </p>
  225. <div class="versionchanged">
  226. <p><span class="versionmodified changed">Changed in version 3.2: </span><em>context</em> parameter added.</p>
  227. </div>
  228. <div class="versionchanged">
  229. <p><span class="versionmodified changed">Changed in version 3.4: </span>The class now supports hostname check with
  230. <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> and <em>Server Name Indication</em> (see
  231. <a class="reference internal" href="ssl.html#ssl.HAS_SNI" title="ssl.HAS_SNI"><code class="xref py py-const docutils literal notranslate"><span class="pre">ssl.HAS_SNI</span></code></a>).</p>
  232. </div>
  233. <div class="versionchanged">
  234. <p><span class="versionmodified changed">Changed in version 3.9: </span>If the <em>timeout</em> parameter is set to be zero, it will raise a
  235. <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-class docutils literal notranslate"><span class="pre">ValueError</span></code></a> to prevent the creation of a non-blocking socket.</p>
  236. </div>
  237. <div class="versionchanged">
  238. <p><span class="versionmodified changed">Changed in version 3.12: </span>The deprecated <em>keyfile</em> and <em>certfile</em> parameters have been removed.</p>
  239. </div>
  240. </dd></dl>
  241. <p>One exception is defined as an attribute of the <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> module:</p>
  242. <dl class="py exception">
  243. <dt class="sig sig-object py" id="poplib.error_proto">
  244. <em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">poplib.</span></span><span class="sig-name descname"><span class="pre">error_proto</span></span><a class="headerlink" href="#poplib.error_proto" title="Link to this definition">¶</a></dt>
  245. <dd><p>Exception raised on any errors from this module (errors from <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>
  246. module are not caught). The reason for the exception is passed to the
  247. constructor as a string.</p>
  248. </dd></dl>
  249. <div class="admonition seealso">
  250. <p class="admonition-title">See also</p>
  251. <dl class="simple">
  252. <dt>Module <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>The standard Python IMAP module.</p>
  253. </dd>
  254. <dt><a class="reference external" href="http://www.catb.org/~esr/fetchmail/fetchmail-FAQ.html">Frequently Asked Questions About Fetchmail</a></dt><dd><p>The FAQ for the <strong class="program">fetchmail</strong> POP/IMAP client collects information on
  255. POP3 server variations and RFC noncompliance that may be useful if you need to
  256. write an application based on the POP protocol.</p>
  257. </dd>
  258. </dl>
  259. </div>
  260. <section id="pop3-objects">
  261. <span id="id1"></span><h2>POP3 Objects<a class="headerlink" href="#pop3-objects" title="Link to this heading">¶</a></h2>
  262. <p>All POP3 commands are represented by methods of the same name, in lowercase;
  263. most return the response text sent by the server.</p>
  264. <p>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> instance has the following methods:</p>
  265. <dl class="py method">
  266. <dt class="sig sig-object py" id="poplib.POP3.set_debuglevel">
  267. <span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">set_debuglevel</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">level</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.set_debuglevel" title="Link to this definition">¶</a></dt>
  268. <dd><p>Set the instance’s debugging level. This controls the amount of debugging
  269. output printed. The default, <code class="docutils literal notranslate"><span class="pre">0</span></code>, produces no debugging output. A value of
  270. <code class="docutils literal notranslate"><span class="pre">1</span></code> produces a moderate amount of debugging output, generally a single line
  271. per request. A value of <code class="docutils literal notranslate"><span class="pre">2</span></code> or higher produces the maximum amount of
  272. debugging output, logging each line sent and received on the control connection.</p>
  273. </dd></dl>
  274. <dl class="py method">
  275. <dt class="sig sig-object py" id="poplib.POP3.getwelcome">
  276. <span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">getwelcome</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.getwelcome" title="Link to this definition">¶</a></dt>
  277. <dd><p>Returns the greeting string sent by the POP3 server.</p>
  278. </dd></dl>
  279. <dl class="py method">
  280. <dt class="sig sig-object py" id="poplib.POP3.capa">
  281. <span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">capa</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.capa" title="Link to this definition">¶</a></dt>
  282. <dd><p>Query the server’s capabilities as specified in <span class="target" id="index-4"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc2449.html"><strong>RFC 2449</strong></a>.
  283. Returns a dictionary in the form <code class="docutils literal notranslate"><span class="pre">{'name':</span> <span class="pre">['param'...]}</span></code>.</p>
  284. <div class="versionadded">
  285. <p><span class="versionmodified added">New in version 3.4.</span></p>
  286. </div>
  287. </dd></dl>
  288. <dl class="py method">
  289. <dt class="sig sig-object py" id="poplib.POP3.user">
  290. <span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">user</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">username</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.user" title="Link to this definition">¶</a></dt>
  291. <dd><p>Send user command, response should indicate that a password is required.</p>
  292. </dd></dl>
  293. <dl class="py method">
  294. <dt class="sig sig-object py" id="poplib.POP3.pass_">
  295. <span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">pass_</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">password</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.pass_" title="Link to this definition">¶</a></dt>
  296. <dd><p>Send password, response includes message count and mailbox size. Note: the
  297. mailbox on the server is locked until <a class="reference internal" href="#poplib.POP3.quit" title="poplib.POP3.quit"><code class="xref py py-meth docutils literal notranslate"><span class="pre">quit()</span></code></a> is called.</p>
  298. </dd></dl>
  299. <dl class="py method">
  300. <dt class="sig sig-object py" id="poplib.POP3.apop">
  301. <span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">apop</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">user</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">secret</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.apop" title="Link to this definition">¶</a></dt>
  302. <dd><p>Use the more secure APOP authentication to log into the POP3 server.</p>
  303. </dd></dl>
  304. <dl class="py method">
  305. <dt class="sig sig-object py" id="poplib.POP3.rpop">
  306. <span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">rpop</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">user</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.rpop" title="Link to this definition">¶</a></dt>
  307. <dd><p>Use RPOP authentication (similar to UNIX r-commands) to log into POP3 server.</p>
  308. </dd></dl>
  309. <dl class="py method">
  310. <dt class="sig sig-object py" id="poplib.POP3.stat">
  311. <span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">stat</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.stat" title="Link to this definition">¶</a></dt>
  312. <dd><p>Get mailbox status. The result is a tuple of 2 integers: <code class="docutils literal notranslate"><span class="pre">(message</span> <span class="pre">count,</span>
  313. <span class="pre">mailbox</span> <span class="pre">size)</span></code>.</p>
  314. </dd></dl>
  315. <dl class="py method">
  316. <dt class="sig sig-object py" id="poplib.POP3.list">
  317. <span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">list</span></span><span class="sig-paren">(</span><span class="optional">[</span><em class="sig-param"><span class="n"><span class="pre">which</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.list" title="Link to this definition">¶</a></dt>
  318. <dd><p>Request message list, result is in the form <code class="docutils literal notranslate"><span class="pre">(response,</span> <span class="pre">['mesg_num</span> <span class="pre">octets',</span>
  319. <span class="pre">...],</span> <span class="pre">octets)</span></code>. If <em>which</em> is set, it is the message to list.</p>
  320. </dd></dl>
  321. <dl class="py method">
  322. <dt class="sig sig-object py" id="poplib.POP3.retr">
  323. <span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">retr</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">which</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.retr" title="Link to this definition">¶</a></dt>
  324. <dd><p>Retrieve whole message number <em>which</em>, and set its seen flag. Result is in form
  325. <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>
  326. </dd></dl>
  327. <dl class="py method">
  328. <dt class="sig sig-object py" id="poplib.POP3.dele">
  329. <span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">dele</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">which</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.dele" title="Link to this definition">¶</a></dt>
  330. <dd><p>Flag message number <em>which</em> for deletion. On most servers deletions are not
  331. actually performed until QUIT (the major exception is Eudora QPOP, which
  332. deliberately violates the RFCs by doing pending deletes on any disconnect).</p>
  333. </dd></dl>
  334. <dl class="py method">
  335. <dt class="sig sig-object py" id="poplib.POP3.rset">
  336. <span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">rset</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.rset" title="Link to this definition">¶</a></dt>
  337. <dd><p>Remove any deletion marks for the mailbox.</p>
  338. </dd></dl>
  339. <dl class="py method">
  340. <dt class="sig sig-object py" id="poplib.POP3.noop">
  341. <span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">noop</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.noop" title="Link to this definition">¶</a></dt>
  342. <dd><p>Do nothing. Might be used as a keep-alive.</p>
  343. </dd></dl>
  344. <dl class="py method">
  345. <dt class="sig sig-object py" id="poplib.POP3.quit">
  346. <span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">quit</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.quit" title="Link to this definition">¶</a></dt>
  347. <dd><p>Signoff: commit changes, unlock mailbox, drop connection.</p>
  348. </dd></dl>
  349. <dl class="py method">
  350. <dt class="sig sig-object py" id="poplib.POP3.top">
  351. <span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">top</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">which</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">howmuch</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.top" title="Link to this definition">¶</a></dt>
  352. <dd><p>Retrieves the message header plus <em>howmuch</em> lines of the message after the
  353. header of message number <em>which</em>. Result is in form <code class="docutils literal notranslate"><span class="pre">(response,</span> <span class="pre">['line',</span> <span class="pre">...],</span>
  354. <span class="pre">octets)</span></code>.</p>
  355. <p>The POP3 TOP command this method uses, unlike the RETR command, doesn’t set the
  356. message’s seen flag; unfortunately, TOP is poorly specified in the RFCs and is
  357. frequently broken in off-brand servers. Test this method by hand against the
  358. POP3 servers you will use before trusting it.</p>
  359. </dd></dl>
  360. <dl class="py method">
  361. <dt class="sig sig-object py" id="poplib.POP3.uidl">
  362. <span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">uidl</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">which</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.uidl" title="Link to this definition">¶</a></dt>
  363. <dd><p>Return message digest (unique id) list. If <em>which</em> is specified, result contains
  364. the unique id for that message in the form <code class="docutils literal notranslate"><span class="pre">'response</span> <span class="pre">mesgnum</span> <span class="pre">uid</span></code>, otherwise
  365. result is list <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>
  366. </dd></dl>
  367. <dl class="py method">
  368. <dt class="sig sig-object py" id="poplib.POP3.utf8">
  369. <span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">utf8</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.utf8" title="Link to this definition">¶</a></dt>
  370. <dd><p>Try to switch to UTF-8 mode. Returns the server response if successful,
  371. raises <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> if not. Specified in <span class="target" id="index-5"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc6856.html"><strong>RFC 6856</strong></a>.</p>
  372. <div class="versionadded">
  373. <p><span class="versionmodified added">New in version 3.5.</span></p>
  374. </div>
  375. </dd></dl>
  376. <dl class="py method">
  377. <dt class="sig sig-object py" id="poplib.POP3.stls">
  378. <span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">stls</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">context</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.stls" title="Link to this definition">¶</a></dt>
  379. <dd><p>Start a TLS session on the active connection as specified in <span class="target" id="index-6"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc2595.html"><strong>RFC 2595</strong></a>.
  380. This is only allowed before user authentication</p>
  381. <p><em>context</em> parameter is a <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> object which allows
  382. bundling SSL configuration options, certificates and private keys into
  383. a single (potentially long-lived) structure. Please read <a class="reference internal" href="ssl.html#ssl-security"><span class="std std-ref">Security considerations</span></a>
  384. for best practices.</p>
  385. <p>This method supports hostname checking via
  386. <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> and <em>Server Name Indication</em> (see
  387. <a class="reference internal" href="ssl.html#ssl.HAS_SNI" title="ssl.HAS_SNI"><code class="xref py py-const docutils literal notranslate"><span class="pre">ssl.HAS_SNI</span></code></a>).</p>
  388. <div class="versionadded">
  389. <p><span class="versionmodified added">New in version 3.4.</span></p>
  390. </div>
  391. </dd></dl>
  392. <p>Instances of <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> have no additional methods. The interface of this
  393. subclass is identical to its parent.</p>
  394. </section>
  395. <section id="pop3-example">
  396. <span id="id2"></span><h2>POP3 Example<a class="headerlink" href="#pop3-example" title="Link to this heading">¶</a></h2>
  397. <p>Here is a minimal example (without error checking) that opens a mailbox and
  398. retrieves and prints all messages:</p>
  399. <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>
  400. <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">&#39;localhost&#39;</span><span class="p">)</span>
  401. <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>
  402. <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>
  403. <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>
  404. <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>
  405. <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>
  406. <span class="nb">print</span><span class="p">(</span><span class="n">j</span><span class="p">)</span>
  407. </pre></div>
  408. </div>
  409. <p>At the end of the module, there is a test section that contains a more extensive
  410. example of usage.</p>
  411. </section>
  412. </section>
  413. <div class="clearer"></div>
  414. </div>
  415. </div>
  416. </div>
  417. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  418. <div class="sphinxsidebarwrapper">
  419. <div>
  420. <h3><a href="../contents.html">Table of Contents</a></h3>
  421. <ul>
  422. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">poplib</span></code> — POP3 protocol client</a><ul>
  423. <li><a class="reference internal" href="#pop3-objects">POP3 Objects</a></li>
  424. <li><a class="reference internal" href="#pop3-example">POP3 Example</a></li>
  425. </ul>
  426. </li>
  427. </ul>
  428. </div>
  429. <div>
  430. <h4>Previous topic</h4>
  431. <p class="topless"><a href="ftplib.html"
  432. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ftplib</span></code> — FTP protocol client</a></p>
  433. </div>
  434. <div>
  435. <h4>Next topic</h4>
  436. <p class="topless"><a href="imaplib.html"
  437. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">imaplib</span></code> — IMAP4 protocol client</a></p>
  438. </div>
  439. <div role="note" aria-label="source link">
  440. <h3>This Page</h3>
  441. <ul class="this-page-menu">
  442. <li><a href="../bugs.html">Report a Bug</a></li>
  443. <li>
  444. <a href="https://github.com/python/cpython/blob/main/Doc/library/poplib.rst"
  445. rel="nofollow">Show Source
  446. </a>
  447. </li>
  448. </ul>
  449. </div>
  450. </div>
  451. <div id="sidebarbutton" title="Collapse sidebar">
  452. <span>«</span>
  453. </div>
  454. </div>
  455. <div class="clearer"></div>
  456. </div>
  457. <div class="related" role="navigation" aria-label="related navigation">
  458. <h3>Navigation</h3>
  459. <ul>
  460. <li class="right" style="margin-right: 10px">
  461. <a href="../genindex.html" title="General Index"
  462. >index</a></li>
  463. <li class="right" >
  464. <a href="../py-modindex.html" title="Python Module Index"
  465. >modules</a> |</li>
  466. <li class="right" >
  467. <a href="imaplib.html" title="imaplib — IMAP4 protocol client"
  468. >next</a> |</li>
  469. <li class="right" >
  470. <a href="ftplib.html" title="ftplib — FTP protocol client"
  471. >previous</a> |</li>
  472. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  473. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  474. <li class="switchers">
  475. <div class="language_switcher_placeholder"></div>
  476. <div class="version_switcher_placeholder"></div>
  477. </li>
  478. <li>
  479. </li>
  480. <li id="cpython-language-and-version">
  481. <a href="../index.html">3.12.3 Documentation</a> &#187;
  482. </li>
  483. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  484. <li class="nav-item nav-item-2"><a href="internet.html" >Internet Protocols and Support</a> &#187;</li>
  485. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">poplib</span></code> — POP3 protocol client</a></li>
  486. <li class="right">
  487. <div class="inline-search" role="search">
  488. <form class="inline-search" action="../search.html" method="get">
  489. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  490. <input type="submit" value="Go" />
  491. </form>
  492. </div>
  493. |
  494. </li>
  495. <li class="right">
  496. <label class="theme-selector-label">
  497. Theme
  498. <select class="theme-selector" oninput="activateTheme(this.value)">
  499. <option value="auto" selected>Auto</option>
  500. <option value="light">Light</option>
  501. <option value="dark">Dark</option>
  502. </select>
  503. </label> |</li>
  504. </ul>
  505. </div>
  506. <div class="footer">
  507. &copy;
  508. <a href="../copyright.html">
  509. Copyright
  510. </a>
  511. 2001-2024, Python Software Foundation.
  512. <br />
  513. This page is licensed under the Python Software Foundation License Version 2.
  514. <br />
  515. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  516. <br />
  517. See <a href="/license.html">History and License</a> for more information.<br />
  518. <br />
  519. The Python Software Foundation is a non-profit corporation.
  520. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  521. <br />
  522. <br />
  523. Last updated on Apr 09, 2024 (13:47 UTC).
  524. <a href="/bugs.html">Found a bug</a>?
  525. <br />
  526. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  527. </div>
  528. </body>
  529. </html>
上海开阖软件有限公司 沪ICP备12045867号-1