]> khamidou — GitHub mirrors - imapclient.git/commitdiff
Correctly handle literals in STATUS responses
authorMenno Smits <menno@freshfoo.com>
Tue, 1 Sep 2015 05:46:37 +0000 (17:46 +1200)
committerMenno Smits <menno@freshfoo.com>
Tue, 1 Sep 2015 05:46:37 +0000 (17:46 +1200)
Also added missing unit tests for folder_status().
Fixes #174.

NEWS.rst
imapclient/imapclient.py
imapclient/test/test_folder_status.py [new file with mode: 0644]

index 096c736449c4a5a8804047e6fdf479a588dba3f2..0399361f06b2dde780a2405cf2d5411d5ddd186d 100644 (file)
--- 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
index 9febb7b1d36cc6f259ab5624ff5e9c2262ea1a21..3b29063e3aef5d189063b8ea0e50580f2aa72d4d 100644 (file)
@@ -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 (file)
index 0000000..5bf2c73
--- /dev/null
@@ -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})