]> khamidou — GitHub mirrors - imapclient.git/commitdiff
Merged the big search criteria handling change into trunk
authorMenno Smits <menno@freshfoo.com>
Tue, 25 Aug 2015 05:02:41 +0000 (17:02 +1200)
committerMenno Smits <menno@freshfoo.com>
Tue, 25 Aug 2015 05:02:41 +0000 (17:02 +1200)
1  2 
NEWS.rst
imapclient/imapclient.py
imapclient/livetest.py
imapclient/test/test_imapclient.py
imapclient/test/test_search.py

diff --cc NEWS.rst
index 816bf4bc3af66e108489334846d997facb1a9590,82f18da66a4818bd24f5820274f0030d4d2b8080..c383132aecd5ad8a7451be63b727b71853c84443
+++ b/NEWS.rst
@@@ -41,17 -19,67 +41,70 @@@ into these TLS improvements
  
  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
index b3a21c47573bd70e87abcdd080693532c1776c31,2dfe2f5019af9e59bc8b0178cd2c68d7ca4a71bc..7ac6a6715d2c7e2aa1049fff7b2b7ceac53358ba
@@@ -13,8 -13,7 +13,8 @@@ import r
  from datetime import datetime
  from operator import itemgetter
  
- from six import moves, iteritems, text_type, integer_types, PY3, binary_type
++from six import moves, iteritems, text_type, integer_types, PY3, binary_type, iterbytes
 +
  # Confusingly, this module is for OAUTH v1, not v2
  try:
      import oauth2 as oauth_module
Simple merge
Simple merge
index fd3293f5b7809b00a1fda952b811389766f7ab68,99d088bb28e5cdd890927925714d275946dec156..d6b81f5c5056110745a2a321486ec0b2e2149d36
@@@ -81,62 -70,22 +70,22 @@@ class TestSearch(TestSearchBase)
          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"'])