问题
What is the COMMAND used to search for non ascii or Japanese characters in IMAP GMAIL server?
回答1:
The correct way is to use a CHARSET UTF-8 SEARCH with a literal. For example (each line ends with a \r\n):
> tag UID SEARCH CHARSET UTF-8 TEXT {4}
< + go ahead
> term
< * SEARCH 700 701 702
< tag OK SEARCH done
term should be UTF-8 encoded, and the 4 should be the length of the search therm, in bytes after encoding.
For example, to search for the term 日本 which is \xE6\x97\xA5\xE6\x9C\xAC in UTF-8 encoding (6 bytes)
> tag UID SEARCH CHARSET UTF-8 TEXT {6}
< + go ahead
> <6 bytes of binary data>
< * SEARCH 700 701 702
< tag OK SEARCH done
You can use different search keys besides TEXT
, such as BODY
or TO
. Searching in utf-8 should work on any reasonable IMAP server. Other character sets are less likely to be supported.
来源:https://stackoverflow.com/questions/27502901/imap-search-for-non-ascii-characters