blob: 2c21a7fdf4645149080775347588e062822cad87 [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
6\section{Standard Module \module{poplib}}
Fred Drakeb91e9341998-07-23 17:59:49 +00007\declaremodule{standard}{poplib}
8
9\modulesynopsis{POP3 protocol client (requires sockets).}
10
Fred Drakea4684041998-04-24 20:49:02 +000011\indexii{POP3}{protocol}
12
13This module defines a class, \class{POP3}, which encapsulates a
14connection to an POP3 server and implements protocol as defined in
15\rfc{1725}. The \class{POP3} class supports both the minmal and
16optional command sets.
17
18A single class is provided by the \module{poplib} module:
19
20\begin{classdesc}{POP3}{host\optional{, port}}
21This class implements the actual POP3 protocol. The connection is
22created when the instance is initialized.
23If \var{port} is omitted, the standard POP3 port (110) is used.
24\end{classdesc}
25
26One exception is defined as attributes of the \module{poplib} module:
27
28\begin{excdesc}{error_proto}
29Exception raised on any errors. The reason for the exception is
30passed to the constructor as a string.
31\end{excdesc}
32
33
34\subsection{POP3 Objects}
35\label{pop3-objects}
36
37All POP3 commands are represented by methods of the same name,
38in lower-case.
39
40Most commands return the response text sent by the server.
41
42An \class{POP3} instance has the following methods:
43
44
45\begin{methoddesc}{getwelcome}{}
46Returns the greeting string sent by the POP3 server.
47\end{methoddesc}
48
49
50\begin{methoddesc}{user}{username}
51Send user commad, response should indicate that a password is required.
52\end{methoddesc}
53
54\begin{methoddesc}{pass_}{password}
55Send password, response includes message count and mailbox size.
56Note: the mailbox on the server is locked until \method{quit()} is
57called.
58\end{methoddesc}
59
60\begin{methoddesc}{apop}{user, secret}
61Use the more secure APOP authentication to log into the POP3 server.
62\end{methoddesc}
63
64\begin{methoddesc}{rpop}{user}
65Use RPOP authentication (similar to UNIX r-commands) to log into POP3 server.
66\end{methoddesc}
67
68\begin{methoddesc}{stat}{}
69Get mailbox status. The result is a tuple of 2 integers:
70\code{(\var{message count}, \var{mailbox size})}.
71\end{methoddesc}
72
73\begin{methoddesc}{list}{\optional{which}}
74Request message list, result is in the form
75\code{['response', ['mesg_num octets', ...]]}. If \var{which} is
76set, it is the message to list.
77\end{methoddesc}
78
79\begin{methoddesc}{retr}{which}
80Retrieve whole message number \var{which}. Result is in form
81\code{['response', ['line', ...], octets]}.
82\end{methoddesc}
83
84\begin{methoddesc}{dele}{which}
85Delete message number \var{which}.
86\end{methoddesc}
87
88\begin{methoddesc}{rset}{}
89Remove any deletion marks for the mailbox.
90\end{methoddesc}
91
92\begin{methoddesc}{noop}{}
93Do nothing. Might be used as a keep-alive.
94\end{methoddesc}
95
96\begin{methoddesc}{quit}{}
97Signoff: commit changes, unlock mailbox, drop connection.
98\end{methoddesc}
99
100\begin{methoddesc}{top}{which, howmuch}
101Retrieves the message header plus \var{howmuch} lines of the message
102after the header of message number \var{which}. Result is in form
103\code{['response', ['line', ...], octets]}.
104\end{methoddesc}
105
106\begin{methoddesc}{uidl}{\optional{which}}
107Return message digest (unique id) list.
108If \var{which} is specified, result contains unique id for that
109message, otherwise result is list \code{['response',
110['mesgnum uid', ...], octets]}.
111\end{methoddesc}
112
113
114\subsection{POP3 Example}
115\label{pop3-example}
116
117Here is a minimal example (without error checking) that opens a
118mailbox and retrieves and prints all messages:
119
120\begin{verbatim}
121import getpass, poplib, string
122
123M = poplib.POP3('localhost')
124M.user(getpass.getuser())
125M.pass(getpass.getpass())
126numMessages = len(M.list()[1])
127for i in range(numMessages):
128 for j in M.retr(i+1)[1]:
129 sys.stdout.write(j)
130\end{verbatim}
131
132At the end of the module, there is a test section that contains a more
133extensive example of usage.