From 7b010d5a66ef5ab8411bf218e70995850d7c53a8 Mon Sep 17 00:00:00 2001 From: Menno Smits Date: Tue, 1 Sep 2015 15:30:42 +1200 Subject: [PATCH] Added a "shutdown" method. Allows closing of the underlying socket. Closes #173. --- NEWS.rst | 3 +++ imapclient/imapclient.py | 8 ++++++++ imapclient/test/test_imapclient.py | 7 +++++++ 3 files changed, 18 insertions(+) diff --git a/NEWS.rst b/NEWS.rst index f9a5417..096c736 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -144,6 +144,9 @@ Other easier to use any unicode string as a search string and is safe because Gmail supports UTF-8 search criteria. * PEP8 compliance fixed (except for some occasional long lines) + * Added a "shutdown" method. + * The embedded six package has been removed in favour of using an + externally installed instance. ====== 0.13 diff --git a/imapclient/imapclient.py b/imapclient/imapclient.py index 2760584..9febb7b 100644 --- a/imapclient/imapclient.py +++ b/imapclient/imapclient.py @@ -251,6 +251,14 @@ class IMAPClient(object): self._check_resp('BYE', 'logout', typ, data) return data[0] + def shutdown(self): + """Close the connection to the IMAP server (without logging out) + + In most cases, :py:meth:`.logout` should be used instead of + this. The logout method also shutdown down the connection. + """ + self._imap.shutdown() + def id_(self, parameters=None): """Issue the ID command, returning a dict of server implementation fields. diff --git a/imapclient/test/test_imapclient.py b/imapclient/test/test_imapclient.py index e49e59f..7cf1aff 100644 --- a/imapclient/test/test_imapclient.py +++ b/imapclient/test/test_imapclient.py @@ -599,3 +599,10 @@ class TestRawCommand(IMAPClientTest): expected_error = "unexpected response while waiting for continuation response: \(u?'NO', \[u?'go away'\]\)" with self.assertRaisesRegex(IMAPClient.AbortError, expected_error): self.client._raw_command(b'FOO', [b'\xff']) + + +class TestShutdown(IMAPClientTest): + + def test_shutdown(self): + self.client.shutdown() + self.client._imap.shutdown.assert_called_once_with() -- 2.43.0