From: Menno Smits Date: Sun, 31 Mar 2013 22:19:55 +0000 (+0100) Subject: synced the python3 repo with the main repo X-Git-Tag: 0.10~2^2~21^2~19 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=38fb296ea8e5f37a104b5c8a257a3383fb93eff8;p=imapclient.git synced the python3 repo with the main repo There's been a significant number of changes in the main repo since the python3 fork was created. --- 38fb296ea8e5f37a104b5c8a257a3383fb93eff8 diff --cc imapclient/__init__.py index 6bd5251,9ce1892..8a05321 --- a/imapclient/__init__.py +++ b/imapclient/__init__.py @@@ -4,10 -4,7 +4,10 @@@ # version_info provides the version number in programmer friendly way. # The 4th part will be either alpha, beta or final. + +from __future__ import unicode_literals + - version_info = (0, 9, 0, 'final') + version_info = (0, 9, 2, 'final') def _imapclient_version_string(vinfo): major, minor, micro, releaselevel = vinfo diff --cc imapclient/config.py index b1fd2b9,2e54e2c..b3eb3b9 --- a/imapclient/config.py +++ b/imapclient/config.py @@@ -1,11 -1,11 +1,17 @@@ -from ConfigParser import SafeConfigParser, NoOptionError +from __future__ import unicode_literals + +try: + from ConfigParser import SafeConfigParser, NoOptionError +except ImportError: + from configparser import SafeConfigParser, NoOptionError + import imapclient + import urllib + + try: + import json + except ImportError: + json = None def parse_config_file(path): @@@ -13,15 -13,23 +19,22 @@@ Used by livetest.py and interact.py """ - parser = SafeConfigParser(dict(ssl='false', - username=None, - password=None, - oauth='false', - oauth_url=None, - oauth_token=None, - oauth_token_secret=None)) + parser = SafeConfigParser(dict( + username=None, + password=None, + ssl='false', + stream='false', + oauth='false', + oauth_token=None, + oauth_token_secret=None, + oauth_url=None, + oauth2='false', + oauth2_client_id=None, + oauth2_client_secret=None, + oauth2_refresh_token=None, + )) - fh = file(path) - parser.readfp(fh) - fh.close() + with open(path, 'r') as fh: + parser.readfp(fh) section = 'main' assert parser.sections() == [section], 'Only expected a [main] section' diff --cc imapclient/imapclient.py index eb5854a,d39aa86..bb20469 --- a/imapclient/imapclient.py +++ b/imapclient/imapclient.py @@@ -12,20 -9,17 +12,21 @@@ import warning from datetime import datetime from operator import itemgetter -import imaplib -import response_lexer +from . import response_lexer + # Confusingly, this module is for OAUTH v1, not v2 try: - import oauth2 + import oauth2 as oauth_module except ImportError: - oauth2 = None + oauth_module = None - from .imap_utf7 import encode as encode_utf7, from_bytes, decode as decode_utf7 -import imap_utf7 -from fixed_offset import FixedOffset ++from .imap_utf7 import encode as encode_utf7, from_bytes +from .fixed_offset import FixedOffset +from .six import moves, iteritems, text_type, integer_types, PY3, binary_type +xrange = moves.xrange + +if PY3: + long = int # long is just int in python3 __all__ = ['IMAPClient', 'DELETED', 'SEEN', 'ANSWERED', 'FLAGGED', 'DRAFT', 'RECENT'] @@@ -145,9 -160,37 +168,38 @@@ class IMAPClient(object) def capabilities(self): """Returns the server capability list. + + If the session is authenticated and the server has returned a + CAPABILITY response at authentication time, this response + will be returned. Otherwise, the CAPABILITY command will be + issued to the server, with the results cached for future calls. + + If the session is not yet authenticated, the cached + capabilities determined at connection time will be returned. """ - capabilities = from_bytes(self._imap.capabilities, self.folder_encode) - return capabilities + # if a capability response has been cached, use that + if self._cached_capabilities: + return self._cached_capabilities + + # If server returned an untagged CAPABILITY response (during + # authentication), cache it and return that. + response = self._imap.untagged_responses.pop('CAPABILITY', None) + if response: + return self._save_capabilities(response[0]) + + # if authenticated, but don't have a capability reponse, ask for one + if self._imap.state in ('SELECTED', 'AUTH'): + response = self._command_and_check('capability', unpack=True) + return self._save_capabilities(response) + + # Just return capabilities that imaplib grabbed at connection + # time (pre-auth) - return self._imap.capabilities ++ return from_bytes(self._imap.capabilities, folder_encode=False) + + def _save_capabilities(self, raw_response): ++ raw_response = from_bytes(raw_response, folder_encode=False) + self._cached_capabilities = tuple(raw_response.upper().split()) + return self._cached_capabilities def has_capability(self, capability): """Return ``True`` if the IMAP server has the given *capability*. @@@ -502,13 -532,11 +546,13 @@@ args = ['CHARSET', charset] else: args = [] - args.extend(crit_list) + args.extend(criteria) typ, data = self._imap.uid('SEARCH', *args) else: - typ, data = self._imap.search(charset, *crit_list) + typ, data = self._imap.search(charset, *criteria) + data = from_bytes(data, self.folder_encode) + self._checkok('search', typ, data) data = data[0] if data is None: # no untagged responses... @@@ -899,8 -934,25 +961,15 @@@ def messages_to_str(messages) messages = (messages,) elif not isinstance(messages, (tuple, list)): raise ValueError('invalid message list: %r' % messages) - return ','.join([str(m) for m in messages]) - -def seq_to_parenlist(flags): - """Convert a sequence of strings into parenthised list string for - use with IMAP commands. - """ - if isinstance(flags, str): - flags = (flags,) - elif not isinstance(flags, (tuple, list)): - raise ValueError('invalid flags list: %r' % flags) - return '(%s)' % ' '.join(flags) + return ','.join([text_type(m) for m in messages]) + def normalise_search_criteria(criteria): + if not criteria: + raise ValueError('no criteria specified') + if isinstance(criteria, basestring): + criteria = (criteria,) + return ['(%s)' % c for c in criteria] + def datetime_to_imap(dt): """Convert a datetime instance to a IMAP datetime string.