mscdex / node-imap

An IMAP client module for node.js.
MIT License
2.17k stars 382 forks source link

Search with accented characters #802

Closed berengerzyla closed 4 years ago

berengerzyla commented 4 years ago

Hi!

I have an issue with the imap.search when searching in text parts of the message (subject, body..). Let's say I'm looking for Montréal in the subject.

(they're 5 different messages, the numbers are the uids).

The specified charset is not supported. and textCode: { key: 'BADCHARSET', val: [ 'US-ASCII' ] },

What I am missing? How to run a search with special characters?

Reading messages does not show any issue, just the search.

Many thanks!

mscdex commented 4 years ago

AFAIK non-ASCII strings should be automatically detected and handled appropriately. This can be verified by setting debug: console.log and checking that there is a string "literal" instead of a quoted string for the particular string in the search command sent to the server.

The string literal in the debug output will probably look something like this:

{9}
Montréal
berengerzyla commented 4 years ago
...
<= '+ IDLE accepted, awaiting DONE command.'
=> DONE
<= 'IDLE OK IDLE completed.'
=> 'A6 UID SEARCH CHARSET UTF-8 ALL SUBJECT {9}'
<= '+ Ready for additional command text.'
=> 'Montréal\r\n'
<= 'A6 NO [BADCHARSET (US-ASCII)] The specified charset is not supported.'
=> 'IDLE IDLE'

Encoding seems fine when sent. The line-break is not in my original string, I assume the lib does it? This is an Outlook (Office365) server behind that, which seems to only accept US-ASCII, when we send a search with CHARSET UTF-8. Any way to make them talk without conflict? Thanks!

mscdex commented 4 years ago

From my brief google search, it appears Office 365 does not support UTF-8 via IMAP, only US-ASCII, so I'm not sure there's much that can be done client-side. Not supporting UTF-8 in 2020 is absurd, especially for a company/product that large.

berengerzyla commented 4 years ago

OK, and this seems like a final blow to it. https://stackoverflow.com/a/55977511

I'll change my way to go though an API, instead of IMAP. Thanks for checking with me! (and yup, it's a bummer, coming from Microsoft...)