blob: 7c2fa459e516df6c54904c4e960e562c8f2448d5 [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{imaplib} ---
Fred Drakeb7745501999-04-22 16:46:18 +00002 IMAP4 protocol client}
3
Fred Drakeb91e9341998-07-23 17:59:49 +00004\declaremodule{standard}{imaplib}
Fred Drakeb7745501999-04-22 16:46:18 +00005\modulesynopsis{IMAP4 protocol client (requires sockets).}
Piers Lauderd3c821e2002-11-22 05:47:39 +00006\moduleauthor{Piers Lauder}{piers@communitysolutions.com.au}
7\sectionauthor{Piers Lauder}{piers@communitysolutions.com.au}
Fred Drakeb91e9341998-07-23 17:59:49 +00008
Piers Lauderd3c821e2002-11-22 05:47:39 +00009% Based on HTML documentation by Piers Lauder <piers@communitysolutions.com.au>;
Fred Drake38e5d272000-04-03 20:13:55 +000010% converted by Fred L. Drake, Jr. <fdrake@acm.org>.
Eric S. Raymond5ac97952001-01-11 04:19:52 +000011% Revised by ESR, January 2000.
Piers Laudera4f83132002-03-08 01:53:24 +000012% Changes for IMAP4_SSL by Tino Lange <Tino.Lange@isg.de>, March 2002
Piers Lauderd3c821e2002-11-22 05:47:39 +000013% Changes for IMAP4_stream by Piers Lauder <piers@communitysolutions.com.au>, November 2002
Fred Drake38e5d272000-04-03 20:13:55 +000014
Fred Drakee5cf53a1998-04-11 05:02:45 +000015\indexii{IMAP4}{protocol}
Piers Laudera4f83132002-03-08 01:53:24 +000016\indexii{IMAP4_SSL}{protocol}
Piers Lauderd3c821e2002-11-22 05:47:39 +000017\indexii{IMAP4_stream}{protocol}
Fred Drake89de3141998-04-11 04:19:04 +000018
Piers Lauderd3c821e2002-11-22 05:47:39 +000019This module defines three classes, \class{IMAP4}, \class{IMAP4_SSL} and \class{IMAP4_stream}, which encapsulate a
Piers Laudera4f83132002-03-08 01:53:24 +000020connection to an IMAP4 server and implement a large subset of the
Eric S. Raymond5ac97952001-01-11 04:19:52 +000021IMAP4rev1 client protocol as defined in \rfc{2060}. It is backward
22compatible with IMAP4 (\rfc{1730}) servers, but note that the
23\samp{STATUS} command is not supported in IMAP4.
Fred Drake89de3141998-04-11 04:19:04 +000024
Piers Lauderd3c821e2002-11-22 05:47:39 +000025Three classes are provided by the \module{imaplib} module, \class{IMAP4} is the base class:
Fred Drake89de3141998-04-11 04:19:04 +000026
27\begin{classdesc}{IMAP4}{\optional{host\optional{, port}}}
28This class implements the actual IMAP4 protocol. The connection is
29created and protocol version (IMAP4 or IMAP4rev1) is determined when
30the instance is initialized.
31If \var{host} is not specified, \code{''} (the local host) is used.
32If \var{port} is omitted, the standard IMAP4 port (143) is used.
33\end{classdesc}
34
Piers Lauderd3c821e2002-11-22 05:47:39 +000035Three exceptions are defined as attributes of the \class{IMAP4} class:
Fred Drake89de3141998-04-11 04:19:04 +000036
37\begin{excdesc}{IMAP4.error}
38Exception raised on any errors. The reason for the exception is
39passed to the constructor as a string.
40\end{excdesc}
41
42\begin{excdesc}{IMAP4.abort}
43IMAP4 server errors cause this exception to be raised. This is a
44sub-class of \exception{IMAP4.error}. Note that closing the instance
45and instantiating a new one will usually allow recovery from this
46exception.
47\end{excdesc}
48
Guido van Rossum5f7a28c1999-12-13 23:29:39 +000049\begin{excdesc}{IMAP4.readonly}
Thomas Woutersf8316632000-07-16 19:01:10 +000050This exception is raised when a writable mailbox has its status changed by the server. This is a
Guido van Rossum5f7a28c1999-12-13 23:29:39 +000051sub-class of \exception{IMAP4.error}. Some other client now has write permission,
52and the mailbox will need to be re-opened to re-obtain write permission.
53\end{excdesc}
54
Piers Laudera4f83132002-03-08 01:53:24 +000055There's also a subclass for secure connections:
56
57\begin{classdesc}{IMAP4_SSL}{\optional{host\optional{, port\optional{, keyfile\optional{, certfile}}}}}
58This is a subclass derived from \class{IMAP4} that connects over an SSL encrypted socket
59(to use this class you need a socket module that was compiled with SSL support).
60If \var{host} is not specified, \code{''} (the local host) is used.
61If \var{port} is omitted, the standard IMAP4-over-SSL port (993) is used.
62\var{keyfile} and \var{certfile} are also optional - they can contain a PEM formatted
63private key and certificate chain file for the SSL connection.
64\end{classdesc}
65
Piers Lauderd3c821e2002-11-22 05:47:39 +000066The second subclass allows for connections created by a child process:
67
68\begin{classdesc}{IMAP4_stream}{command}
69This is a subclass derived from \class{IMAP4} that connects
70to the \code{stdin/stdout} file descriptors created by passing \var{command} to \code{os.popen2()}.
Neal Norwitze1497982003-01-02 15:32:00 +000071\versionadded{2.3}
Piers Lauderd3c821e2002-11-22 05:47:39 +000072\end{classdesc}
73
Fred Drake89de3141998-04-11 04:19:04 +000074The following utility functions are defined:
75
76\begin{funcdesc}{Internaldate2tuple}{datestr}
77 Converts an IMAP4 INTERNALDATE string to Coordinated Universal
Fred Drakeb7745501999-04-22 16:46:18 +000078 Time. Returns a \refmodule{time} module tuple.
Fred Drake89de3141998-04-11 04:19:04 +000079\end{funcdesc}
80
81\begin{funcdesc}{Int2AP}{num}
82 Converts an integer into a string representation using characters
83 from the set [\code{A} .. \code{P}].
84\end{funcdesc}
85
86\begin{funcdesc}{ParseFlags}{flagstr}
87 Converts an IMAP4 \samp{FLAGS} response to a tuple of individual
88 flags.
89\end{funcdesc}
90
91\begin{funcdesc}{Time2Internaldate}{date_time}
Fred Drakeb7745501999-04-22 16:46:18 +000092 Converts a \refmodule{time} module tuple to an IMAP4
Fred Drake89de3141998-04-11 04:19:04 +000093 \samp{INTERNALDATE} representation. Returns a string in the form:
94 \code{"DD-Mmm-YYYY HH:MM:SS +HHMM"} (including double-quotes).
95\end{funcdesc}
96
97
Eric S. Raymond5ac97952001-01-11 04:19:52 +000098Note that IMAP4 message numbers change as the mailbox changes; in
99particular, after an \samp{EXPUNGE} command performs deletions the
100remaining messages are renumbered. So it is highly advisable to use
101UIDs instead, with the UID command.
Fred Drake363d67c1999-07-07 13:42:56 +0000102
103At the end of the module, there is a test section that contains a more
104extensive example of usage.
105
106\begin{seealso}
Fred Drake37f15741999-11-10 16:21:37 +0000107 \seetext{Documents describing the protocol, and sources and binaries
108 for servers implementing it, can all be found at the
109 University of Washington's \emph{IMAP Information Center}
110 (\url{http://www.cac.washington.edu/imap/}).}
Fred Drake363d67c1999-07-07 13:42:56 +0000111\end{seealso}
112
113
114\subsection{IMAP4 Objects \label{imap4-objects}}
Fred Drake89de3141998-04-11 04:19:04 +0000115
116All IMAP4rev1 commands are represented by methods of the same name,
117either upper-case or lower-case.
118
Guido van Rossum5f7a28c1999-12-13 23:29:39 +0000119All arguments to commands are converted to strings, except for
Fred Draked16b5ab1999-12-13 23:34:42 +0000120\samp{AUTHENTICATE}, and the last argument to \samp{APPEND} which is
121passed as an IMAP4 literal. If necessary (the string contains IMAP4
122protocol-sensitive characters and isn't enclosed with either
123parentheses or double quotes) each string is quoted. However, the
124\var{password} argument to the \samp{LOGIN} command is always quoted.
Fred Drake99d707a2000-05-26 04:08:37 +0000125If you want to avoid having an argument string quoted
126(eg: the \var{flags} argument to \samp{STORE}) then enclose the string in
127parentheses (eg: \code{r'(\e Deleted)'}).
Guido van Rossum5f7a28c1999-12-13 23:29:39 +0000128
Fred Drakeb7745501999-04-22 16:46:18 +0000129Each command returns a tuple: \code{(\var{type}, [\var{data},
130...])} where \var{type} is usually \code{'OK'} or \code{'NO'},
Fred Drake89de3141998-04-11 04:19:04 +0000131and \var{data} is either the text from the command response, or
Piers Lauderd3c821e2002-11-22 05:47:39 +0000132mandated results from the command. Each \var{data}
133is either a string, or a tuple. If a tuple, then the first part
134is the header of the response, and the second part contains
135the data (ie: 'literal' value).
Fred Drake89de3141998-04-11 04:19:04 +0000136
137An \class{IMAP4} instance has the following methods:
138
139
140\begin{methoddesc}{append}{mailbox, flags, date_time, message}
Piers Lauder8bc81fc2004-05-20 12:12:58 +0000141 Append \var{message} to named mailbox.
Fred Drake89de3141998-04-11 04:19:04 +0000142\end{methoddesc}
143
Piers Lauder8bc81fc2004-05-20 12:12:58 +0000144\begin{methoddesc}{authenticate}{mechanism, authobject}
145 Authenticate command --- requires response processing.
146
147 \var{mechanism} specifies which authentication mechanism is to
148 be used - it should appear in the instance variable \code{capabilities} in the
149 form \code{AUTH=mechanism}.
150
151 \var{authobject} must be a callable object:
152
153\begin{verbatim}
154data = authobject(response)
155\end{verbatim}
156
157 It will be called to process server continuation responses.
158 It should return \code{data} that will be encoded and sent to server.
159 It should return \code{None} if the client abort response \samp{*} should
160 be sent instead.
Fred Drake89de3141998-04-11 04:19:04 +0000161\end{methoddesc}
162
163\begin{methoddesc}{check}{}
164 Checkpoint mailbox on server.
165\end{methoddesc}
166
167\begin{methoddesc}{close}{}
168 Close currently selected mailbox. Deleted messages are removed from
169 writable mailbox. This is the recommended command before
170 \samp{LOGOUT}.
171\end{methoddesc}
172
173\begin{methoddesc}{copy}{message_set, new_mailbox}
174 Copy \var{message_set} messages onto end of \var{new_mailbox}.
175\end{methoddesc}
176
177\begin{methoddesc}{create}{mailbox}
178 Create new mailbox named \var{mailbox}.
179\end{methoddesc}
180
181\begin{methoddesc}{delete}{mailbox}
182 Delete old mailbox named \var{mailbox}.
183\end{methoddesc}
184
Martin v. Löwis7b9190b2004-07-27 05:07:19 +0000185\begin{methoddesc}{deleteacl}{mailbox, who}
186 Delete the ACLs (remove any rights) set for who on mailbox.
Neal Norwitzbee41742004-07-28 02:34:12 +0000187\versionadded{2.4}
Martin v. Löwis7b9190b2004-07-27 05:07:19 +0000188\end{methoddesc}
189
Fred Drake89de3141998-04-11 04:19:04 +0000190\begin{methoddesc}{expunge}{}
191 Permanently remove deleted items from selected mailbox. Generates an
192 \samp{EXPUNGE} response for each deleted message. Returned data
193 contains a list of \samp{EXPUNGE} message numbers in order
194 received.
195\end{methoddesc}
196
197\begin{methoddesc}{fetch}{message_set, message_parts}
Fred Drake99d707a2000-05-26 04:08:37 +0000198 Fetch (parts of) messages. \var{message_parts} should be
199 a string of message part names enclosed within parentheses,
200 eg: \samp{"(UID BODY[TEXT])"}. Returned data are tuples
201 of message part envelope and data.
Fred Drake89de3141998-04-11 04:19:04 +0000202\end{methoddesc}
203
Piers Laudera3a16682001-07-20 11:04:19 +0000204\begin{methoddesc}{getacl}{mailbox}
205 Get the \samp{ACL}s for \var{mailbox}.
206 The method is non-standard, but is supported by the \samp{Cyrus} server.
207\end{methoddesc}
208
Piers Lauder3fca2912002-06-17 07:07:20 +0000209\begin{methoddesc}{getquota}{root}
210 Get the \samp{quota} \var{root}'s resource usage and limits.
211 This method is part of the IMAP4 QUOTA extension defined in rfc2087.
Neal Norwitz1cfcafc2002-07-20 00:46:12 +0000212\versionadded{2.3}
Piers Lauder3fca2912002-06-17 07:07:20 +0000213\end{methoddesc}
214
215\begin{methoddesc}{getquotaroot}{mailbox}
216 Get the list of \samp{quota} \samp{roots} for the named \var{mailbox}.
217 This method is part of the IMAP4 QUOTA extension defined in rfc2087.
Neal Norwitz1cfcafc2002-07-20 00:46:12 +0000218\versionadded{2.3}
Piers Lauder3fca2912002-06-17 07:07:20 +0000219\end{methoddesc}
220
Fred Drakee5cf53a1998-04-11 05:02:45 +0000221\begin{methoddesc}{list}{\optional{directory\optional{, pattern}}}
222 List mailbox names in \var{directory} matching
223 \var{pattern}. \var{directory} defaults to the top-level mail
224 folder, and \var{pattern} defaults to match anything. Returned data
225 contains a list of \samp{LIST} responses.
Fred Drake89de3141998-04-11 04:19:04 +0000226\end{methoddesc}
227
228\begin{methoddesc}{login}{user, password}
229 Identify the client using a plaintext password.
Guido van Rossum5f7a28c1999-12-13 23:29:39 +0000230 The \var{password} will be quoted.
Fred Drake89de3141998-04-11 04:19:04 +0000231\end{methoddesc}
232
Piers Lauderd3c821e2002-11-22 05:47:39 +0000233\begin{methoddesc}{login_cram_md5}{user, password}
234 Force use of \samp{CRAM-MD5} authentication when identifying the client to protect the password.
235 Will only work if the server \samp{CAPABILITY} response includes the phrase \samp{AUTH=CRAM-MD5}.
Neal Norwitze1497982003-01-02 15:32:00 +0000236\versionadded{2.3}
Piers Lauderd3c821e2002-11-22 05:47:39 +0000237\end{methoddesc}
238
Fred Drake89de3141998-04-11 04:19:04 +0000239\begin{methoddesc}{logout}{}
240 Shutdown connection to server. Returns server \samp{BYE} response.
241\end{methoddesc}
242
Fred Drakee5cf53a1998-04-11 05:02:45 +0000243\begin{methoddesc}{lsub}{\optional{directory\optional{, pattern}}}
244 List subscribed mailbox names in directory matching pattern.
245 \var{directory} defaults to the top level directory and
246 \var{pattern} defaults to match any mailbox.
247 Returned data are tuples of message part envelope and data.
Fred Drake89de3141998-04-11 04:19:04 +0000248\end{methoddesc}
249
Martin v. Löwis7b9190b2004-07-27 05:07:19 +0000250\begin{methoddes}{myrights}{mailbox}
251 Show my ACLs for a mailbox (i.e. the rights that I have on mailbox).
Neal Norwitzbee41742004-07-28 02:34:12 +0000252\versionadded{2.4}
Martin v. Löwis7b9190b2004-07-27 05:07:19 +0000253\end{methoddesc}
254
Piers Lauder8bc81fc2004-05-20 12:12:58 +0000255\begin{methoddesc}{namespace}{}
256 Returns IMAP namespaces as defined in RFC2342.
257\versionadded{2.3}
258\end{methoddesc}
259
Guido van Rossum5f7a28c1999-12-13 23:29:39 +0000260\begin{methoddesc}{noop}{}
Fred Draked16b5ab1999-12-13 23:34:42 +0000261 Send \samp{NOOP} to server.
Guido van Rossum5f7a28c1999-12-13 23:29:39 +0000262\end{methoddesc}
263
264\begin{methoddesc}{open}{host, port}
265 Opens socket to \var{port} at \var{host}.
Piers Laudera3a16682001-07-20 11:04:19 +0000266 The connection objects established by this method
Piers Lauder3fca2912002-06-17 07:07:20 +0000267 will be used in the \code{read}, \code{readline}, \code{send}, and \code{shutdown} methods.
Guido van Rossum5f7a28c1999-12-13 23:29:39 +0000268 You may override this method.
269\end{methoddesc}
270
271\begin{methoddesc}{partial}{message_num, message_part, start, length}
272 Fetch truncated part of a message.
273 Returned data is a tuple of message part envelope and data.
274\end{methoddesc}
275
Piers Lauderd3c821e2002-11-22 05:47:39 +0000276\begin{methoddesc}{proxyauth}{user}
277 Assume authentication as \var{user}.
278 Allows an authorised administrator to proxy into any user's mailbox.
Neal Norwitze1497982003-01-02 15:32:00 +0000279\versionadded{2.3}
Piers Lauderd3c821e2002-11-22 05:47:39 +0000280\end{methoddesc}
281
Piers Laudera3a16682001-07-20 11:04:19 +0000282\begin{methoddesc}{read}{size}
283 Reads \var{size} bytes from the remote server.
284 You may override this method.
285\end{methoddesc}
286
287\begin{methoddesc}{readline}{}
288 Reads one line from the remote server.
289 You may override this method.
290\end{methoddesc}
291
Fred Drake89de3141998-04-11 04:19:04 +0000292\begin{methoddesc}{recent}{}
293 Prompt server for an update. Returned data is \code{None} if no new
294 messages, else value of \samp{RECENT} response.
295\end{methoddesc}
296
297\begin{methoddesc}{rename}{oldmailbox, newmailbox}
298 Rename mailbox named \var{oldmailbox} to \var{newmailbox}.
299\end{methoddesc}
300
301\begin{methoddesc}{response}{code}
302 Return data for response \var{code} if received, or
303 \code{None}. Returns the given code, instead of the usual type.
304\end{methoddesc}
305
Martin v. Löwis3ae0f7a2003-03-27 16:59:38 +0000306\begin{methoddesc}{search}{charset, criterion\optional{, ...}}
Fred Drake99d707a2000-05-26 04:08:37 +0000307 Search mailbox for matching messages. Returned data contains a space
308 separated list of matching message numbers. \var{charset} may be
309 \code{None}, in which case no \samp{CHARSET} will be specified in the
310 request to the server. The IMAP protocol requires that at least one
Martin v. Löwis3ae0f7a2003-03-27 16:59:38 +0000311 criterion be specified; an exception will be raised when the server
Fred Drake99d707a2000-05-26 04:08:37 +0000312 returns an error.
313
314 Example:
315
316\begin{verbatim}
317# M is a connected IMAP4 instance...
318msgnums = M.search(None, 'FROM', '"LDJ"')
319
320# or:
321msgnums = M.search(None, '(FROM "LDJ")')
322\end{verbatim}
Fred Drake89de3141998-04-11 04:19:04 +0000323\end{methoddesc}
324
325\begin{methoddesc}{select}{\optional{mailbox\optional{, readonly}}}
326 Select a mailbox. Returned data is the count of messages in
327 \var{mailbox} (\samp{EXISTS} response). The default \var{mailbox}
328 is \code{'INBOX'}. If the \var{readonly} flag is set, modifications
329 to the mailbox are not allowed.
330\end{methoddesc}
331
Piers Lauder3fca2912002-06-17 07:07:20 +0000332\begin{methoddesc}{send}{data}
333 Sends \code{data} to the remote server.
334 You may override this method.
335\end{methoddesc}
336
Piers Laudera3a16682001-07-20 11:04:19 +0000337\begin{methoddesc}{setacl}{mailbox, who, what}
338 Set an \samp{ACL} for \var{mailbox}.
339 The method is non-standard, but is supported by the \samp{Cyrus} server.
340\end{methoddesc}
341
Piers Lauder3fca2912002-06-17 07:07:20 +0000342\begin{methoddesc}{setquota}{root, limits}
343 Set the \samp{quota} \var{root}'s resource \var{limits}.
344 This method is part of the IMAP4 QUOTA extension defined in rfc2087.
Neal Norwitz1cfcafc2002-07-20 00:46:12 +0000345\versionadded{2.3}
Piers Lauder3fca2912002-06-17 07:07:20 +0000346\end{methoddesc}
347
Piers Laudera3a16682001-07-20 11:04:19 +0000348\begin{methoddesc}{shutdown}{}
349 Close connection established in \code{open}.
350 You may override this method.
351\end{methoddesc}
352
Guido van Rossum5f7a28c1999-12-13 23:29:39 +0000353\begin{methoddesc}{socket}{}
Piers Laudera3a16682001-07-20 11:04:19 +0000354 Returns socket instance used to connect to server.
355\end{methoddesc}
356
Martin v. Löwis3ae0f7a2003-03-27 16:59:38 +0000357\begin{methoddesc}{sort}{sort_criteria, charset, search_criterion\optional{, ...}}
Piers Laudera3a16682001-07-20 11:04:19 +0000358 The \code{sort} command is a variant of \code{search} with sorting semantics for
359 the results. Returned data contains a space
360 separated list of matching message numbers.
361
Martin v. Löwis3ae0f7a2003-03-27 16:59:38 +0000362 Sort has two arguments before the \var{search_criterion}
Piers Laudera3a16682001-07-20 11:04:19 +0000363 argument(s); a parenthesized list of \var{sort_criteria}, and the searching \var{charset}.
364 Note that unlike \code{search}, the searching \var{charset} argument is mandatory.
365 There is also a \code{uid sort} command which corresponds to \code{sort} the way
366 that \code{uid search} corresponds to \code{search}.
367 The \code{sort} command first searches the mailbox for messages that
368 match the given searching criteria using the charset argument for
369 the interpretation of strings in the searching criteria. It then
370 returns the numbers of matching messages.
371
372 This is an \samp{IMAP4rev1} extension command.
Guido van Rossum5f7a28c1999-12-13 23:29:39 +0000373\end{methoddesc}
374
Fred Drake89de3141998-04-11 04:19:04 +0000375\begin{methoddesc}{status}{mailbox, names}
376 Request named status conditions for \var{mailbox}.
377\end{methoddesc}
378
379\begin{methoddesc}{store}{message_set, command, flag_list}
380 Alters flag dispositions for messages in mailbox.
381\end{methoddesc}
382
383\begin{methoddesc}{subscribe}{mailbox}
384 Subscribe to new mailbox.
385\end{methoddesc}
386
Martin v. Löwisd8921372003-11-10 06:44:44 +0000387\begin{methoddesc}{thread}{threading_algorithm, charset, search_criterion\optional{, ...}}
388 The \code{thread} command is a variant of \code{search} with threading semantics for
389 the results. Returned data contains a space
390 separated list of thread members.
391
392 Thread members consist of zero or more messages numbers, delimited by spaces,
393 indicating successive parent and child.
394
395 Thread has two arguments before the \var{search_criterion}
396 argument(s); a \var{threading_algorithm}, and the searching \var{charset}.
397 Note that unlike \code{search}, the searching \var{charset} argument is mandatory.
398 There is also a \code{uid thread} command which corresponds to \code{thread} the way
399 that \code{uid search} corresponds to \code{search}.
400 The \code{thread} command first searches the mailbox for messages that
401 match the given searching criteria using the charset argument for
402 the interpretation of strings in the searching criteria. It thren
403 returns the matching messages threaded according to the specified
404 threading algorithm.
405
406 This is an \samp{IMAP4rev1} extension command. \versionadded{2.4}
407\end{methoddesc}
408
Fred Drake99d707a2000-05-26 04:08:37 +0000409\begin{methoddesc}{uid}{command, arg\optional{, ...}}
Fred Drake89de3141998-04-11 04:19:04 +0000410 Execute command args with messages identified by UID, rather than
Fred Drake99d707a2000-05-26 04:08:37 +0000411 message number. Returns response appropriate to command. At least
412 one argument must be supplied; if none are provided, the server will
413 return an error and an exception will be raised.
Fred Drake89de3141998-04-11 04:19:04 +0000414\end{methoddesc}
415
416\begin{methoddesc}{unsubscribe}{mailbox}
417 Unsubscribe from old mailbox.
418\end{methoddesc}
419
Fred Drake99d707a2000-05-26 04:08:37 +0000420\begin{methoddesc}{xatom}{name\optional{, arg\optional{, ...}}}
Fred Drake89de3141998-04-11 04:19:04 +0000421 Allow simple extension commands notified by server in
422 \samp{CAPABILITY} response.
423\end{methoddesc}
424
425
Piers Laudera4f83132002-03-08 01:53:24 +0000426Instances of \class{IMAP4_SSL} have just one additional method:
427
428\begin{methoddesc}{ssl}{}
429 Returns SSLObject instance used for the secure connection with the server.
430\end{methoddesc}
431
432
Fred Drake8f6b9581998-04-11 15:11:55 +0000433The following attributes are defined on instances of \class{IMAP4}:
Fred Drake89de3141998-04-11 04:19:04 +0000434
Fred Drake8f6b9581998-04-11 15:11:55 +0000435
436\begin{memberdesc}{PROTOCOL_VERSION}
Fred Drakeb7745501999-04-22 16:46:18 +0000437The most recent supported protocol in the
438\samp{CAPABILITY} response from the server.
Fred Drake8f6b9581998-04-11 15:11:55 +0000439\end{memberdesc}
440
441\begin{memberdesc}{debug}
442Integer value to control debugging output. The initialize value is
443taken from the module variable \code{Debug}. Values greater than
444three trace each command.
445\end{memberdesc}
Fred Drake89de3141998-04-11 04:19:04 +0000446
447
Fred Drake363d67c1999-07-07 13:42:56 +0000448\subsection{IMAP4 Example \label{imap4-example}}
Fred Drake89de3141998-04-11 04:19:04 +0000449
450Here is a minimal example (without error checking) that opens a
451mailbox and retrieves and prints all messages:
452
453\begin{verbatim}
Piers Laudera3a16682001-07-20 11:04:19 +0000454import getpass, imaplib
Fred Drake363d67c1999-07-07 13:42:56 +0000455
Fred Drake89de3141998-04-11 04:19:04 +0000456M = imaplib.IMAP4()
Fred Drake363d67c1999-07-07 13:42:56 +0000457M.login(getpass.getuser(), getpass.getpass())
458M.select()
459typ, data = M.search(None, 'ALL')
Piers Laudera3a16682001-07-20 11:04:19 +0000460for num in data[0].split():
Fred Drake363d67c1999-07-07 13:42:56 +0000461 typ, data = M.fetch(num, '(RFC822)')
Fred Drake89de3141998-04-11 04:19:04 +0000462 print 'Message %s\n%s\n' % (num, data[0][1])
Fred Drake363d67c1999-07-07 13:42:56 +0000463M.logout()
Fred Drake89de3141998-04-11 04:19:04 +0000464\end{verbatim}