From: Menno Smits Date: Tue, 14 Jul 2015 00:47:01 +0000 (+1200) Subject: Clear cached capabilities after successful STARTTLS X-Git-Tag: 1.0.0~1^2~57^2~12 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=3890d7e3a4b45488fbe05d8e321fbf373bc01338;p=imapclient.git Clear cached capabilities after successful STARTTLS --- diff --git a/imapclient/imapclient.py b/imapclient/imapclient.py index b08e922..19e50ee 100644 --- a/imapclient/imapclient.py +++ b/imapclient/imapclient.py @@ -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] diff --git a/imapclient/test/test_starttls.py b/imapclient/test/test_starttls.py index a8ad7ee..8ef8f99 100644 --- a/imapclient/test/test_starttls.py +++ b/imapclient/test/test_starttls.py @@ -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']