IMAP search for non-ascii characters

和自甴很熟 提交于 2020-01-05 13:08:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!