Changeset 201:f8f625bffdcb

Show
Ignore:
Timestamp:
01/27/11 13:21:41 (16 months ago)
Author:
Menno Smits <menno@…>
Branch:
default
Parents:
200:ed6498330d85 (diff), 199:b796e986ac3b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merged from trunk

Files:
1 removed
2 modified

Legend:

Unmodified
Added
Removed
  • imapclient/imapclient.py

    r195 r201  
    485485 
    486486 
    487     def fetch(self, messages, parts): 
     487    def fetch(self, messages, parts, modifiers=None): 
    488488        """Retrieve selected data items for one or more messages. 
    489489 
    490490        @param messages: Message IDs to fetch. 
    491491        @param parts: A sequence of data items to retrieve. 
     492        @param modifiers: An optional sequence of modifiers. 
    492493        @return: A dictionary indexed by message number. Each item is itself a 
    493494            dictionary containing the requested message parts. 
     
    500501        msg_list = messages_to_str(messages) 
    501502        parts_list = seq_to_parenlist([p.upper() for p in parts]) 
     503        modifiers_list = None 
     504        if modifiers is not None: 
     505          modifiers_list = seq_to_parenlist([m.upper() for m in modifiers]) 
    502506 
    503507        if self.use_uid: 
    504             tag = self._imap._command('UID', 'FETCH', msg_list, parts_list) 
     508            tag = self._imap._command('UID', 'FETCH', msg_list, parts_list, modifiers_list) 
    505509        else: 
    506             tag = self._imap._command('FETCH', msg_list, parts_list) 
     510            tag = self._imap._command('FETCH', msg_list, parts_list, modifiers_list) 
    507511        typ, data = self._imap._command_complete('FETCH', tag) 
    508512        self._checkok('fetch', typ, data) 
  • imapclient/imapclient.py

    r200 r201  
    66import imaplib 
    77import response_lexer 
     8from operator import itemgetter 
     9import warnings 
    810#imaplib.Debug = 5 
    911 
     
    3032RECENT = r'\Recent'         # This flag is read-only 
    3133 
     34class Namespace(tuple): 
     35    def __new__(cls, personal, other, shared): 
     36        return tuple.__new__(cls, (personal, other, shared))  
     37 
     38    personal = property(itemgetter(0)) 
     39    other = property(itemgetter(1)) 
     40    shared = property(itemgetter(2)) 
     41 
    3242 
    3343class IMAPClient(object): 
     
    7080    ReadOnlyError = imaplib.IMAP4.readonly 
    7181 
    72     re_sep = re.compile('^\(\("[^"]*" "([^"]+)"\)\)') 
    7382    re_status = re.compile(r'^\s*"?(?P<folder>[^"]+)"?\s+' 
    7483                           r'\((?P<status_items>.*)\)$') 
     
    134143            return False 
    135144 
     145    def namespace(self): 
     146        """Return the namespace for the account as a (personal, other, shared) tuple. 
     147 
     148        Each element may be None if no namespace of that type exists, 
     149        or a sequence of (prefix, separator) pairs. 
     150 
     151        For convenience the tuple elements may be accessed 
     152        positionally or attributes named "personal", "other" and 
     153        "shared". 
     154 
     155        See RFC 2342 for more details. 
     156        """ 
     157        typ, data = self._imap.namespace() 
     158        self._checkok('namespace', typ, data) 
     159        return Namespace(*parse_response(data)) 
     160 
    136161    def get_folder_delimiter(self): 
    137162        """Determine the folder separator used by the IMAP server. 
    138163 
     164        WARNING: The implementation just picks the first folder 
     165        separator from the first namespace returned. This is not 
     166        particularly sensible. Use namespace instead(). 
     167 
    139168        @return: The folder separator. 
    140169        @rtype: string 
    141170        """ 
    142         typ, data = self._imap.namespace() 
    143         self._checkok('namespace', typ, data) 
    144  
    145         match = self.re_sep.match(data[0]) 
    146         if match: 
    147             return match.group(1) 
    148         else: 
    149             raise self.Error('could not determine folder separator') 
     171        warnings.warn(DeprecationWarning('get_folder_delimiter is going away. Use namespace() instead.')) 
     172        for part in self.namespace(): 
     173            for ns in part: 
     174                return ns[1] 
     175        raise self.Error('could not determine folder separator') 
    150176 
    151177    def list_folders(self, directory="", pattern="*"): 
     
    486512        self._checkok('fetch', typ, data) 
    487513        typ, data = self._imap._untagged_response(typ, data, 'FETCH') 
    488         # appears to be a special case - no 'untagged' responses (ie, no 
    489         # folders) results in [None] 
    490         if data == [None]: 
    491           return {} 
    492  
    493514        return parse_fetch_response(data) 
    494515 
     
    616637            typ, data = self._imap.store(msg_list, cmd, flag_list) 
    617638        self._checkok('store', typ, data) 
    618  
    619639        return self._flatten_dict(parse_fetch_response((data))) 
    620640