Gmail doesn’t send “OK [UNSEEN n]” when required
In IMAP protocol OK [UNSEEN <n>]
is a required untagged response to SELECT command. Core IMAP specification (RFC 3501) along with the errata states:
Responses: REQUIRED untagged responses: FLAGS, EXISTS, RECENT
REQUIRED OK untagged responses: PERMANENTFLAGS,
UIDNEXT, UIDVALIDITY, UNSEEN (if any unseen exist)
and later:
If there are any unseen messages in the mailbox, an UNSEEN response MUST be sent, if not it MUST be omitted.
However Gmail IMAP server doesn’t send the OK [UNSEEN <n>]
response, even when there are unseen emails in the mailbox. The following listing shows that (note the subsequent SEARCH command that returns a single email):
C: c7a56 SELECT "INBOX"
S: * FLAGS (\Answered \Flagged \Draft \Deleted \Seen $Phishing $MDNSent NonJunk $NotPhishing Junk)
S: * OK [PERMANENTFLAGS (\Answered \Flagged \Draft \Deleted \Seen $Phishing $MDNSent NonJunk $NotPhishing Junk \*)] Flags permitted.
S: * OK [UIDVALIDITY 3] UIDs valid.
S: * 7619 EXISTS
S: * 0 RECENT
S: * OK [UIDNEXT 30566] Predicted next UID.
S: * OK [HIGHESTMODSEQ 2384884]
S: c7a56 OK [READ-WRITE] INBOX selected. (Success)
C: a7c39 UID SEARCH UNSEEN
S: * SEARCH 30565
S: a7c39 OK SEARCH completed (Success)