title: Gmail IMAP NOT command improperly implemented?
body: <p>The following IMAP session seems to indicate a bug in Gmail's implementation of IMAP:</p>
  
  <pre><code>T SEARCH NOT X-GM-RAW "-label:drafts"
  * SEARCH 1 2 3 4 5 6 7 8
  T OK SEARCH completed (Success)
  T SEARCH X-GM-RAW "-label:drafts"
  * SEARCH 1 2 3 4 5 6 7 8
  T OK SEARCH completed (Success)
  </code></pre>
  
  <p>Note this behavior does not reproduce if I use a different argument to <code>X-GM-RAW</code>:</p>
  
  <pre><code>T SEARCH NOT X-GM-RAW "label:drafts" 
  * SEARCH 1 2 3 4 5 6 7 8
  T OK SEARCH completed (Success)
  t SEARCH X-GM-RAW "label:drafts"
  * SEARCH 9
  t OK SEARCH completed (Success)
  </code></pre>
  
  <p><code>X-GM-RAW</code> is of course a Gmail IMAP extension (documented <a href="https://developers.google.com/gmail/imap_extensions" rel="nofollow">here</a>), but its results should be opaque.</p>
  
  <p>I am the only person with credentials to the account being tested. No mail should be moved while I am testing and I have verified that I am the only person who has accessed the account.</p>
  
  <p>Is this actually buggy behavior or am I misunderstanding IMAP?</p>
  
  <p>In any case a reasonable patch seems to be to only use the positive search <code>label:drafts</code> and invert it in the IMAP layer, not within the raw search itself.</p>