diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/python~3.12/library%2Fpoplib.html | |
new repository
Diffstat (limited to 'devdocs/python~3.12/library%2Fpoplib.html')
| -rw-r--r-- | devdocs/python~3.12/library%2Fpoplib.html | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/devdocs/python~3.12/library%2Fpoplib.html b/devdocs/python~3.12/library%2Fpoplib.html new file mode 100644 index 00000000..a5d39cdb --- /dev/null +++ b/devdocs/python~3.12/library%2Fpoplib.html @@ -0,0 +1,89 @@ + <span id="poplib-pop3-protocol-client"></span><h1>poplib — POP3 protocol client</h1> <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> <p>This module defines a class, <a class="reference internal" href="#poplib.POP3" title="poplib.POP3"><code>POP3</code></a>, which encapsulates a connection to a 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 <a class="reference internal" href="#poplib.POP3" title="poplib.POP3"><code>POP3</code></a> class supports both the minimal and optional command sets from <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>POP3</code></a> class also supports the <code>STLS</code> command introduced 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> <p>Additionally, this module provides a class <a class="reference internal" href="#poplib.POP3_SSL" title="poplib.POP3_SSL"><code>POP3_SSL</code></a>, which provides support for connecting to POP3 servers that use SSL as an underlying protocol layer.</p> <p>Note that POP3, though widely supported, is obsolescent. The implementation quality of POP3 servers varies widely, and too many are quite poor. If your mailserver supports IMAP, you would be better off using the <a class="reference internal" href="imaplib#imaplib.IMAP4" title="imaplib.IMAP4"><code>imaplib.IMAP4</code></a> class, as IMAP servers tend to be better implemented.</p> <div class="availability docutils container"> <p><a class="reference internal" href="https://docs.python.org/3.12/library/intro.html#availability"><span class="std std-ref">Availability</span></a>: not Emscripten, not WASI.</p> <p>This module does not work or is not available on WebAssembly platforms <code>wasm32-emscripten</code> and <code>wasm32-wasi</code>. See <a class="reference internal" href="https://docs.python.org/3.12/library/intro.html#wasm-availability"><span class="std std-ref">WebAssembly platforms</span></a> for more information.</p> </div> <p>The <a class="reference internal" href="#module-poplib" title="poplib: POP3 protocol client (requires sockets)."><code>poplib</code></a> module provides two classes:</p> <dl class="py class"> <dt class="sig sig-object py" id="poplib.POP3"> +<code>class poplib.POP3(host, port=POP3_PORT[, timeout])</code> </dt> <dd> +<p>This class implements the actual POP3 protocol. The connection is created when the instance is initialized. If <em>port</em> is omitted, the standard POP3 port (110) is used. The optional <em>timeout</em> parameter specifies a timeout in seconds for the connection attempt (if not specified, the global default timeout setting will be used).</p> <p class="audit-hook">Raises an <a class="reference internal" href="sys#auditing"><span class="std std-ref">auditing event</span></a> <code>poplib.connect</code> with arguments <code>self</code>, <code>host</code>, <code>port</code>.</p> <p class="audit-hook"></p> +<p>All commands will raise an <a class="reference internal" href="sys#auditing"><span class="std std-ref">auditing event</span></a> <code>poplib.putline</code> with arguments <code>self</code> and <code>line</code>, where <code>line</code> is the bytes about to be sent to the remote host.</p> <div class="versionchanged"> <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 <a class="reference internal" href="exceptions#ValueError" title="ValueError"><code>ValueError</code></a> to prevent the creation of a non-blocking socket.</p> </div> </dd> +</dl> <dl class="py class"> <dt class="sig sig-object py" id="poplib.POP3_SSL"> +<code>class poplib.POP3_SSL(host, port=POP3_SSL_PORT, *, timeout=None, context=None)</code> </dt> <dd> +<p>This is a subclass of <a class="reference internal" href="#poplib.POP3" title="poplib.POP3"><code>POP3</code></a> that connects to the server over an SSL encrypted socket. If <em>port</em> is not specified, 995, the standard POP3-over-SSL port is used. <em>timeout</em> works as in the <a class="reference internal" href="#poplib.POP3" title="poplib.POP3"><code>POP3</code></a> constructor. <em>context</em> is an optional <a class="reference internal" href="ssl#ssl.SSLContext" title="ssl.SSLContext"><code>ssl.SSLContext</code></a> object which allows bundling SSL configuration options, certificates and private keys into a single (potentially long-lived) structure. Please read <a class="reference internal" href="ssl#ssl-security"><span class="std std-ref">Security considerations</span></a> for best practices.</p> <p class="audit-hook">Raises an <a class="reference internal" href="sys#auditing"><span class="std std-ref">auditing event</span></a> <code>poplib.connect</code> with arguments <code>self</code>, <code>host</code>, <code>port</code>.</p> <p class="audit-hook"></p> +<p>All commands will raise an <a class="reference internal" href="sys#auditing"><span class="std std-ref">auditing event</span></a> <code>poplib.putline</code> with arguments <code>self</code> and <code>line</code>, where <code>line</code> is the bytes about to be sent to the remote host.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.2: </span><em>context</em> parameter added.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.4: </span>The class now supports hostname check with <a class="reference internal" href="ssl#ssl.SSLContext.check_hostname" title="ssl.SSLContext.check_hostname"><code>ssl.SSLContext.check_hostname</code></a> and <em>Server Name Indication</em> (see <a class="reference internal" href="ssl#ssl.HAS_SNI" title="ssl.HAS_SNI"><code>ssl.HAS_SNI</code></a>).</p> </div> <div class="versionchanged"> <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 <a class="reference internal" href="exceptions#ValueError" title="ValueError"><code>ValueError</code></a> to prevent the creation of a non-blocking socket.</p> </div> <div class="versionchanged"> <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> </div> </dd> +</dl> <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>poplib</code></a> module:</p> <dl class="py exception"> <dt class="sig sig-object py" id="poplib.error_proto"> +<code>exception poplib.error_proto</code> </dt> <dd> +<p>Exception raised on any errors from this module (errors from <a class="reference internal" href="socket#module-socket" title="socket: Low-level networking interface."><code>socket</code></a> module are not caught). The reason for the exception is passed to the constructor as a string.</p> </dd> +</dl> <div class="admonition seealso"> <p class="admonition-title">See also</p> <dl class="simple"> <dt> +<code>Module</code> <a class="reference internal" href="imaplib#module-imaplib" title="imaplib: IMAP4 protocol client (requires sockets)."><code>imaplib</code></a> +</dt> +<dd> +<p>The standard Python IMAP module.</p> </dd> <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 POP3 server variations and RFC noncompliance that may be useful if you need to write an application based on the POP protocol.</p> </dd> </dl> </div> <section id="pop3-objects"> <span id="id1"></span><h2>POP3 Objects</h2> <p>All POP3 commands are represented by methods of the same name, in lowercase; most return the response text sent by the server.</p> <p>A <a class="reference internal" href="#poplib.POP3" title="poplib.POP3"><code>POP3</code></a> instance has the following methods:</p> <dl class="py method"> <dt class="sig sig-object py" id="poplib.POP3.set_debuglevel"> +<code>POP3.set_debuglevel(level)</code> </dt> <dd> +<p>Set the instance’s debugging level. This controls the amount of debugging output printed. The default, <code>0</code>, produces no debugging output. A value of <code>1</code> produces a moderate amount of debugging output, generally a single line per request. A value of <code>2</code> or higher produces the maximum amount of debugging output, logging each line sent and received on the control connection.</p> </dd> +</dl> <dl class="py method"> <dt class="sig sig-object py" id="poplib.POP3.getwelcome"> +<code>POP3.getwelcome()</code> </dt> <dd> +<p>Returns the greeting string sent by the POP3 server.</p> </dd> +</dl> <dl class="py method"> <dt class="sig sig-object py" id="poplib.POP3.capa"> +<code>POP3.capa()</code> </dt> <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>. Returns a dictionary in the form <code>{'name': ['param'...]}</code>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.4.</span></p> </div> </dd> +</dl> <dl class="py method"> <dt class="sig sig-object py" id="poplib.POP3.user"> +<code>POP3.user(username)</code> </dt> <dd> +<p>Send user command, response should indicate that a password is required.</p> </dd> +</dl> <dl class="py method"> <dt class="sig sig-object py" id="poplib.POP3.pass_"> +<code>POP3.pass_(password)</code> </dt> <dd> +<p>Send password, response includes message count and mailbox size. Note: the mailbox on the server is locked until <a class="reference internal" href="#poplib.POP3.quit" title="poplib.POP3.quit"><code>quit()</code></a> is called.</p> </dd> +</dl> <dl class="py method"> <dt class="sig sig-object py" id="poplib.POP3.apop"> +<code>POP3.apop(user, secret)</code> </dt> <dd> +<p>Use the more secure APOP authentication to log into the POP3 server.</p> </dd> +</dl> <dl class="py method"> <dt class="sig sig-object py" id="poplib.POP3.rpop"> +<code>POP3.rpop(user)</code> </dt> <dd> +<p>Use RPOP authentication (similar to UNIX r-commands) to log into POP3 server.</p> </dd> +</dl> <dl class="py method"> <dt class="sig sig-object py" id="poplib.POP3.stat"> +<code>POP3.stat()</code> </dt> <dd> +<p>Get mailbox status. The result is a tuple of 2 integers: <code>(message count, +mailbox size)</code>.</p> </dd> +</dl> <dl class="py method"> <dt class="sig sig-object py" id="poplib.POP3.list"> +<code>POP3.list([which])</code> </dt> <dd> +<p>Request message list, result is in the form <code>(response, ['mesg_num octets', +...], octets)</code>. If <em>which</em> is set, it is the message to list.</p> </dd> +</dl> <dl class="py method"> <dt class="sig sig-object py" id="poplib.POP3.retr"> +<code>POP3.retr(which)</code> </dt> <dd> +<p>Retrieve whole message number <em>which</em>, and set its seen flag. Result is in form <code>(response, ['line', ...], octets)</code>.</p> </dd> +</dl> <dl class="py method"> <dt class="sig sig-object py" id="poplib.POP3.dele"> +<code>POP3.dele(which)</code> </dt> <dd> +<p>Flag message number <em>which</em> for deletion. On most servers deletions are not actually performed until QUIT (the major exception is Eudora QPOP, which deliberately violates the RFCs by doing pending deletes on any disconnect).</p> </dd> +</dl> <dl class="py method"> <dt class="sig sig-object py" id="poplib.POP3.rset"> +<code>POP3.rset()</code> </dt> <dd> +<p>Remove any deletion marks for the mailbox.</p> </dd> +</dl> <dl class="py method"> <dt class="sig sig-object py" id="poplib.POP3.noop"> +<code>POP3.noop()</code> </dt> <dd> +<p>Do nothing. Might be used as a keep-alive.</p> </dd> +</dl> <dl class="py method"> <dt class="sig sig-object py" id="poplib.POP3.quit"> +<code>POP3.quit()</code> </dt> <dd> +<p>Signoff: commit changes, unlock mailbox, drop connection.</p> </dd> +</dl> <dl class="py method"> <dt class="sig sig-object py" id="poplib.POP3.top"> +<code>POP3.top(which, howmuch)</code> </dt> <dd> +<p>Retrieves the message header plus <em>howmuch</em> lines of the message after the header of message number <em>which</em>. Result is in form <code>(response, ['line', ...], +octets)</code>.</p> <p>The POP3 TOP command this method uses, unlike the RETR command, doesn’t set the message’s seen flag; unfortunately, TOP is poorly specified in the RFCs and is frequently broken in off-brand servers. Test this method by hand against the POP3 servers you will use before trusting it.</p> </dd> +</dl> <dl class="py method"> <dt class="sig sig-object py" id="poplib.POP3.uidl"> +<code>POP3.uidl(which=None)</code> </dt> <dd> +<p>Return message digest (unique id) list. If <em>which</em> is specified, result contains the unique id for that message in the form <code>'response mesgnum uid</code>, otherwise result is list <code>(response, ['mesgnum uid', ...], octets)</code>.</p> </dd> +</dl> <dl class="py method"> <dt class="sig sig-object py" id="poplib.POP3.utf8"> +<code>POP3.utf8()</code> </dt> <dd> +<p>Try to switch to UTF-8 mode. Returns the server response if successful, raises <a class="reference internal" href="#poplib.error_proto" title="poplib.error_proto"><code>error_proto</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> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.5.</span></p> </div> </dd> +</dl> <dl class="py method"> <dt class="sig sig-object py" id="poplib.POP3.stls"> +<code>POP3.stls(context=None)</code> </dt> <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>. This is only allowed before user authentication</p> <p><em>context</em> parameter is a <a class="reference internal" href="ssl#ssl.SSLContext" title="ssl.SSLContext"><code>ssl.SSLContext</code></a> object which allows bundling SSL configuration options, certificates and private keys into a single (potentially long-lived) structure. Please read <a class="reference internal" href="ssl#ssl-security"><span class="std std-ref">Security considerations</span></a> for best practices.</p> <p>This method supports hostname checking via <a class="reference internal" href="ssl#ssl.SSLContext.check_hostname" title="ssl.SSLContext.check_hostname"><code>ssl.SSLContext.check_hostname</code></a> and <em>Server Name Indication</em> (see <a class="reference internal" href="ssl#ssl.HAS_SNI" title="ssl.HAS_SNI"><code>ssl.HAS_SNI</code></a>).</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.4.</span></p> </div> </dd> +</dl> <p>Instances of <a class="reference internal" href="#poplib.POP3_SSL" title="poplib.POP3_SSL"><code>POP3_SSL</code></a> have no additional methods. The interface of this subclass is identical to its parent.</p> </section> <section id="pop3-example"> <span id="id2"></span><h2>POP3 Example</h2> <p>Here is a minimal example (without error checking) that opens a mailbox and retrieves and prints all messages:</p> <pre data-language="python">import getpass, poplib + +M = poplib.POP3('localhost') +M.user(getpass.getuser()) +M.pass_(getpass.getpass()) +numMessages = len(M.list()[1]) +for i in range(numMessages): + for j in M.retr(i+1)[1]: + print(j) +</pre> <p>At the end of the module, there is a test section that contains a more extensive example of usage.</p> </section> <div class="_attribution"> + <p class="_attribution-p"> + © 2001–2023 Python Software Foundation<br>Licensed under the PSF License.<br> + <a href="https://docs.python.org/3.12/library/poplib.html" class="_attribution-link">https://docs.python.org/3.12/library/poplib.html</a> + </p> +</div> |
