75 messages that aren't deleted
Messages:
- ID 38273: 1775 bytes, flags=('NonJunk',)
- ID 36459: 2833 bytes, flags=('\\Flagged', '\\Seen')
- ID 34693: 2874 bytes, flags=('\\Flagged', '\\Seen')
- ID 38066: 5368 bytes, flags=('\\Flagged', '\\Seen')
- ID 38154: 9079 bytes, flags=('\\Seen', 'NonJunk')
- ID 14099: 3322 bytes, flags=('\\Flagged', '\\Seen', '$Label1')
- ID 34196: 9163 bytes, flags=('\\Answered', '\\Seen')
- ID 35349: 4266 bytes, flags=('\\Flagged', '\\Seen')
- ID 29335: 5617 bytes, flags=('\\Flagged', '\\Seen', 'NonJunk')
- ID 38041: 7649 bytes, flags=('\\Seen', 'NonJunk')
- ID 22310: 976108 bytes, flags=('\\Flagged', '\\Seen', '$Label1')
- ID 6439: 3792 bytes, flags=('\\Flagged', '\\Seen', '$Label1', 'Junk')
+ ID 38273: 1775 bytes, flags=(b'NonJunk',)
+ ID 36459: 2833 bytes, flags=(b'\\Flagged', v'\\Seen')
+ ID 34693: 2874 bytes, flags=(b'\\Flagged', v'\\Seen')
+ ID 38066: 5368 bytes, flags=(b'\\Flagged', v'\\Seen')
+ ID 38154: 9079 bytes, flags=(b'\\Seen', b'NonJunk')
+ ID 14099: 3322 bytes, flags=(b'\\Flagged', b'\\Seen', b'$Label1')
+ ID 34196: 9163 bytes, flags=(b'\\Answered', b'\\Seen')
+ ID 35349: 4266 bytes, flags=(b'\\Flagged', b'\\Seen')
+ ID 29335: 5617 bytes, flags=(b'\\Flagged', b'\\Seen', b'NonJunk')
+ ID 38041: 7649 bytes, flags=(b'\\Seen', b'NonJunk')
+ ID 22310: 976108 bytes, flags=(b'\\Flagged', b'\\Seen', b'$Label1')
+ ID 6439: 3792 bytes, flags=(b'\\Flagged', b'\\Seen', b'$Label1', b'Junk')
Concepts
for arbitrary unicode characters (eg. non-English characters) to be
used in folder names.
-All folder names returned by IMAPClient are always returned as unicode
-strings.
-
The ampersand character ("&") has special meaning in IMAP folder
names. IMAPClient automatically escapes and unescapes this character
so that the caller doesn't have to.
Automatic folder name encoding and decoding can be enabled or disabled
with the *folder_encode* attribute. It defaults to True.
+If *folder_encode* is True, all folder names returned by IMAPClient
+are always returned as unicode strings. If *folder_encode* is False,
+folder names are returned as str (Python 2) or bytes (Python 3).
+
Exceptions
~~~~~~~~~~
The IMAP related exceptions that will be raised by this class are:
the help (--help) for more details. You'll be prompted for a username
and password if one isn't provided on the command line.
+The connected IMAPClient instance is available as the variable "c".
+
If installed, IPython will be used as the embedded shell. Otherwise
the basic built-in Python shell will be used.
IMAPClient instance is "c"
In [1]: c.select_folder('inbox')
Out[1]:
- {'EXISTS': 2,
- 'FLAGS': ('\\Answered',
- '\\Flagged',
- '\\Deleted',
- '\\Seen',
- '\\Draft'),
- 'PERMANENTFLAGS': ('\\Answered',
- '\\Flagged',
- '\\Deleted',
- '\\Seen',
- '\\Draft'),
- 'READ-WRITE': True,
- 'RECENT': 0,
- 'UIDNEXT': 1339,
- 'UIDVALIDITY': 1239278212}
+ {b'EXISTS': 2,
+ b'FLAGS': (b'\\Answered',
+ b'\\Flagged',
+ b'\\Deleted',
+ b'\\Seen',
+ b'\\Draft'),
+ b'PERMANENTFLAGS': (b'\\Answered',
+ b'\\Flagged',
+ b'\\Deleted',
+ b'\\Seen',
+ b'\\Draft'),
+ b'READ-WRITE': True,
+ b'RECENT': 0,
+ b'UIDNEXT': 1339,
+ b'UIDVALIDITY': 1239278212}
In [2]: c.search()
Out[2]: [1123, 1233]
In [3]: c.logout()
- Out[3]: 'Logging out'
-
-Note that the connected IMAPClient instance is available as the variable "c".
+ Out[3]: b'Logging out'
A ``XLIST`` response could look something like::
- [([u'\\HasNoChildren', u'\\Inbox'], '/', u'Inbox'),
- ([u'\\Noselect', u'\\HasChildren'], '/', u'[Gmail]'),
- ([u'\\HasNoChildren', u'\\AllMail'], '/', u'[Gmail]/All Mail'),
- ([u'\\HasNoChildren', u'\\Drafts'], '/', u'[Gmail]/Drafts'),
- ([u'\\HasNoChildren', u'\\Important'], '/', u'[Gmail]/Important'),
- ([u'\\HasNoChildren', u'\\Sent'], '/', u'[Gmail]/Sent Mail'),
- ([u'\\HasNoChildren', u'\\Spam'], '/', u'[Gmail]/Spam'),
- ([u'\\HasNoChildren', u'\\Starred'], '/', u'[Gmail]/Starred'),
- ([u'\\HasNoChildren', u'\\Trash'], '/', u'[Gmail]/Trash')]
+ [((b'\\HasNoChildren', b'\\Inbox'), b'/', u'Inbox'),
+ ((b'\\Noselect', b'\\HasChildren'), b'/', u'[Gmail]'),
+ ((b'\\HasNoChildren', b'\\AllMail'), b'/', u'[Gmail]/All Mail'),
+ ((b'\\HasNoChildren', b'\\Drafts'), b'/', u'[Gmail]/Drafts'),
+ ((b'\\HasNoChildren', b'\\Important'), b'/', u'[Gmail]/Important'),
+ ((b'\\HasNoChildren', b'\\Sent'), b'/', u'[Gmail]/Sent Mail'),
+ ((b'\\HasNoChildren', b'\\Spam'), b'/', u'[Gmail]/Spam'),
+ ((b'\\HasNoChildren', b'\\Starred'), b'/', u'[Gmail]/Starred'),
+ ((b'\\HasNoChildren', b'\\Trash'), b'/', u'[Gmail]/Trash')]
This is a *deprecated* Gmail-specific IMAP extension (See
https://developers.google.com/gmail/imap_extensions#xlist_is_deprecated
the selected folder.
Returns a dictionary containing the ``SELECT`` response. At least
- the ``EXISTS``, ``FLAGS`` and ``RECENT`` keys are guaranteed
+ the ``b'EXISTS'``, ``b'FLAGS'`` and ``b'RECENT'`` keys are guaranteed
to exist. An example::
- {'EXISTS': 3,
- 'FLAGS': ('\\Answered', '\\Flagged', '\\Deleted', ... ),
- 'RECENT': 0,
- 'PERMANENTFLAGS': ('\\Answered', '\\Flagged', '\\Deleted', ... ),
- 'READ-WRITE': True,
- 'UIDNEXT': 11,
- 'UIDVALIDITY': 1239278212}
+ {b'EXISTS': 3,
+ b'FLAGS': (b'\\Answered', b'\\Flagged', b'\\Deleted', ... ),
+ b'RECENT': 0,
+ b'PERMANENTFLAGS': (b'\\Answered', b'\\Flagged', b'\\Deleted', ... ),
+ b'READ-WRITE': True,
+ b'UIDNEXT': 11,
+ b'UIDVALIDITY': 1239278212}
"""
self._command_and_check('select', self._normalise_folder(folder), readonly)
return self._process_select_response(self._imap.untagged_responses)
The return value is the server command response message
followed by a list of status responses. For example::
- ('NOOP completed.',
- [(4, 'EXISTS'),
- (3, 'FETCH', ('FLAGS', ('bar', 'sne'))),
- (6, 'FETCH', ('FLAGS', ('sne',)))])
+ (b'NOOP completed.',
+ [(4, b'EXISTS'),
+ (3, b'FETCH', (b'FLAGS', (b'bar', b'sne'))),
+ (6, b'FETCH', (b'FLAGS', (b'sne',)))])
"""
tag = self._imap._command('NOOP')
will be parsed with values converted to appropriate types. For
example::
- [('OK', 'Still here'),
- (1, 'EXISTS'),
- (1, 'FETCH', ('FLAGS', ('\\NotJunk',)))]
+ [(b'OK', b'Still here'),
+ (1, b'EXISTS'),
+ (1, b'FETCH', (b'FLAGS', (b'\\NotJunk',)))]
"""
# In py2, imaplib has sslobj (for SSL connections), and sock for non-SSL.
# In the py3 version it's just sock.
The return value is of the form ``(command_text,
idle_responses)`` where *command_text* is the text sent by the
- server when the IDLE command finished (eg. ``'Idle
+ server when the IDLE command finished (eg. ``b'Idle
terminated'``) and *idle_responses* is a list of parsed idle
responses received since the last call to ``idle_check()`` (if
any). These are returned in parsed form as per
"""Search using Gmail's X-GM-RAW attribute.
*query* should be a valid Gmail search query string. For
- example::
-
- 'has:attachment in:unread'
+ example: ``has:attachment in:unread``
See https://developers.google.com/gmail/imap_extensions#extension_of_the_search_command_x-gm-raw
for more info.
"""Return the flags set for each message in *messages*.
The return value is a dictionary structured like this: ``{
- msgid1: [flag1, flag2, ... ], }``.
+ msgid1: (flag1, flag2, ... ), }``.
"""
response = self.fetch(messages, ['FLAGS'])
return self._filter_fetch_dict(response, b'FLAGS')
"""Return the label set for each message in *messages*.
The return value is a dictionary structured like this: ``{
- msgid1: [label1, label2, ... ], }``.
+ msgid1: (label1, label2, ... ), }``.
This only works with IMAP servers that support the X-GM-LABELS
attribute (eg. Gmail).
instances and ENVELOPE responses will be returned as
:py:class:`Envelope <imapclient.response_types.Envelope>` instances.
+ String data will generally be returned as bytes (Python 3) or
+ str (Python 2).
+
In addition to an element for each *data* item, the dict
returned for each message also contains a *SEQ* key containing
the sequence number for the message. This allows for mapping
Example::
>> c.fetch([3293, 3230], ['INTERNALDATE', 'FLAGS'])
- {3230: {'FLAGS': ('\\Seen',),
- 'INTERNALDATE': datetime.datetime(2011, 1, 30, 13, 32, 9),
- 'SEQ': 84},
- 3293: {'FLAGS': (),
- 'INTERNALDATE': datetime.datetime(2011, 2, 24, 19, 30, 36),
- 'SEQ': 110}}
+ {3230: {b'FLAGS': (b'\\Seen',),
+ b'INTERNALDATE': datetime.datetime(2011, 1, 30, 13, 32, 9),
+ b'SEQ': 84},
+ 3293: {b'FLAGS': (),
+ b'INTERNALDATE': datetime.datetime(2011, 2, 24, 19, 30, 36),
+ b'SEQ': 110}}
+
"""
if not messages:
return {}