imaplib (version: 2.15)
 

IMAP4 client.

Based on RFC 2060.

Author: Piers Lauder <piers@cs.su.oz.au> December 1997.

Authentication code contributed by Donn Cave <donn@u.washington.edu> June 1998.

Public class:           IMAP4
Public variable:        Debug
Public functions:       Internaldate2tuple
                        Int2AP
                        ParseFlags
                        Time2Internaldate


 Modules
                                                                                                                                                                                                                               
binascii
random
re
socket
string
sys
time


 Classes
                                                                                                                                                                                                                               
IMAP4
_Authenticator


 class IMAP4
           IMAP4 client class.

Instantiate with: IMAP4([host[, port]])

        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
white-space and isn't enclosed with either parentheses or
double quotes) each string is quoted.

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.

Errors raise the exception class <instance>.error("<reason>").
IMAP4 server errors raise <instance>.abort("<reason>"),
which is a sub-class of 'error'. Mailbox status changes
from READ-WRITE to READ-ONLY raise the exception class
<instance>.readonly("<reason>"), which is a sub-class of 'abort'.

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.
 
                                                                                                                                                                                                                     
__getattr__(self, attr)
no doc string
__init__(self, host='', port=143)
no doc string
_append_untagged(self, typ, dat)
#       Private methods
_command(self, name, *args)
no doc string
_command_complete(self, name, tag)
no doc string
_get_line(self)
no doc string
_get_response(self)
no doc string
_get_tagged_response(self, tag)
no doc string
_match(self, cre, s)
no doc string
_new_tag(self)
no doc string
_simple_command(self, name, *args)
no doc string
_untagged_response(self, typ, dat, name)
no doc string
append(self, mailbox, flags, date_time, message)
Append message to named mailbox.
(typ, [data]) = <instance>.append(mailbox, flags, date_time, message)
authenticate(self, mechanism, authobject)
Authenticate command - requires response processing.
'mechanism' specifies which authentication mechanism is to
be used - it must appear in <instance>.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.
check(self)
Checkpoint mailbox on server.
(typ, [data]) = <instance>.check()
close(self)
Close currently selected mailbox.
Deleted messages are removed from writable mailbox.
This is the recommended command before 'LOGOUT'.
(typ, [data]) = <instance>.close()
copy(self, message_set, new_mailbox)
Copy 'message_set' messages onto end of 'new_mailbox'.
(typ, [data]) = <instance>.copy(message_set, new_mailbox)
create(self, mailbox)
Create new mailbox.
(typ, [data]) = <instance>.create(mailbox)
delete(self, mailbox)
Delete old mailbox.
(typ, [data]) = <instance>.delete(mailbox)
expunge(self)
Permanently remove deleted items from selected mailbox.
Generates 'EXPUNGE' response for each deleted message.
(typ, [data]) = <instance>.expunge()
'data' is list of 'EXPUNGE'd message numbers in order received.
fetch(self, message_set, message_parts)
Fetch (parts of) messages.
(typ, [data, ...]) = <instance>.fetch(message_set, message_parts)
'data' are tuples of message part envelope and data.
list(self, directory='""', pattern='*')
List mailbox names in directory matching pattern.
(typ, [data]) = <instance>.list(directory='""', pattern='*')
'data' is list of LIST responses.
login(self, user, password)
Identify client using plaintext password.
(typ, [data]) = <instance>.list(user, password)
logout(self)
Shutdown connection to server.
(typ, [data]) = <instance>.logout()
Returns server 'BYE' response.
lsub(self, directory='""', pattern='*')
List 'subscribed' mailbox names in directory matching pattern.
(typ, [data, ...]) = <instance>.lsub(directory='""', pattern='*')
'data' are tuples of message part envelope and data.
noop(self)
Send NOOP command.
(typ, data) = <instance>.noop()
open(self, host, port)
Setup 'self.sock' and 'self.file'.
partial(self, message_num, message_part, start, length)
Fetch truncated part of a message.
(typ, [data, ...]) = <instance>.partial(message_num, message_part, start, length)
'data' is tuple of message part envelope and data.
recent(self)
Return most recent 'RECENT' responses if any exist,
else prompt server for an update using the 'NOOP' command.
(typ, [data]) = <instance>.recent()
'data' is None if no new messages,
else list of RECENT responses, most recent last.
rename(self, oldmailbox, newmailbox)
Rename old mailbox name to new.
(typ, data) = <instance>.rename(oldmailbox, newmailbox)
response(self, code)
Return data for response 'code' if received, or None.
Old value for response 'code' is cleared.
(code, [data]) = <instance>.response(code)
search(self, charset, criteria)
Search mailbox for matching messages.
(typ, [data]) = <instance>.search(charset, criteria)
'data' is space separated list of matching message numbers.
select(self, mailbox='INBOX', readonly=None)
Select a mailbox.
Flush all untagged responses.
(typ, [data]) = <instance>.select(mailbox='INBOX', readonly=None)
'data' is count of messages in mailbox ('EXISTS' response).
socket(self)
Return socket instance used to connect to IMAP4 server.
socket = <instance>.socket()
status(self, mailbox, names)
Request named status conditions for mailbox.
(typ, [data]) = <instance>.status(mailbox, names)
store(self, message_set, command, flag_list)
Alters flag dispositions for messages in mailbox.
(typ, [data]) = <instance>.store(message_set, command, flag_list)
subscribe(self, mailbox)
Subscribe to new mailbox.
(typ, [data]) = <instance>.subscribe(mailbox)
uid(self, command, *args)
Execute "command arg ..." with messages identified by UID,
        rather than message number.
(typ, [data]) = <instance>.uid(command, arg1, arg2, ...)
Returns response appropriate to 'command'.
unsubscribe(self, mailbox)
Unsubscribe from old mailbox.
(typ, [data]) = <instance>.unsubscribe(mailbox)
xatom(self, name, *args)
Allow simple extension commands
        notified by server in CAPABILITY response.
(typ, [data]) = <instance>.xatom(name, arg, ...)


 class _Authenticator
           Private class to provide en/decoding
for base64-based authentication conversation.
 
                                                                                                                                                                                                                     
__init__(self, mechinst)
no doc string
decode(self, inp)
no doc string
encode(self, inp)
no doc string
process(self, data)
no doc string


 Functions
                                                                                                                                                                                                                               
Int2AP(num)
Convert integer to A-P string representation.
Internaldate2tuple(resp)
Convert IMAP4 INTERNALDATE to UT.
Returns Python time module tuple.
ParseFlags(resp)
Convert IMAP4 flags response to python tuple.
Time2Internaldate(date_time)
Convert 'date_time' to IMAP4 INTERNALDATE representation.
Return string in form: '"DD-Mmm-YYYY HH:MM:SS +HHMM"'
_dump_ur(dict)
no doc string
_mesg(s)
no doc string