Show
Ignore:
Timestamp:
17/04/11 11:33:16 (13 months ago)
Author:
Menno Smits <menno@…>
Branch:
default
Message:

Updated documentation and examples wrt IDLE support

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • imapclient/examples/idle_example.py

    r208 r221  
     1# This example is a lot more interesting if you have an active client 
     2# connected to the same IMAP account! 
     3 
    14from imapclient import IMAPClient 
    2 import time 
    35 
    46HOST = 'imap.host.com' 
     
    810 
    911server = IMAPClient(HOST, use_uid=True, ssl=ssl) 
     12server.login(USERNAME, PASSWORD) 
     13server.select_folder('INBOX') 
    1014 
    11 server.login(USERNAME, PASSWORD) 
     15# Start IDLE mode 
     16server.idle()      
    1217 
    13 select_info = server.select_folder('INBOX') 
    14 print select_info 
    15 print 
     18# Wait for up to 30 seconds for an IDLE response 
     19responses = server.idle_check(timeout=30) 
     20print responses 
    1621 
    17 idling = True 
    18  
    19 def callback(resp, arg): 
    20     global idling 
    21      
    22     print "Something happened, or timeout was reached" 
    23     print 
    24     print "Callback response:" 
    25     print resp 
    26     print 
    27     print "The callback function received arg: ", arg 
    28     print 
    29     idling = False 
    30  
    31 server.idle(timeout=5, callback=callback, cb_arg="Hello future self!") 
    32 print "Began idling" 
    33  
    34 while idling: 
    35     print "..still idling.." 
    36     time.sleep(1) 
     22# Come out of IDLE mode 
     23text, responses = server.idle_done() 
     24print 'IDLE done. Server said %r' % text 
     25print 'Final responses: ', responses 
    3726     
    3827print server.logout()