Show
Ignore:
Timestamp:
01/25/10 13:26:30 (2 years ago)
Author:
Menno Smits <menno@…>
Branch:
default
Message:

select_folder() now returns the full parsed SELECT response (#24)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • imapclient/imapclient.py

    r121 r126  
    1515    'RECENT'] 
    1616 
    17 from response_parser import parse_fetch_response 
     17from response_parser import parse_response, parse_fetch_response 
     18 
    1819 
    1920# System flags 
     
    205206 
    206207        @param folder: The folder name. 
    207         @return: Number of messages in the folder. 
    208         @rtype: long int 
     208        @return: A dictionary containing the SELECT response 
     209          values. At least the EXISTS, FLAGS and RECENT keys are 
     210          guaranteed to exist. Example: 
     211            {'EXISTS': 3, 
     212             'FLAGS': ('\\Answered', '\\Flagged', '\\Deleted', ... ), 
     213             'RECENT': 0, 
     214             'PERMANENTFLAGS': ('\\Answered', '\\Flagged', '\\Deleted', ... ), 
     215             'READ-WRITE': True, 
     216             'UIDNEXT': 11, 
     217             'UIDVALIDITY': 1239278212} 
    209218        """ 
    210219        typ, data = self._imap.select(self._encode_folder_name(folder)) 
    211220        self._checkok('select', typ, data) 
    212         return long(data[0]) 
     221        return self._process_select_response(self._imap.untagged_responses) 
     222 
     223 
     224    def _process_select_response(self, resp): 
     225        out = {} 
     226        for key, value in resp.iteritems(): 
     227            key = key.upper() 
     228            if key == 'OK': 
     229                continue 
     230            elif key in ('EXISTS', 'RECENT', 'UIDNEXT', 'UIDVALIDITY'): 
     231                value = int(value[0]) 
     232            elif key in ('FLAGS', 'PERMANENTFLAGS'): 
     233                value = parse_response(value)[0] 
     234            elif key == 'READ-WRITE': 
     235                value = True 
     236                                  
     237            out[key] = value 
     238        return out 
    213239 
    214240