IMAP4 client class.
host - host's name (default: localhost); port - port number (default: standard IMAP4 port).
All IMAP4rev1 commands are supported by methods of the same name (in 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 any
non-printing characters or white-space 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: "(\Deleted)").
Each command returns a tuple: (type, [data, ...]) where type
is usually OK
or NO
, and data
is either the text from the
tagged response, or untagged results from 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).
Errors raise the exception class error
. Mailbox status changes
from READ-WRITE to READ-ONLY raise the exception class
abort
.
"error" exceptions imply a program error. "abort" exceptions imply the connection should be reset, and the command re-tried. "readonly" exceptions imply the command should be re-tried.
Note: to use this module, you must read the RFCs pertaining to the IMAP4 protocol, as the semantics of the arguments to each IMAP4 command are left to the invoker, not to mention the results.
There are no base classes.
There are no implemented interfaces.
abort
(type: classobj
)
<class imaplib.abort at 0x407330bc>
error
(type: classobj
)
<class imaplib.error at 0x4073308c>
mustquote
(type: SRE_Pattern
)
<_sre.SRE_Pattern object at 0x409b4cb8>
readonly
(type: classobj
)
<class imaplib.readonly at 0x407330ec>
append(mailbox, flags, date_time, message)
Append message to named mailbox.
All args except `message' can be None.
authenticate(mechanism, authobject)
Authenticate command - requires response processing.
mechanism
specifies which authentication mechanism is to
be used - it must appear in
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.
check()
Checkpoint mailbox on server.
(typ, [data]) =
close()
Close currently selected mailbox.
Deleted messages are removed from writable mailbox.
This is the recommended command before LOGOUT
.
(typ, [data]) =
copy(message_set, new_mailbox)
Copy message_set
messages onto end of new_mailbox
.
(typ, [data]) =
create(mailbox)
Create new mailbox.
(typ, [data]) =
delete(mailbox)
Delete old mailbox.
(typ, [data]) =
deleteacl(mailbox, who)
Delete the ACLs (remove any rights) set for who on mailbox.
(typ, [data]) =
expunge()
Permanently remove deleted items from selected mailbox.
Generates EXPUNGE
response for each deleted message.
(typ, [data]) =
data
is list of 'EXPUNGE'd message numbers in order received.
fetch(message_set, message_parts)
Fetch (parts of) messages.
(typ, [data, ...]) =
message_parts
should be a string of selected parts
enclosed in parentheses, eg: "(UID BODY[TEXT])".
data
are tuples of message part envelope and data.
getacl(mailbox)
Get the ACLs for a mailbox.
(typ, [data]) =
getquota(root)
Get the quota root's resource usage and limits.
Part of the IMAP4 QUOTA extension defined in rfc2087.
(typ, [data]) =
getquotaroot(mailbox)
Get the list of quota roots for the named mailbox.
(typ, [[QUOTAROOT responses...], [QUOTA responses]]) =
list(directory='""', pattern='*')
List mailbox names in directory matching pattern.
(typ, [data]) = ""
, pattern=*
)
data
is list of LIST responses.
login(user, password)
Identify client using plaintext password.
(typ, [data]) =
NB: password
will be quoted.
login_cram_md5(user, password)
Force use of CRAM-MD5 authentication.
(typ, [data]) =
logout()
lsub(directory='""', pattern='*')
List subscribed
mailbox names in directory matching pattern.
(typ, [data, ...]) = ""
, pattern=*
)
data
are tuples of message part envelope and data.
myrights(mailbox)
Show my ACLs for a mailbox (i.e. the rights that I have on mailbox).
(typ, [data]) =
namespace()
Returns IMAP namespaces ala rfc2342
(typ, [data, ...]) =
noop()
Send NOOP command.
(typ, [data]) =
open(host='', port=143)
Setup connection to remote server on "host:port" (default: localhost:standard IMAP4 port). This connection will be used by the routines: read, readline, send, shutdown.
partial(message_num, message_part, start, length)
Fetch truncated part of a message.
(typ, [data, ...]) =
data
is tuple of message part envelope and data.
print_log()
proxyauth(user)
Assume authentication as "user".
Allows an authorised administrator to proxy into any user's mailbox.
(typ, [data]) =
read(size)
Read size
bytes from remote.
readline()
Read line from remote.
recent()
Return most recent RECENT
responses if any exist,
else prompt server for an update using the NOOP
command.
(typ, [data]) =
data
is None if no new messages,
else list of RECENT responses, most recent last.
rename(oldmailbox, newmailbox)
Rename old mailbox name to new.
(typ, [data]) =
response(code)
Return data for response code
if received, or None.
Old value for response code
is cleared.
(code, [data]) =
search(charset, *criteria)
Search mailbox for matching messages.
(typ, [data]) =
data
is space separated list of matching message numbers.
select(mailbox='INBOX', readonly=None)
Select a mailbox.
Flush all untagged responses.
(typ, [data]) = INBOX
, readonly=None)
data
is count of messages in mailbox (EXISTS
response).
Mandated responses are (FLAGS
, EXISTS
, RECENT
, UIDVALIDITY
), so
other responses should be obtained via FLAGS
) etc.
send(data)
Send data to remote.
setacl(mailbox, who, what)
Set a mailbox acl.
(typ, [data]) =
setquota(root, limits)
Set the quota root's resource limits.
(typ, [data]) =
shutdown()
Close I/O established in "open".
socket()
Return socket instance used to connect to IMAP4 server.
socket =
sort(sort_criteria, charset, *search_criteria)
IMAP4rev1 extension SORT command.
(typ, [data]) =
status(mailbox, names)
Request named status conditions for mailbox.
(typ, [data]) =
store(message_set, command, flags)
Alters flag dispositions for messages in mailbox.
(typ, [data]) =
subscribe(mailbox)
Subscribe to new mailbox.
(typ, [data]) =
thread(threading_algorithm, charset, *search_criteria)
IMAPrev1 extension THREAD command.
(type, [data]) =
uid(command, *args)
Execute "command arg ..." with messages identified by UID, rather than message number.
(typ, [data]) =
Returns response appropriate to command
.
unsubscribe(mailbox)
Unsubscribe from old mailbox.
(typ, [data]) =
xatom(name, *args)
Allow simple extension commands notified by server in CAPABILITY response.
Assumes command is legal in current state.
(typ, [data]) =
Returns response appropriate to extension command `name'.