0

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?

krokodil
  • 1,326
  • 10
  • 18
  • A workaround is to use X-GM-RAW Gmail IMAP extension. – krokodil Mar 11 '21 at 05:40
  • Your last two searches are correct and should work. It's a server bug. – arnt Mar 11 '21 at 09:07
  • Hi there! I have been studying your situation without much success. To better understand the setup, could you please describe what steps are you taking from scratch? Also, do you receive any additional messages? – Jacques-Guzel Heron Mar 16 '21 at 16:00
  • @Jacques-GuzelHeron Here is a blog post with more detail. http://lambda-files.crocodile.org/2021/03/importing-mail-from-google-takout-into.html It is a Gmail IMAP implementation bug. – krokodil Mar 18 '21 at 20:21
  • Based on those references I recommend you to report this on [Issue Tracker](https://developers.google.com/issue-tracker/guides/create-issue-ui). I beg you to please understand that replication steps or further explanations about the IMAP protocol are needed. – Jacques-Guzel Heron Mar 24 '21 at 12:19

0 Answers0