Following on from last week's
post</a> about the upcoming
IMAPClient 1.0 release, I'd like to draw attention to some significant,
compatibility breaking changes related to the handling of search
criteria.</p>
IMAPClient's methods that accept search criteria
(search</a>,
sort</a>,
thread</a>,
gmail_search</a>)
have been changed to provide take criteria in a more straightforward and
robust way. In addition, the way the charset</em> argument interacts with
search criteria has been improved. These changes make it easier to pass
search criteria and have them handled correctly but unfortunately also
mean that small changes may be required to existing code that uses
IMAPClient.</p>
The preferred way to specify criteria now is as a list of strings, ints
and dates (where relevant). The list should be flat with all the
criteria parts run together. Where a criteria takes an argument, just
provide it as the next element in the list.</p>
Some valid examples:</p>
IMAPClient will perform all required conversion, quoting and encoding.
Callers do not need to and should not attempt to do this themselves.
IMAPClient will automatically send criteria parts as IMAP literals when
required (i.e. when the encoded part is 8-bit).</p>
Some previously accepted ways of passing search criteria will not work
as they did in previous versions of IMAPClient. Small changes will be
required in these cases. Here are some examples of how to update code
written against older versions of IMAPClient:</p>
It is also possible to pass a single string as the search criteria.
IMAPClient will not attempt quoting in this case, allowing the caller to
specify search criteria at a lower level. Specifying criteria using a
sequence of strings is preferable however. The following examples
(equivalent to those further above) are valid:</p>
The way that the search charset</em> argument is handled has also changed.</p>
Any unicode criteria arguments will now be encoded by IMAPClient using
the supplied charset. The charset must refer to an encoding that is
capable of handling the criteria's characters or an error will occur.
The charset must obviously also be one that the server supports! (UTF-8
is common)</p>
Any criteria given as bytes will not be changed by IMAPClient, but the
provided charset will still be passed to the IMAP server. This allows
already encoding criteria to be passed through as-is. The encoding
referred to by charset</em> should match the actual encoding used for the
criteria.</p>
The following are valid examples:</p>
The documentation and tests for search, gmail_search, sort and thread
has updated to account for these changes and have also been generally
improved.</p>
For those willing to try out the changes now please install from
IMAPClient's tip. Any feedback on the changes and/or documentation would
be hugely appreciated.</p>Search criteria</h1>
c.search([</span>'DELETED'</span>])</span></span>
c.search([</span>'NOT'</span>,</span> 'DELETED'</span>])</span></span>
c.search([</span>'FLAGGED'</span>,</span> 'SUBJECT'</span>,</span> 'foo'</span>,</span> 'BODY'</span>,</span> 'hello world'</span>])</span></span>
c.search([</span>'NOT'</span>,</span> 'DELETED'</span>,</span> 'SMALLER'</span>,</span> 1000</span>])</span></span>
c.search([</span>'SINCE'</span>, date(</span>2006</span>,</span> 5</span>,</span> 3</span>)])</span></span></code></pre>
c.search([</span>'NOT DELETED'</span>])</span> # Before</span></span>
c.search([</span>'NOT'</span>,</span> 'DELETED'</span>])</span> # After</span></span>
</span>
c.search([</span>'TEXT "foo"'</span>])</span> # Before</span></span>
c.search([</span>'TEXT'</span>,</span> 'foo'</span>])</span> # After (IMAPClient will add the quotes)</span></span>
</span>
c.search([</span>'DELETED'</span>,</span> 'TEXT "foo"'</span>])</span> # Before</span></span>
c.search([</span>'DELETED'</span>,</span> 'TEXT'</span>,</span> 'foo'</span>])</span> # After</span></span>
</span>
c.search([</span>'SMALLER 1000'</span>])</span> # Before</span></span>
c.search([</span>'SMALLER'</span>,</span> 1000</span>])</span> # After</span></span></code></pre>
c.search(</span>'DELETED'</span>)</span></span>
c.search(</span>'NOT DELETED'</span>)</span></span>
c.search(</span>'FLAGGED SUBJECT "foo" BODY "hello world"'</span>)</span></span>
c.search(</span>'NOT DELETED SMALLER 1000'</span>)</span></span>
c.search(</span>'SINCE 03-May-2006'</span>)</span></span></code></pre>Search charset</h1>
c.search([</span>'TEXT'</span>,</span> u</span>'</span>\u263a</span>'</span>],</span> 'utf-8'</span>)</span> # IMAPClient will apply UTF-8 encoding</span></span>
c.search([</span>b</span>'TEXT'</span>,</span> b</span>'</span>\xe2\x98\xba</span>'</span>],</span> 'utf-8'</span>)</span> # Caller has already applied UTF-8 encoding</span></span></code></pre>
This page cannot be shown here. You can still read it on the original site — the toolbar below keeps your place in the directory.
Following on from last week's post about the upcoming IMAPClient 1.0 release, I'd like to draw attention to some significant, compatibility breaking changes related to the handling of search criteria. IMAPClient's methods that accept search criteria ( search , sort , thread , gmail_search ) have been changed to provide take criteria in a more straightforward and robust way. In…
Comments
Nothing yet. Say the first thing.
Sign in to join the conversation.