All IMAP4rev1 commands are represented by methods of the same name, either upper-case or lower-case.
All arguments to commands are converted to strings, except for
"AUTHENTICATE", and the last argument to "APPEND" which is
passed as an IMAP4 literal. If necessary (the string contains IMAP4
protocol-sensitive characters and isn't enclosed with either
parentheses or double quotes) each string is quoted. However, the
password argument to the "LOGIN" command is always quoted.
If you want to avoid having an argument string quoted
(eg: the flags argument to "STORE") then enclose the string in
Each command returns a tuple:
...]) where type is usually
and data is either the text from the command response, or
mandated results from the command. Each data
is either a string, or a tuple. If a tuple, then the first part
is the header of the response, and the second part contains
the data (ie: 'literal' value).
The message_set options to commands below is a string specifying one
or more messages to be acted upon. It may be a simple message number
'1'), a range of message numbers (
'2:4'), or a group of
non-contiguous ranges separated by commas (
'1:3,6:9'). A range
can contain an asterisk to indicate an infinite upper bound
An IMAP4 instance has the following methods:
|mailbox, flags, date_time, message)|
mechanism specifies which authentication mechanism is to be
used - it should appear in the instance variable
in the form
authobject must be a callable object:
data = authobject(response)
It will be called to process server continuation responses.
It should return
data that will be encoded and sent to server.
It should return
None if the client abort response "*" should
be sent instead.
|mailbox, entry, attribute)|
shutdownmethods. You may override this method.
|message_num, message_part, start, length)|
Noneif no new messages, else value of "RECENT" response.
None. Returns the given code, instead of the usual type.
|charset, criterion[, ...])|
None, in which case no "CHARSET" will be specified in the request to the server. The IMAP protocol requires that at least one criterion be specified; an exception will be raised when the server returns an error.
# M is a connected IMAP4 instance... typ, msgnums = M.search(None, 'FROM', '"LDJ"') # or: typ, msgnums = M.search(None, '(FROM "LDJ")')
'INBOX'. If the readonly flag is set, modifications to the mailbox are not allowed.
datato the remote server. You may override this method.
|mailbox, who, what)|
|mailbox, entry, attribute[, ...])|
open. You may override this method.
|sort_criteria, charset, search_criterion[, ...])|
sortcommand is a variant of
searchwith sorting semantics for the results. Returned data contains a space separated list of matching message numbers.
Sort has two arguments before the search_criterion
argument(s); a parenthesized list of sort_criteria, and the
searching charset. Note that unlike
searching charset argument is mandatory. There is also a
uid sort command which corresponds to
sort the way
uid search corresponds to
sort command first searches the mailbox for messages that
match the given searching criteria using the charset argument for
the interpretation of strings in the searching criteria. It then
returns the numbers of matching messages.
This is an "IMAP4rev1" extension command.
|message_set, command, flag_list)|
For example, to set the delete flag on all messages:
typ, data = M.search(None, 'ALL') for num in data.split(): M.store(num, '+FLAGS', '\\Deleted') M.expunge()
|threading_algorithm, charset, search_criterion[, ...])|
threadcommand is a variant of
searchwith threading semantics for the results. Returned data contains a space separated list of thread members.
Thread members consist of zero or more messages numbers, delimited by spaces, indicating successive parent and child.
Thread has two arguments before the search_criterion
argument(s); a threading_algorithm, and the searching
charset. Note that unlike
search, the searching
charset argument is mandatory. There is also a
thread command which corresponds to
thread the way that
uid search corresponds to
command first searches the mailbox for messages that match the given
searching criteria using the charset argument for the interpretation
of strings in the searching criteria. It then returns the matching
messages threaded according to the specified threading algorithm.
This is an "IMAP4rev1" extension command. New in version 2.4.
|command, arg[, ...])|
|name[, arg[, ...]])|
Instances of IMAP4_SSL have just one additional method:
The following attributes are defined on instances of IMAP4:
Debug. Values greater than three trace each command.
See About this document... for information on suggesting changes.