"""
typ, data = self._imap.list('', self._encode_folder_name(folder))
self._checkok('list', typ, data)
+ data = [x for x in data if x]
return len(data) == 1 and data[0] != None
def _encode_folder_name(self, name):
if self.folder_encode:
- return imap_utf7.encode(name)
- return name
+ name = imap_utf7.encode(name)
+ # imaplib assumes that if a command argument (in this case a
+ # folder name) has double quotes around it, then it doesn't
+ # need quoting. This "feature" prevents creation of folders
+ # with names that start and end with double quotes.
+ #
+ # To work around this IMAPClient performs the quoting
+ # itself. This adds start and end double quotes which also
+ # serves to fool IMAP4._checkquote into not attempting further
+ # quoting. A hack but it works.
+ return _quote_arg(name)
def messages_to_str(messages):
return dt.strftime("%d-%b-%Y %H:%M:%S %z")
+def _quote_arg(arg):
+ arg = arg.replace('\\', '\\\\')
+ arg = arg.replace('"', '\\"')
+ return '"%s"' % arg
self.client._imap.append.return_value = ('OK', ['Good'])
self.client.append('foobar', sentinel.msg, ['FLAG', 'WAVE'], None)
-
+
self.assert_(self.client._imap.method_calls ==
- [('append', ('foobar',
+ [('append', ('"foobar"',
'(FLAG WAVE)',
None,
sentinel.msg),
self.assert_(datetime_to_imap.called)
self.assert_(self.client._imap.method_calls ==
- [('append', ('foobar',
+ [('append', ('"foobar"',
'(FLAG WAVE)',
'"somedate"',
sentinel.msg),
assert not client.folder_exists('this is very unlikely to exist')
test_folders = ['foobar',
+ '"foobar"',
+ 'foo "bar"',
'stuff & things',
u'test & \u2622']
client.create_folder(folder)
assert client.folder_exists(folder)
- assert folder in extract_normal_folders(client.list_folders())
+ assert folder in extract_normal_folders(client.list_folders()), repr(folder)
client.select_folder(folder)
client.close_folder()