I'm looking for an IMAP search clause to get GMail's "[Gmail]/All Mail" contents but filter out mails which are in "[Gmail]/Drafts".
IMAP DRAFT flag doesn't help with GMail's IMAP. By comparing full headers, I've noticed that drafts don't have value in "Delivered-To" field - it's missing from the header for all messages in "[Gmail]/Drafts".
I've tried UID search directly on "[Gmail]/Drafts" which has a few messages with following clause/results:
I'm expecting to get a clause which returns no messages - or all messages which have Delivered-To absent:
(HEADER Delivered-To "") <- returns all drafts
(NOT (HEADER Delivered-To "")) <- negating still returns all drafts!
(NOT HEADER Delivered-To "") <- still returns all drafts
(HEADER Delivered-To NIL) <- returns no messages - opposite to expected
(NOT (HEADER Delivered-To NIL)) <- returns all drafts
(NOT HEADER Delivered-To NIL) <- returns all drafts
(NOT (DRAFT)) <- returns all drafts
(DRAFT) <- returns none - opposite to expected, GMail doesn't seem to flag drafts with DRAFT
Will appreciate suggestions for how would you formulate "HEADER Delivered-To is not empty" for GMail IMAP.
UID SEARCH NOT X-GM-LABELS \Draft
? Gmail IMAP Extensions includes Search Terms for labels, which seems more to be what you want. – Max29:27.40 imap.gmail.com writer > BGOD4 UID SEARCH (X-GM-LABELS (\Drafts))\r\n 29:27.50 imap.gmail.com reader < BGOD4 BAD Could not parse command\r\n
– kuz8> NBHH4 UID SEARCH (X-GM-LABELS foo)\r\n < * SEARCH\r\n
, the question is how to search for \Drafts.. I'm using Python's imaplib2 if it makes any difference.. Sometimes it duplicates \ as \\.. So still> HIPP4 UID SEARCH (X-GM-LABELS (\Drafts))\r\n < HIPP4 BAD Could not parse command\r\n
and without parens> HNEN4 UID SEARCH (X-GM-LABELS \Drafts)\r\n < HNEN4 BAD Could not parse command\r\n
– kuz8status, uidsString = M.uid('search', None, '(X-GM-LABELS "\Drafts")')
results in> OONJ4 UID SEARCH (X-GM-LABELS "\Drafts")\r\n < OONJ4 BAD Could not parse command\r\n
; but double (*2) slash treated as non-existing labelM.uid('search', None, '(X-GM-LABELS "\\\\Drafts")')
results in legal search but no results> OCIF4 UID SEARCH (X-GM-LABELS "\\Drafts")\r\n < * SEARCH\r\n
– kuz8