Search code examples
imap

IMAP BAD [CLIENTBUG] Invalid tag


I want send IMAP command so that I can receive IMAP response.

So a short code that easy for undertanding but save space to prevent type all code and faster for the Overflow reader:

SSL_write("a0001 login user pass")

SSL_read = "* CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS COMPRESS=DEFLATE ENABLE MOVE CONDSTORE ESEARCH UTF8=ACCEPT
a0001 OK [email protected] authenticated (Success)

OK, now everything ok, but here is where problem that is small start:

SSL_write("a0002 select inbox\r\n\r\n")

SSL_read = * BAD [CLIENTBUG] Invalid tag
* FLAGS (\Answered \Flagged \Draft \Deleted \Seen $Phishing $NotPhishing)
* OK [PERMANENTFLAGS (\Answered \Flagged \Draft \Deleted \Seen $Phishing $NotPhishing \*)] Flags permitted.
* OK [UIDVALIDITY 1] UIDs valid.
* 7958 EXISTS
* 0 RECENT
* OK [UIDNEXT 22979] Predicted next UID.
* OK [HIGHESTMODSEQ 2553479]
a0002 OK [READ-WRITE] inbox selected. (Success)

Any time after login when I send the IMAP command to get the IMAP response, always the first thing I receive is

* BAD [CLIENTBUG] Invalid tag

After it tell me BAD it then give me proper response and tell me (Success).

Is very confusing to me because I give correct tag. I use OpenSSL on linux platform.

This example with gmail server but happen on all IMAP server tested. Login is perfect and everything else start with "Invalid tag" then give me correct response.

Do you know what I do wrong and how to prevent this? Thanks you very much. My kindest regard.


Solution

  • The problem is here:

    SSL_write("a0002 select inbox\r\n\r\n")
    

    Only write one CRLF:

    SSL_write("a0002 select inbox\r\n")
    

    You've unintentionally sent two commands. One is the command you wanted, one was the empty command, which has no (an invalid) tag.