rest25/library/poplib.rst => rest262/library/poplib.rst
f1
2:mod:`poplib` --- POP3 protocol client
3======================================
4
5.. module:: poplib
6   :synopsis: POP3 protocol client (requires sockets).
n7- 
n7+.. sectionauthor:: Andrew T. Csillag
8+.. revised by ESR, January 2000
8
9.. index:: pair: POP3; protocol
n10- 
11-.. % By Andrew T. Csillag
12-.. % Even though I put it into LaTeX, I cannot really claim that I wrote
13-.. % it since I just stole most of it from the poplib.py source code and
14-.. % the imaplib ``chapter''.
15-.. % Revised by ESR, January 2000
16
17This module defines a class, :class:`POP3`, which encapsulates a connection to a
18POP3 server and implements the protocol as defined in :rfc:`1725`.  The
19:class:`POP3` class supports both the minimal and optional command sets.
20Additionally, this module provides a class :class:`POP3_SSL`, which provides
21support for connecting to POP3 servers that use SSL as an underlying protocol
22layer.
23
24Note that POP3, though widely supported, is obsolescent.  The implementation
25quality of POP3 servers varies widely, and too many are quite poor. If your
n26-mailserver supports IMAP, you would be better off using the ``imaplib.IMAP4``
n21+mailserver supports IMAP, you would be better off using the
27-class, as IMAP servers tend to be better implemented.
22+:class:`imaplib.IMAP4` class, as IMAP servers tend to be better implemented.
28
29A single class is provided by the :mod:`poplib` module:
30
31
n32-.. class:: POP3(host[, port])
n27+.. class:: POP3(host[, port[, timeout]])
33
34   This class implements the actual POP3 protocol.  The connection is created when
35   the instance is initialized. If *port* is omitted, the standard POP3 port (110)
n31+   is used. The optional *timeout* parameter specifies a timeout in seconds for the
32+   connection attempt (if not specified, the global default timeout setting will
36-   is used.
33+   be used).
34+ 
35+   .. versionchanged:: 2.6
36+      *timeout* was added.
37
38
39.. class:: POP3_SSL(host[, port[, keyfile[, certfile]]])
40
41   This is a subclass of :class:`POP3` that connects to the server over an SSL
42   encrypted socket.  If *port* is not specified, 995, the standard POP3-over-SSL
43   port is used.  *keyfile* and *certfile* are also optional - they can contain a
44   PEM formatted private key and certificate chain file for the SSL connection.
45
46   .. versionadded:: 2.4
47
48One exception is defined as an attribute of the :mod:`poplib` module:
49
50
51.. exception:: error_proto
52
n53-   Exception raised on any errors.  The reason for the exception is passed to the
n53+   Exception raised on any errors from this module (errors from :mod:`socket`
54+   module are not caught). The reason for the exception is passed to the
54   constructor as a string.
55
56
57.. seealso::
58
59   Module :mod:`imaplib`
60      The standard Python IMAP module.
61
71------------
72
73All POP3 commands are represented by methods of the same name, in lower-case;
74most return the response text sent by the server.
75
76An :class:`POP3` instance has the following methods:
77
78
n79-.. method:: XXX Class.set_debuglevel(level)
n80+.. method:: POP3.set_debuglevel(level)
80
81   Set the instance's debugging level.  This controls the amount of debugging
82   output printed.  The default, ``0``, produces no debugging output.  A value of
83   ``1`` produces a moderate amount of debugging output, generally a single line
84   per request.  A value of ``2`` or higher produces the maximum amount of
85   debugging output, logging each line sent and received on the control connection.
86
87
n88-.. method:: XXX Class.getwelcome()
n89+.. method:: POP3.getwelcome()
89
90   Returns the greeting string sent by the POP3 server.
91
92
n93-.. method:: XXX Class.user(username)
n94+.. method:: POP3.user(username)
94
95   Send user command, response should indicate that a password is required.
96
97
n98-.. method:: XXX Class.pass_(password)
n99+.. method:: POP3.pass_(password)
99
100   Send password, response includes message count and mailbox size. Note: the
101   mailbox on the server is locked until :meth:`quit` is called.
102
103
n104-.. method:: XXX Class.apop(user, secret)
n105+.. method:: POP3.apop(user, secret)
105
106   Use the more secure APOP authentication to log into the POP3 server.
107
108
n109-.. method:: XXX Class.rpop(user)
n110+.. method:: POP3.rpop(user)
110
111   Use RPOP authentication (similar to UNIX r-commands) to log into POP3 server.
112
113
n114-.. method:: XXX Class.stat()
n115+.. method:: POP3.stat()
115
116   Get mailbox status.  The result is a tuple of 2 integers: ``(message count,
117   mailbox size)``.
118
119
n120-.. method:: XXX Class.list([which])
n121+.. method:: POP3.list([which])
121
122   Request message list, result is in the form ``(response, ['mesg_num octets',
123   ...], octets)``. If *which* is set, it is the message to list.
124
125
n126-.. method:: XXX Class.retr(which)
n127+.. method:: POP3.retr(which)
127
128   Retrieve whole message number *which*, and set its seen flag. Result is in form
129   ``(response, ['line', ...], octets)``.
130
131
n132-.. method:: XXX Class.dele(which)
n133+.. method:: POP3.dele(which)
133
134   Flag message number *which* for deletion.  On most servers deletions are not
135   actually performed until QUIT (the major exception is Eudora QPOP, which
136   deliberately violates the RFCs by doing pending deletes on any disconnect).
137
138
n139-.. method:: XXX Class.rset()
n140+.. method:: POP3.rset()
140
141   Remove any deletion marks for the mailbox.
142
143
n144-.. method:: XXX Class.noop()
n145+.. method:: POP3.noop()
145
146   Do nothing.  Might be used as a keep-alive.
147
148
n149-.. method:: XXX Class.quit()
n150+.. method:: POP3.quit()
150
151   Signoff:  commit changes, unlock mailbox, drop connection.
152
153
n154-.. method:: XXX Class.top(which, howmuch)
n155+.. method:: POP3.top(which, howmuch)
155
156   Retrieves the message header plus *howmuch* lines of the message after the
157   header of message number *which*. Result is in form ``(response, ['line', ...],
158   octets)``.
159
160   The POP3 TOP command this method uses, unlike the RETR command, doesn't set the
161   message's seen flag; unfortunately, TOP is poorly specified in the RFCs and is
162   frequently broken in off-brand servers. Test this method by hand against the
163   POP3 servers you will use before trusting it.
164
165
t166-.. method:: XXX Class.uidl([which])
t167+.. method:: POP3.uidl([which])
167
168   Return message digest (unique id) list. If *which* is specified, result contains
169   the unique id for that message in the form ``'response mesgnum uid``, otherwise
170   result is list ``(response, ['mesgnum uid', ...], octets)``.
171
172Instances of :class:`POP3_SSL` have no additional methods. The interface of this
173subclass is identical to its parent.
174
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op