From 3625948bbe7a7b2583845ea15a18db66c1fc834e Mon Sep 17 00:00:00 2001 From: Menno Smits Date: Tue, 1 Sep 2015 17:46:37 +1200 Subject: [PATCH] Correctly handle literals in STATUS responses Also added missing unit tests for folder_status(). Fixes #174. --- NEWS.rst | 1 + imapclient/imapclient.py | 4 +-- imapclient/test/test_folder_status.py | 41 +++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 imapclient/test/test_folder_status.py diff --git a/NEWS.rst b/NEWS.rst index 096c736..0399361 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -147,6 +147,7 @@ Other * Added a "shutdown" method. * The embedded six package has been removed in favour of using an externally installed instance. + * Fixed handling of literals in STATUS responses. ====== 0.13 diff --git a/imapclient/imapclient.py b/imapclient/imapclient.py index 9febb7b..3b29063 100644 --- a/imapclient/imapclient.py +++ b/imapclient/imapclient.py @@ -620,8 +620,8 @@ class IMAPClient(object): what = normalise_text_list(what) what_ = '(%s)' % (' '.join(what)) - data = self._command_and_check('status', self._normalise_folder(folder), what_, unpack=True) - _, status_items = parse_response([data]) + data = self._command_and_check('status', self._normalise_folder(folder), what_) + _, status_items = parse_response(data) return dict(as_pairs(status_items)) def close_folder(self): diff --git a/imapclient/test/test_folder_status.py b/imapclient/test/test_folder_status.py new file mode 100644 index 0000000..5bf2c73 --- /dev/null +++ b/imapclient/test/test_folder_status.py @@ -0,0 +1,41 @@ +# Copyright (c) 2015, Menno Smits +# Released subject to the New BSD License +# Please see http://en.wikipedia.org/wiki/BSD_licenses + +from __future__ import unicode_literals + +from .imapclient_test import IMAPClientTest + + +class TestFolderStatus(IMAPClientTest): + + def test_basic(self): + self.client._imap.status.return_value = ( + 'OK', + [b'foo (MESSAGES 3 RECENT 0 UIDNEXT 4 UIDVALIDITY 1435636895 UNSEEN 0)'] + ) + + out = self.client.folder_status('foo') + + self.client._imap.status.assert_called_once_with( + b'"foo"', + '(MESSAGES RECENT UIDNEXT UIDVALIDITY UNSEEN)' + ) + self.assertDictEqual(out, { + b'MESSAGES': 3, + b'RECENT': 0, + b'UIDNEXT': 4, + b'UIDVALIDITY': 1435636895, + b'UNSEEN': 0 + }) + + def test_literal(self): + self.client._imap.status.return_value = ( + 'OK', + [(b'{3}', b'foo'), b' (UIDNEXT 4)'] + ) + + out = self.client.folder_status('foo', ['UIDNEXT']) + + self.client._imap.status.assert_called_once_with(b'"foo"', '(UIDNEXT)') + self.assertDictEqual(out, {b'UIDNEXT': 4}) -- 2.43.0