How do I formulate search for "HEADER Delivered-To is not empty" in GMail IMAP? (or SEARCH "[Gmail]/All Mail" and exclude "/Drafts")

StackOverflow https://stackoverflow.com/questions/18179201

  •  24-06-2022
  •  | 
  •  

Pergunta

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.

Foi útil?

Solução 2

Though not a direct answer, I ended up downloading bodies of new messages and scanning them for flags.

Outras dicas

x uid search header "delivered-to" "@"

The HEADER key searches for a header field with the given name containing the given substring. That is, header "foo" "" searches for messages that have a foo header field, empty or not. There is no proper way to search for messages that have a nonempty field.

However, you can get around that with a hack in this case: Every nonempty Delivered-To contains an @ sign, so just search for @ and you get the result you want.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top