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.

Location:
imapclient
Files:
2 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 
  • imapclient/test/test_IMAPClient.py

    r142 r143  
    117117 
    118118        self.client.append('foobar', sentinel.msg, ['FLAG', 'WAVE'], None) 
    119                             
     119 
    120120        self.assert_(self.client._imap.method_calls == 
    121                      [('append', ('foobar', 
     121                     [('append', ('"foobar"', 
    122122                                  '(FLAG WAVE)', 
    123123                                  None, 
     
    136136        self.assert_(datetime_to_imap.called) 
    137137        self.assert_(self.client._imap.method_calls == 
    138                      [('append', ('foobar', 
     138                     [('append', ('"foobar"', 
    139139                                  '(FLAG WAVE)', 
    140140                                  '"somedate"',