]> khamidou — GitHub mirrors - imapclient.git/commitdiff
Clear cached capabilities after successful STARTTLS
authorMenno Smits <menno@freshfoo.com>
Tue, 14 Jul 2015 00:47:01 +0000 (12:47 +1200)
committerMenno Smits <menno@freshfoo.com>
Tue, 14 Jul 2015 00:47:01 +0000 (12:47 +1200)
imapclient/imapclient.py
imapclient/test/test_starttls.py

index b08e922df35e626f203363037f05c2bcca2da63e..19e50eeee51a9476b673f2b9ba9c3448e8f4bab8 100644 (file)
@@ -183,6 +183,11 @@ class IMAPClient(object):
         self._checkok('starttls', typ, data)
 
         self._starttls_done = True
+
+        # Clear cached capabilities as per
+        # https://tools.ietf.org/html/rfc2595#section-3.1
+        self._cached_capabilities = None
+
         self._imap.sock = tls.wrap_socket(self._imap.sock, self.host, ssl_context)
         self._imap.file = self._imap.sock.makefile()
         return data[0]
index a8ad7ee3b659a7a3d6f73cec5d56e7fc52a959d9..8ef8f99ea26a51b42665b6574b361dbdb8f1f8ef 100644 (file)
@@ -42,6 +42,19 @@ class TestStarttls(IMAPClientTest):
         self.assertEqual(self.client._imap.file, sentinel.file)
         self.assertEqual(resp, b'start TLS negotiation')
 
+    def test_clears_cached_capabilities(self):
+        # As per https://tools.ietf.org/html/rfc2595#section-3.1
+
+        self.client._save_capabilities(b"FOO BAR")
+        self.assertEqual(self.client.capabilities(), (b"FOO", b"BAR"))
+
+        self.client.starttls(sentinel.ssl_context)
+
+        # Now verify that the cache has been cleared and new
+        # capabilities are read.
+        self.client._imap.untagged_responses = {'CAPABILITY': [b'META']}
+        self.assertEqual(self.client.capabilities(), (b"META",))
+
     def test_command_fails(self):
         self.client._imap._simple_command.return_value = "NO", [b'sorry']