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) |
func) |
) |
) |
message_set, new_mailbox) |
mailbox) |
mailbox) |
) |
message_set, message_parts) |
mailbox) |
root) |
mailbox) |
[directory[, pattern]]) |
user, password) |
user, password) |
) |
[directory[, pattern]]) |
) |
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) |
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) |
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.