blob: fc73a31b059cbf27f8a81ad10c20ccdcaa880a8f [file] [log] [blame]
Fred Drakea4684041998-04-24 20:49:02 +00001%By Andrew T. Csillag
2%Even though I put it into LaTeX, I cannot really claim that I wrote
3%it since I just stole most of it from the poplib.py source code and
4%the imaplib ``chapter''.
5
Fred Drake295da241998-08-10 19:42:37 +00006\section{\module{poplib} ---
Fred Drakee2effbd1999-04-22 16:21:09 +00007 POP3 protocol client}
Fred Drakeb91e9341998-07-23 17:59:49 +00008
Fred Drakee2effbd1999-04-22 16:21:09 +00009\declaremodule{standard}{poplib}
Fred Drakeb91e9341998-07-23 17:59:49 +000010\modulesynopsis{POP3 protocol client (requires sockets).}
11
Fred Drakea4684041998-04-24 20:49:02 +000012\indexii{POP3}{protocol}
13
14This module defines a class, \class{POP3}, which encapsulates a
15connection to an POP3 server and implements protocol as defined in
16\rfc{1725}. The \class{POP3} class supports both the minmal and
17optional command sets.
18
19A single class is provided by the \module{poplib} module:
20
21\begin{classdesc}{POP3}{host\optional{, port}}
22This class implements the actual POP3 protocol. The connection is
23created when the instance is initialized.
24If \var{port} is omitted, the standard POP3 port (110) is used.
25\end{classdesc}
26
Fred Drakee2effbd1999-04-22 16:21:09 +000027One exception is defined as an attribute of the \module{poplib} module:
Fred Drakea4684041998-04-24 20:49:02 +000028
29\begin{excdesc}{error_proto}
30Exception raised on any errors. The reason for the exception is
31passed to the constructor as a string.
32\end{excdesc}
33
34
Fred Drakee2effbd1999-04-22 16:21:09 +000035\subsection{POP3 Objects \label{pop3-objects}}
Fred Drakea4684041998-04-24 20:49:02 +000036
37All POP3 commands are represented by methods of the same name,
Fred Drakee2effbd1999-04-22 16:21:09 +000038in lower-case; most return the response text sent by the server.
Fred Drakea4684041998-04-24 20:49:02 +000039
40An \class{POP3} instance has the following methods:
41
42
43\begin{methoddesc}{getwelcome}{}
44Returns the greeting string sent by the POP3 server.
45\end{methoddesc}
46
47
48\begin{methoddesc}{user}{username}
49Send user commad, response should indicate that a password is required.
50\end{methoddesc}
51
52\begin{methoddesc}{pass_}{password}
53Send password, response includes message count and mailbox size.
54Note: the mailbox on the server is locked until \method{quit()} is
55called.
56\end{methoddesc}
57
58\begin{methoddesc}{apop}{user, secret}
59Use the more secure APOP authentication to log into the POP3 server.
60\end{methoddesc}
61
62\begin{methoddesc}{rpop}{user}
63Use RPOP authentication (similar to UNIX r-commands) to log into POP3 server.
64\end{methoddesc}
65
66\begin{methoddesc}{stat}{}
67Get mailbox status. The result is a tuple of 2 integers:
68\code{(\var{message count}, \var{mailbox size})}.
69\end{methoddesc}
70
71\begin{methoddesc}{list}{\optional{which}}
72Request message list, result is in the form
Fred Drake3a4ceb71999-07-07 14:04:38 +000073\code{(\var{response}, ['mesg_num octets', ...])}. If \var{which} is
Fred Drakea4684041998-04-24 20:49:02 +000074set, it is the message to list.
75\end{methoddesc}
76
77\begin{methoddesc}{retr}{which}
78Retrieve whole message number \var{which}. Result is in form
Fred Drake3a4ceb71999-07-07 14:04:38 +000079\code{(\var{response}, ['line', ...], \var{octets})}.
Fred Drakea4684041998-04-24 20:49:02 +000080\end{methoddesc}
81
82\begin{methoddesc}{dele}{which}
83Delete message number \var{which}.
84\end{methoddesc}
85
86\begin{methoddesc}{rset}{}
87Remove any deletion marks for the mailbox.
88\end{methoddesc}
89
90\begin{methoddesc}{noop}{}
91Do nothing. Might be used as a keep-alive.
92\end{methoddesc}
93
94\begin{methoddesc}{quit}{}
95Signoff: commit changes, unlock mailbox, drop connection.
96\end{methoddesc}
97
98\begin{methoddesc}{top}{which, howmuch}
99Retrieves the message header plus \var{howmuch} lines of the message
100after the header of message number \var{which}. Result is in form
Fred Drake3a4ceb71999-07-07 14:04:38 +0000101\code{(\var{response}, ['line', ...], \var{octets})}.
Fred Drakea4684041998-04-24 20:49:02 +0000102\end{methoddesc}
103
104\begin{methoddesc}{uidl}{\optional{which}}
105Return message digest (unique id) list.
Fred Drakedbc2d081999-05-13 18:48:14 +0000106If \var{which} is specified, result contains the unique id for that
107message in the form \code{'\var{response}\ \var{mesgnum}\ \var{uid}},
Fred Drake3a4ceb71999-07-07 14:04:38 +0000108otherwise result is list \code{(\var{response}, ['mesgnum uid', ...],
109\var{octets})}.
Fred Drakea4684041998-04-24 20:49:02 +0000110\end{methoddesc}
111
112
Fred Drakee2effbd1999-04-22 16:21:09 +0000113\subsection{POP3 Example \label{pop3-example}}
Fred Drakea4684041998-04-24 20:49:02 +0000114
115Here is a minimal example (without error checking) that opens a
116mailbox and retrieves and prints all messages:
117
118\begin{verbatim}
Guido van Rossumaac399b1998-12-08 16:30:10 +0000119import getpass, poplib
Fred Drakea4684041998-04-24 20:49:02 +0000120
121M = poplib.POP3('localhost')
122M.user(getpass.getuser())
Guido van Rossumaac399b1998-12-08 16:30:10 +0000123M.pass_(getpass.getpass())
Fred Drakea4684041998-04-24 20:49:02 +0000124numMessages = len(M.list()[1])
125for i in range(numMessages):
126 for j in M.retr(i+1)[1]:
Guido van Rossumaac399b1998-12-08 16:30:10 +0000127 print j
Fred Drakea4684041998-04-24 20:49:02 +0000128\end{verbatim}
129
130At the end of the module, there is a test section that contains a more
131extensive example of usage.