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
parentheses (eg: r'(\Deleted)'
).
Each command returns a tuple: (type, [data,
...])
where type is usually 'OK'
or 'NO'
,
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
('3:*'
).
An IMAP4 instance has the following methods:
mailbox, flags, date_time, message) |
mechanism, authobject) |
mechanism specifies which authentication mechanism is to be
used - it should appear in the instance variable capabilities
in the form AUTH=mechanism
.
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.
) |
) |
message_set, new_mailbox) |
mailbox) |
mailbox) |
mailbox, who) |
) |
message_set, message_parts) |
mailbox) |
mailbox, entry, attribute) |
root) |
mailbox) |
[directory[, pattern]]) |
user, password) |
user, password) |
) |
[directory[, pattern]]) |
mailbox) |
) |
) |
host, port) |
read
, readline
, send
, and
shutdown
methods.
You may override this method.
message_num, message_part, start, length) |
user) |
size) |
) |
) |
None
if no new
messages, else value of "RECENT" response.
oldmailbox, newmailbox) |
code) |
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.
Example:
# M is a connected IMAP4 instance... msgnums = M.search(None, 'FROM', '"LDJ"') # or: msgnums = M.search(None, '(FROM "LDJ")')
[mailbox[, readonly]]) |
'INBOX'
. If the readonly flag is set, modifications
to the mailbox are not allowed.
data) |
data
to the remote server.
You may override this method.
mailbox, who, what) |
mailbox, entry, attribute[, ...]) |
root, limits) |
) |
open
.
You may override this method.
) |
sort_criteria, charset, search_criterion[, ...]) |
sort
command is a variant of search
with 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 search
, the
searching charset argument is mandatory. There is also a
uid sort
command which corresponds to sort
the way
that uid search
corresponds to search
. The
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.
mailbox, names) |
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[0].split(): M.store(num, '+FLAGS', '\\Deleted') M.expunge()
mailbox) |
threading_algorithm, charset, search_criterion[, ...]) |
thread
command is a variant of search
with
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 uid
thread
command which corresponds to thread
the way that
uid search
corresponds to search
. The thread
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[, ...]) |
mailbox) |
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.