Changeset 208:3eeca2dda55d for imapclient
- Timestamp:
- 03/23/11 00:00:36 (14 months ago)
- Branch:
- idle
- Children:
- 209:80f530da50d7, 212:45fab16c5bf6
- Location:
- imapclient
- Files:
-
- 1 added
- 2 modified
-
examples/idle_example.py (added)
-
imapclient.py (modified) (4 diffs)
-
response_parser.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
imapclient/imapclient.py
r204 r208 4 4 5 5 import re 6 import imaplib7 6 import response_lexer 8 7 from operator import itemgetter 9 8 import warnings 9 10 try: 11 import imaplib2 as imaplib 12 imaplib2 = True 13 except ImportError: 14 imaplib2 = False 15 import imaplib 16 10 17 #imaplib.Debug = 5 11 18 12 19 import imap_utf7 13 20 from fixed_offset import FixedOffset … … 263 270 typ, data = self._imap.select(self._encode_folder_name(folder), readonly) 264 271 self._checkok('select', typ, data) 265 return self._process_select_response(self._imap.untagged_responses) 266 272 if imaplib2: 273 untagged_responses = self._response_to_dict(self._imap.untagged_responses) 274 else: 275 untagged_responses = self._imap.untagged_responses 276 return self._process_select_response(untagged_responses) 277 278 def _response_to_dict(self, resp): 279 dictresp = {} 280 281 if len(resp) > 0: 282 for item in resp: 283 dictresp[item[0]] = item[1] 284 285 return dictresp 267 286 268 287 def _process_select_response(self, resp): … … 282 301 return out 283 302 284 303 def idle(self, timeout=None, **kwargs): 304 """Put server into IDLE mode. 305 306 IDLE mode will end when the server notifies of a change, the sever 307 reaches the timeout, or another IMAP4 command is scheduled. 308 309 @param timeout: timeout for the IDLE command in seconds (default: 29 mins) 310 @param callback: Function to be called when IDLE mode ends. If a callback 311 is supplied the idle function will be asynchronous, returning immediately. 312 @param cb_arg: An optional argument that will be passed to the callback function. 313 @return: Server response. (None if callback is specified). 314 """ 315 if imaplib2: 316 if 'callback' in kwargs: 317 callback = kwargs.pop('callback') 318 def _wrapped_callback(resp): 319 typ, data = resp[0] 320 self._checkok('idle', typ, data) 321 # if there's a cb_arg, pass it along 322 cb_arg = resp[1] 323 if cb_arg: 324 callback(data[0], cb_arg) 325 else: 326 callback(data[0]) 327 self._imap.idle(timeout, callback=_wrapped_callback, **kwargs) 328 else: 329 typ, data = self._imap.idle(timeout) 330 self._checkok('idle', typ, data) 331 return data[0] 332 else: 333 raise self.Error('The imaplib2 module is required to use IDLE') 334 285 335 def folder_status(self, folder, what=None): 286 336 """Requests the status from folder. … … 510 560 else: 511 561 tag = self._imap._command('FETCH', msg_list, parts_list, modifiers_list) 512 typ, data = self._imap._command_complete('FETCH', tag) 562 if imaplib2: 563 typ, data = self._imap._command_complete(tag, 'FETCH') 564 else: 565 typ, data = self._imap._command_complete('FETCH', tag) 513 566 self._checkok('fetch', typ, data) 514 567 typ, data = self._imap._untagged_response(typ, data, 'FETCH') -
imapclient/response_parser.py
r204 r208 12 12 #TODO more exact error reporting 13 13 14 import imaplib15 14 from datetime import datetime 16 15 from fixed_offset import FixedOffset 17 16 from response_lexer import TokenSource 18 17 18 try: 19 import imaplib2 as imaplib 20 except ImportError: 21 imaplib2 = None 22 import imaplib 19 23 20 24 __all__ = ['parse_response', 'ParseError']
