Show
Ignore:
Timestamp:
01/11/10 19:11:54 (2 years ago)
Author:
Menno Smits <menno@…>
Branch:
default
Message:

Parse imaplib's fetch data structures instead of doing it all ourselves

This makes the code messier but means imaplib does a bit more of the
heavy lifting - this is probably safer from a bug standpoint.

From Mark Hammond.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • imapclient/imapclient.py

    r110 r115  
    1414__all__ = ['IMAPClient', 'DELETED', 'SEEN', 'ANSWERED', 'FLAGGED', 'DRAFT', 
    1515    'RECENT'] 
     16 
     17from response_parser import parse_fetch_response 
    1618 
    1719# System flags 
     
    327329 
    328330        self._checkok('search', typ, data) 
     331        if data == [None]: # no untagged responses... 
     332            return [] 
    329333 
    330334        return [ long(i) for i in data[0].split() ] 
     
    436440        return parser(data) 
    437441 
    438  
    439442    def altfetch(self, messages, parts): 
    440443        if not messages: 
     
    448451        else: 
    449452            tag = self._imap._command('FETCH', msg_list, parts_list) 
    450  
    451         print tag 
    452         lines = [] 
    453         while True: 
    454             line = self._imap._get_line() 
    455             if line.startswith(tag): 
    456                 break 
    457             lines.append(line) 
    458         return lines 
    459      
    460         #self._checkok('fetch', typ, data) 
    461  
    462         #parser = FetchParser() 
    463         #return parser(data) 
    464  
     453        typ, data = self._imap._command_complete('FETCH', tag) 
     454        self._checkok('fetch', typ, data) 
     455        typ, data = self._imap._untagged_response(typ, data, 'FETCH') 
     456        # appears to be a special case - no 'untagged' responses (ie, no 
     457        # folders) results in [None] 
     458        if data == [None]: 
     459          return {} 
     460 
     461        return parse_fetch_response(data) 
    465462 
    466463    def append(self, folder, msg, flags=(), msg_time=None):