From: Menno Smits Date: Mon, 8 Feb 2010 13:06:35 +0000 (+0000) Subject: Handle empty strings and None's in the folder list responses again X-Git-Tag: 0.7~51 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=266ae8dfadde9d8fcee3bdf49afd5edc4a57ba9a;p=imapclient.git Handle empty strings and None's in the folder list responses again All tests passing. --- diff --git a/imapclient/imapclient.py b/imapclient/imapclient.py index 46b4093..7fa048e 100644 --- a/imapclient/imapclient.py +++ b/imapclient/imapclient.py @@ -204,10 +204,11 @@ class IMAPClient(object): return self._proc_folder_list(dat) def _proc_folder_list(self, folder_data): - # appears to be a special case - no 'untagged' responses (ie, no - # folders) returns [None] - if folder_data == [None]: - return [] + # Filter out empty strings and None's. + # This also deals with the special case of - no 'untagged' + # responses (ie, no folders). This comes back as [None]. + folder_data = [item for item in folder_data if item not in ('', None)] + ret = [] parsed = parse_response(folder_data) while parsed: diff --git a/imapclient/test/test_IMAPClient.py b/imapclient/test/test_IMAPClient.py index a6672b2..7f2087b 100644 --- a/imapclient/test/test_IMAPClient.py +++ b/imapclient/test/test_IMAPClient.py @@ -96,11 +96,13 @@ class TestListFolders(IMAPClientTest): (['\\HasNoChildren'], '/', 'Left\"Right'), (['\\HasNoChildren'], '/', r'Left\Right')]) + def test_empty_response(self): + self.assertEqual(self.client._proc_folder_list([None]), []) + + def test_blanks(self): - folders = self.client._proc_folder_list(['', None, - r'(\\HasNoChildren) "/" "last"', - ]) - self.assert_(folders == ['last'], 'got %r' % folders) + folders = self.client._proc_folder_list(['', None, r'(\HasNoChildren) "/" "last"']) + self.assertEqual(folders, [([r'\HasNoChildren'], '/', 'last')]) class TestAppend(IMAPClientTest):