eclipse-ee4j / eclipse-ee4j/angus-mail
office365 search fails with NO [BADCHARSET (US-ASCII)]
- Dominant language
- Java
- Stars
- 87
- Forks
- 23
- PR merge metrics
- No merged PRs in 30d
Description
In testing for https://github.com/eclipse-ee4j/angus-mail/issues/104 I observed that IMAP search in Office365 returns NO [BADCHARSET (US-ASCII)] The specified charset is not supported. This error is reporting that for search only US-ASCII is the only supported charset parameter for search. In JakartaMail, we can set the `mail.mime.charset` to try to force US-ASCII as the charset used for search but JakartaMail will canonicalize US-ASCII to ISO-8859-1 which is not allowed as the search charset for Office365. The only way to make server side searching in Office365 work would be to set `mail.mime.charset=US-ASCII` and ship META-INF/javamail.charset.map file that doesn't have the mime2java mapping of us-ascii=ISO-8859-1.
Searching still work (by default) though because AngusMail will fallback to performing the search on the client size by fetching the envelope of every message which is slow.
The changes to explore for this ticket are:
1. Update IMAPProtocol.searchCharsets array to include an entry for `US-ASCII`.
2. SearchQuery doesn't report encoding errors which changes the flow in IMAPFolder. The main issue is that server side search can return zero results but the reason it returned zero results was due to the fact that the bytes generated can't be encoded correctly. Instead an IOException should have been generated. (Move this to a new ticket)
3. Review the IMAP RFC to see if BADCHARSET response codes have been added to the spec. This would allow us to parse the returned list of supported charsets from a BADCHARSET and add them to the IMAPProtocol.searchCharsets. We could consider doing this anyway if it is not in spec.
Contributor guide
Assessment
This issue has not been assessed yet.