Message Identifiers
~~~~~~~~~~~~~~~~~~~
-There are two ways to refer to messages using the IMAP protocol.
+In the IMAP protocol, messages are identified using an integer. These
+message ids are specific to a given folder.
-One way is by message sequence number where the messages in a mailbox
-are numbered from 1 to N where N is the number of messages. These
-numbers don't persist between sessions and may be reassigned after
-some operations such as a folder expunge.
+There are two types of message identifiers in the IMAP protocol.
+
+One type is the message sequence number where the messages in a folder
+are numbered from 1 to N where N is the number of messages in the
+folder. These numbers don't persist between sessions and may be
+reassigned after some operations such as an expunge.
A more convenient approach is Unique Identifiers (UIDs). Unique
Identifiers are integers assigned to each message by the IMAP server
that will persist across sessions. They do not change when folders are
-expunged.
+expunged. Almost all IMAP servers support UIDs.
Each call to the IMAP server can use either message sequence numbers
or UIDs in the command arguments and return values. The client
-specifies to the server which type of identifier should be
-used. IMAPClient uses UIDs by default.
+specifies to the server which type of identifier should be used. You
+can set whether IMAPClient should use UIDs or message sequence number
+via the *use_uid* argument passed when an IMAPClient instance is
+created and the *use_uid* attribute. The *use_uid* attribute can be
+used to change the message id type between calls to the
+server. IMAPClient uses UIDs by default.
Any method that accepts message ids takes either a sequence containing
message ids (eg. ``[1,2,3]``), or a single message id integer, or a
string representing sets and ranges of messages as supported by the
-IMAP protocol (e.g. ``'50-65'``, ``'2:*'`` or
-``'2,4:7,9,12:*'``). Whether these are interpreted as message sequence
-numbers or UIDs depends on the *use_uid* argument passed when an
-IMAPClient instance is created and the *use_uid* attribute. The
-*use_uid* attribute can be used to change the message id type between
-calls to the server.
+IMAP protocol (e.g. ``'50-65'``, ``'2:*'`` or ``'2,4:7,9,12:*'``).
Message Flags
~~~~~~~~~~~~~
return self._command_and_check('unsubscribe', self._normalise_folder(folder))
def search(self, criteria='ALL', charset=None):
- """Return a list of messages ids matching *criteria*.
+ """Return a list of messages ids from the currently selected
+ folder matching *criteria*.
*criteria* should be a sequence of one or more criteria
items. Each criteria item may be either unicode or
return parse_message_list(data)
def sort(self, sort_criteria, criteria='ALL', charset='UTF-8'):
- """Return a list of message ids sorted by *sort_criteria* and
- optionally filtered by *criteria*.
+ """Return a list of message ids from the currently selected
+ folder, sorted by *sort_criteria* and optionally filtered by
+ *criteria*.
*sort_criteria* may be specified as a sequence of strings or a
single string. IMAPClient will take care any required
return [long(i) for i in ids.split()]
def thread(self, algorithm='REFERENCES', criteria='ALL', charset='UTF-8'):
- """Return a list of messages threads matching *criteria*.
+ """Return a list of messages threads from the currently
+ selected folder which match *criteria*.
Each returned thread is a list of messages ids. An example
return value containing three message threads::
return parse_response(data)
def get_flags(self, messages):
- """Return the flags set for each message in *messages*.
+ """Return the flags set for each message in *messages* from
+ the currently selected folder.
The return value is a dictionary structured like this: ``{
msgid1: (flag1, flag2, ... ), }``.
return self._filter_fetch_dict(response, b'FLAGS')
def add_flags(self, messages, flags):
- """Add *flags* to *messages*.
+ """Add *flags* to *messages* in the currently selected folder.
*flags* should be a sequence of strings.
return self._store(b'+FLAGS', messages, flags, b'FLAGS')
def remove_flags(self, messages, flags):
- """Remove one or more *flags* from *messages*.
+ """Remove one or more *flags* from *messages* in the currently
+ selected folder.
*flags* should be a sequence of strings.
return self._store(b'-FLAGS', messages, flags, b'FLAGS')
def set_flags(self, messages, flags):
- """Set the *flags* for *messages*.
+ """Set the *flags* for *messages* in the currently selected
+ folder.
*flags* should be a sequence of strings.
return self._store(b'FLAGS', messages, flags, b'FLAGS')
def get_gmail_labels(self, messages):
- """Return the label set for each message in *messages*.
+ """Return the label set for each message in *messages* in the
+ currently selected folder.
The return value is a dictionary structured like this: ``{
msgid1: (label1, label2, ... ), }``.
return self._filter_fetch_dict(response, b'X-GM-LABELS')
def add_gmail_labels(self, messages, labels):
- """Add *labels* to *messages*.
+ """Add *labels* to *messages* in the currently selected folder.
*labels* should be a sequence of strings.
self._normalise_labels(labels), b'X-GM-LABELS')
def remove_gmail_labels(self, messages, labels):
- """Remove one or more *labels* from *messages*.
+ """Remove one or more *labels* from *messages* in the
+ currently selected folder.
*labels* should be a sequence of strings.
self._normalise_labels(labels), b'X-GM-LABELS')
def set_gmail_labels(self, messages, labels):
- """Set the *labels* for *messages*.
+ """Set the *labels* for *messages* in the currently selected
+ folder.
*labels* should be a sequence of strings.
return self.add_flags(messages, DELETED)
def fetch(self, messages, data, modifiers=None):
- """Retrieve selected *data* associated with one or more *messages*.
+ """Retrieve selected *data* associated with one or more
+ *messages* in the currently selected folder.
*data* should be specified as a sequnce of strings, one item
per data selector, for example ``['INTERNALDATE',