Show
Ignore:
Timestamp:
04/29/10 22:10:51 (2 years ago)
Author:
Menno Smits <menno@…>
Branch:
default
Message:

#42: Folder names with double quotes around them have the double quotes stripped

Work around an imaplib misfeature which prevents quoting when folder names
start and end with double quotes.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • imapclient/imapclient.py

    r135 r143  
    329329        typ, data = self._imap.list('', self._encode_folder_name(folder)) 
    330330        self._checkok('list', typ, data) 
     331        data = [x for x in data if x] 
    331332        return len(data) == 1 and data[0] != None 
    332333 
     
    629630    def _encode_folder_name(self, name): 
    630631        if self.folder_encode: 
    631             return imap_utf7.encode(name) 
    632         return name 
     632            name = imap_utf7.encode(name) 
     633        # imaplib assumes that if a command argument (in this case a 
     634        # folder name) has double quotes around it, then it doesn't 
     635        # need quoting. This "feature" prevents creation of folders 
     636        # with names that start and end with double quotes. 
     637        # 
     638        # To work around this IMAPClient performs the quoting 
     639        # itself. This adds start and end double quotes which also 
     640        # serves to fool IMAP4._checkquote into not attempting further 
     641        # quoting. A hack but it works. 
     642        return _quote_arg(name) 
    633643 
    634644 
     
    671681 
    672682 
     683def _quote_arg(arg): 
     684  arg = arg.replace('\\', '\\\\') 
     685  arg = arg.replace('"', '\\"') 
     686  return '"%s"' % arg