I am trying to perform IMAP SEARCH on Gmail mailbox using IMAP. In particular, I am trying to find a UID of a message with a known Message-ID header. I know this message exists, as I just added it (and I can find it the following search query Rfc822msgid:<D7DA993B.B30DC%psztxa@exmail.nottingham.ac.uk>
in Gmail UI). The problem occurs only when the Message-ID field contains "%". I've tried to quote it in several ways, with no luck:
No quoting:
SEND: "000004 UID SEARCH HEADER Message-ID <D7DA993B.B30DC%psztxa@exmail.nottingham.ac.uk>"
SEND: "\r\n"
RECV: "000004 BAD Could not parse command\r"
Backslash quoting:
SEND: "000004 UID SEARCH HEADER Message-ID <D7DA993B.B30DC\\%psztxa@exmail.nottingham.ac.uk>"
SEND: "\r\n"
RECV: "000004 BAD Could not parse command\r"
Backslash and double-quotes:
SEND: "000004 UID SEARCH HEADER Message-ID \"<D7DA993B.B30D\\%psztxa@exmail.nottingham.ac.uk>\""
SEND: "\r\n"
RECV: "000004 BAD Could not parse command\r"
Finally, using just double-quotes passes without giving error, but fails to find the message:
SEND: "000004 UID SEARCH HEADER Message-ID \"<D7DA993B.B30DC%psztxa@exmail.nottingham.ac.uk>\""
SEND: "\r\n"
RECV: "* SEARCH\r"
RECV: "000004 OK SEARCH completed (Success)\r"
Following this question I also tried to search fragments of message ID, with no luck:
HaskellNet-SSL SEND: "000004 UID SEARCH HEADER Message-ID D7DA993B.B30DC HEADER Message-ID psztxa@exmail.nottingham.ac.uk"
HaskellNet-SSL SEND: "\r\n"
HaskellNet-SSL RECV: "* SEARCH\r"
HaskellNet-SSL RECV: "000004 OK SEARCH completed (Success)\r"
How can I format a search query to find the message with '%' in Message-Id?