STARTTLS support
----------------
-XXX
+When the server supports it, IMAPClient can now establish an encrypted
+connection after initially connection unencrypted via STARTTLS. The
+starttls method takes an SSL context object for controlling the
+parameters of the TLS negotiation.
-XXX Thank people who contributed (Chris?)
+Many thanks to Chris Arndt for his extensive initial work on this.
- Fixed charset handling for search, sort and thread
- --------------------------------------------------
- The handling of the *charset* argument for the search, sort and thread
- methods has been fixed.
+ More robust criteria handling for search, sort and thread [API]
+ ---------------------------------------------------------------
+ The way search criteria are processed by the various methods that
+ accept them has been changed to allow for easier and more robust
+ handling. In addition, the way the *charset* argument interacts with
+ search criteria has been improved.
+
+ Unfortunately these changes will cause compatibility breaks that may
+ required small changes in code that uses IMAPClient.
+
+ The documentation and tests for search, gmail_search, sort and thread
+ has updated to account for these changes and have also been generally
+ improved.
+
+ The details in the following sections apply to all methods that take
+ search criteria.
+
+ Search criteria
+ ~~~~~~~~~~~~~~~
+ The preferred way to specify criteria is as a list of strings. Valid
+ examples are::
+
+ c.search(['DELETED'])
+ c.search(['NOT', 'DELETED'])
+ c.search(['FLAGGED', 'SUBJECT', 'foo', 'BODY', 'hello world'])
+ c.search(['NOT', 'DELETED', 'SMALLER', 1000])
+
+ IMAPClient will perform all required quoting and encoding. Callers
+ should not attempt to do this themselves.
+
+ Following are some examples of how to update code written against
+ older versions of IMAPClient::
+
+ c.search(['NOT DELETED']) # Before
+ c.search(['NOT', 'DELETED']) # After
+
+ c.search(['TEXT "foo"']) # Before
+ c.search(['TEXT', 'foo']) # After
+
+ c.search(['DELETED', 'TEXT "foo"']) # Before
+ c.search(['DELETED', 'TEXT', 'foo']) # After
+
+ It is possible to pass a single string as the search
+ criteria. IMAPClient will not attempt quoting in this case, allowing
+ lower level specification of criteria. Specifying criteria using a
+ sequence of strings is preferable however. The following examples are
+ valid::
+
+ c.search('ALL')
+ c.search('NOT DELETED')
+ c.search('TEXT "foo"')
+ c.search('DELETED TEXT "foo" SMALLER 500')
+
+ Search charset
+ ~~~~~~~~~~~~~~
+ The way that the search *charset* argument is handled has as also
+ changed.
Any unicode criteria given will now be encoded using the supplied
charset. The charset must refer to an encoding that is capable of
self.assertEqual(result, [1, 2])
self.assertEqual(result.modseq, 51101)
- def test_error_from_server(self):
- self.client._imap.uid.return_value = ('NO', [b'bad karma'])
-
- self.assertRaisesRegex(IMAPClient.Error,
- 'bad karma',
- self.client.search, b'FOO')
-
- class TestGmailSearch(IMAPClientTest):
+ class TestGmailSearch(TestSearchBase):
- def test_with_uid(self):
- self.client.use_uid = True
- self.client._imap.uid.return_value = ('OK', [b'1 2 44'])
+ def test_bytes_query(self):
+ result = self.client.gmail_search(b'foo bar')
- result = self.client.gmail_search('FOO')
-
- self.client._imap.uid.assert_called_once_with(search_command, b'X-GM-RAW')
- self.assertEqual(self.client._imap.literal, b'FOO')
- self.assertEqual(result, [1, 2, 44])
-
- def test_without_uid(self):
- self.client.use_uid = False
- self.client._imap.search.return_value = ('OK', [b'1 2 44'])
-
- result = self.client.gmail_search('FOO')
-
- self.client._imap.search.assert_called_once_with(None, b'X-GM-RAW')
- self.assertEqual(self.client._imap.literal, b'FOO')
- self.check_call([b'X-GM-RAW', b'"foo bar"'])
++ self.check_call([b'CHARSET', b'UTF-8', b'X-GM-RAW', b'"foo bar"'])
self.assertEqual(result, [1, 2, 44])
- def test_with_uid_with_charset(self):
- self.client.use_uid = True
- self.client._imap.uid.return_value = ('OK', [b'1 2 44'])
-
- result = self.client.gmail_search('\u2620', 'UTF-8')
-
- self.client._imap.uid.assert_called_once_with(
- search_command,
- b'CHARSET', b'UTF-8',
- b'X-GM-RAW')
- self.assertEqual(self.client._imap.literal, b'\xe2\x98\xa0')
- self.assertEqual(result, [1, 2, 44])
-
- def test_without_uid_with_charset(self):
- self.client.use_uid = False
- self.client._imap.search.return_value = ('OK', [b'1 2 44'])
-
- result = self.client.gmail_search('\u2620', 'UTF-8')
+ def test_bytes_query_with_charset(self):
+ result = self.client.gmail_search(b'foo bar', 'utf-42')
- self.client._imap.search.assert_called_once_with(b'UTF-8', b'X-GM-RAW')
- self.assertEqual(self.client._imap.literal, b'\xe2\x98\xa0')
+ self.check_call([b'CHARSET', b'utf-42', b'X-GM-RAW', b'"foo bar"'])
self.assertEqual(result, [1, 2, 44])
- def test_error_from_server(self):
- self.client._imap.uid.return_value = ('NO', [b'bad karma'])
+ def test_unicode_criteria_with_charset(self):
+ self.client.gmail_search('foo \u2639', 'utf-8')
- self.assertRaisesRegex(IMAPClient.Error,
- 'bad karma',
- self.client.gmail_search, b'FOO')
+ self.check_call([b'CHARSET', b'utf-8', b'X-GM-RAW', b'"foo \xe2\x98\xb9"'])