Python3 IMAP search special characters

夙愿已清 提交于 2019-12-12 05:17:10

问题


I would like to find a note over IMAP using Python3 and it's IMAP extension. I try to search for a subject which contains special chars as in the example below. Is there a way I can encode the search string to be IMAP compatible?

self.connection.search(None, 'ALL', 'SUBJECT "büro"')

returns

UnicodeEncodeError: 'ascii' codec can't encode character '\xfc' in position 10: ordinal not in range(128)

回答1:


You should pass UTF-8 encoded string as the search argument and also need to mention "CHARSET UTF-8" in the search query.

some thing like this UID SEARCH CHARSET utf-8 "search string". Here "search string" should be utf-8 encoded.



来源:https://stackoverflow.com/questions/28375714/python3-imap-search-special-characters

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