From f4f985a4626823b63e7c04197f99a028fb37b4bd Mon Sep 17 00:00:00 2001 From: Menno Smits Date: Thu, 30 May 2013 23:25:49 +0100 Subject: [PATCH] Handle HIGHESTMODSEQ in SELECT response correctly And added much needed unit tests for select_folder --- imapclient/imapclient.py | 2 +- imapclient/test/test_imapclient.py | 35 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/imapclient/imapclient.py b/imapclient/imapclient.py index 7675bbe..6d743cb 100644 --- a/imapclient/imapclient.py +++ b/imapclient/imapclient.py @@ -363,7 +363,7 @@ class IMAPClient(object): key = key.upper() if key == 'OK': continue - elif key in ('EXISTS', 'RECENT', 'UIDNEXT', 'UIDVALIDITY'): + elif key in ('EXISTS', 'RECENT', 'UIDNEXT', 'UIDVALIDITY', 'HIGHESTMODSEQ'): value = int(value[0]) elif key in ('FLAGS', 'PERMANENTFLAGS'): value = parse_response(value)[0] diff --git a/imapclient/test/test_imapclient.py b/imapclient/test/test_imapclient.py index 717f153..a11e5d2 100644 --- a/imapclient/test/test_imapclient.py +++ b/imapclient/test/test_imapclient.py @@ -150,6 +150,41 @@ class TestListFolders(IMAPClientTest): self.assertEqual(folders, [((r'\HasNoChildren',), '/', 'last')]) +class TestSelectFolder(IMAPClientTest): + + def test_normal(self): + self.client._command_and_check = Mock() + self.client._imap.untagged_responses = { + 'OK': [], + 'exists': ['1'], + 'RECENT': ['2'], + 'UIDNEXT': ['3'], + 'UIDVALIDITY': ['4'], + 'HIGHESTMODSEQ': ['5'], + 'FLAGS': ['(ABC DEF)'], + 'PERMANENTFLAGS': ['(XXX ZZZ)'], + 'READ-WRITE': [''], + 'OTHER': ['blah'] + } + + result = self.client.select_folder(b'folder_name', sentinel.readonly) + + self.client._command_and_check.assert_called_once_with('select', + '"folder_name"', + sentinel.readonly) + self.assertEqual(result, { + 'EXISTS': 1, + 'RECENT': 2, + 'UIDNEXT': 3, + 'UIDVALIDITY': 4, + 'HIGHESTMODSEQ': 5, + 'FLAGS': ('ABC', 'DEF'), + 'PERMANENTFLAGS': ('XXX', 'ZZZ'), + 'READ-WRITE': True, + 'OTHER': ['blah'] + }) + + class TestAppend(IMAPClientTest): def test_without_msg_time(self): -- 2.43.0