From: Menno Smits Date: Sun, 19 Apr 2009 12:54:12 +0000 (+0100) Subject: fixed bug that caused breakage with folder names containing unusual chars X-Git-Tag: 0.7~93 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=77055911b7153393752ec7ff794f398500e8b376;p=imapclient.git fixed bug that caused breakage with folder names containing unusual chars --- diff --git a/TODO b/TODO index 829624c..a1dfb81 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,4 @@ - transparent folder escaping - - re_folder currently fails if there's strange chars in the folder name - - write a unit test for this - more testing - gmail - cyrus @@ -10,6 +8,9 @@ - sort out INTERNALDATE timezone issues in livetest.py (see freshfoo.com) +- livetest.py --interact support is clumsy + - make this a separate command-line utility instead + ---- release 0.5 ---- - automate releases with bzr @@ -19,6 +20,7 @@ - clean up basic command handling to avoid repetition - might be able to metaprogram the way out of the currently clumsy UID handling situation - sphinx based docs + - publish on web site too - support for more IMAP functions: sort, examine etc - someone sent a patch for this? - write a comparision of imaplib vs imapclient.py diff --git a/imapclient/imapclient.py b/imapclient/imapclient.py index 24eac20..2234b72 100644 --- a/imapclient/imapclient.py +++ b/imapclient/imapclient.py @@ -163,15 +163,14 @@ class IMAPClient(object): folders = [] for line in data: + #TODO can the FetchParser code be adapted for use here? folder_text = None - #XXX write a unit test for this bug - #XXX can the FetchParser code be used here instead? - #if isinstance(line, tuple): - #folder_text = line[-1] - #else: - m = self.re_folder.match(line) - if m: - folder_text = m.group(1) + if isinstance(line, tuple): + folder_text = line[-1] + else: + match = self.re_folder.match(line) + if match: + folder_text = match.group(1) if folder_text is not None: folders.append(self._decode_folder_name(folder_text)) return folders diff --git a/imapclient/test/test_IMAPClient.py b/imapclient/test/test_IMAPClient.py index 4f113ce..5cb7070 100644 --- a/imapclient/test/test_IMAPClient.py +++ b/imapclient/test/test_IMAPClient.py @@ -1,11 +1,12 @@ import unittest -from imapclient.test.testable_imapclient import TestableIMAPClient +from imapclient.test.testable_imapclient import TestableIMAPClient as IMAPClient from imapclient.test.mock import sentinel + class IMAPClientTestBase(unittest.TestCase): def setUp(self): - self.client = TestableIMAPClient() + self.client = IMAPClient() class TestListFolders(IMAPClientTestBase): @@ -21,6 +22,11 @@ class TestListFolders(IMAPClientTestBase): self.assert_(folders == ['A', 'Foo Bar']) + def test_NO(self): + self.client._imap.list.return_value = ('NO', ['badness']) + self.assertRaises(IMAPClient.Error, self.client.list_folders) + + def test_without_quotes(self): self.client._imap.list.return_value = ('OK', ['(\\HasNoChildren) "/" A', '(\\HasNoChildren) "/" B', @@ -41,10 +47,15 @@ class TestListFolders(IMAPClientTestBase): self.assert_(folders == ['Alpha', 'Foo Bar', 'C'], 'got %r' % folders) -class TestListFolders(IMAPClientTestBase): + def test_funky_characters(self): + self.client._imap.list.return_value = ('OK', + [('(\\NoInferiors \\UnMarked) "/" {5}', 'bang\xff'), + '', + '(\\HasNoChildren \\UnMarked) "/" "INBOX"']) + + folders = self.client.list_folders() + self.assert_(folders == ['bang\xff', 'INBOX'], 'got %r' % folders) - def test_fail(self): - self.assert_(False, 'todo') if __name__ == '__main__':