Python3 IMAP search special characters

2019-09-03 09:44发布

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条回答
老娘就宠你
2楼-- · 2019-09-03 10:22

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.

查看更多
登录 后发表回答