Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.io.UnsupportedEncodingException: en_US.iso885915 if charset is "en_US.iso885915" #107

Closed
jamejose opened this issue Aug 23, 2023 · 3 comments
Assignees

Comments

@jamejose
Copy link

We embed Angus mail Jars in IBM App Connect Enterprise in order to provide email functionalities.

When an attempt is made to get the content of the email using 'getContent()' API, it is failing with following exception for one particular scenario for our clients.

'java.io.UnsupportedEncodingException: en_US.iso885915 at sun.nio.cs.StreamDecoder.forInputStreamReader(StreamDecoder.java:104) at java.io.InputStreamReader.(InputStreamReader.java:121) at com.sun.mail.handlers.text_plain.getContent(text_plain.java:59) at jakarta.activation.DataSourceDataContentHandler.getContent(DataHandler.java:768) at jakarta.activation.DataHandler.getContent(DataHandler.java:514) at jakarta.mail.internet.MimeBodyPart.getContent(MimeBodyPart.java:659)

Here the email is having 'Content-Type: text/html; charset="en_US.iso885915" header. 'en_US.iso885915' is not a valid charSet in java and is the reason for the above exception.

On looking at the source code, it looks like the jar file is having javamail.charset.map file to map the charSets. If we add a mapping for en_US.iso885915 the error can be avoided ie add 'en_US.iso885915 ISO-8859-15' to the jakarta.mail-2.0.2.jar/META-INF/javamail.charset.map file.

Could you please advise whether this is a valid change to have and avoid the error. If so, can this change be included in future releases of jakarta-mail jar.

Following are the version of jars in use :

jakarta.mail-2.0.2.jar
((The Angus Mail implementation jar file, including the Jakarta Mail API, SMTP, IMAP, and POP3 protocol providers and java.util.logging handler)
angus-activation-2.0.1.jar
jakarta.activation-api-2.1.2.jar

To Reproduce
Create a mail with 'Content-Type: text/html; charset="en_US.iso885915"
Invoke getContent() API on the email and it fails.

Expected behavior
To process the email even if it uses charset="en_US.iso885915"

Desktop (please complete the following information):

  • OS: Windows

Mail server:

  • Protocol being used: IMAP
  • Mail service URL: [e.g. gmail.com]
@jmehrens
Copy link
Contributor

jmehrens commented Sep 7, 2023

Could you please advise whether this is a valid change to have and avoid the error.

It should work but, there are some alternatives to consider:

  1. Add the charset to the JDK using: Why do I get the UnsupportedEncodingException when I invoke getContent() on a bodypart that contains text data?. This the most wide spread change you can make.
  2. Hookup the mail.mime.contenttypehandler callback so you can clean the header: Is there a way to add aliases for Java's Charset names. This keeps the mapping local to your code without modifying the jar files.

Could you please advise whether this is a valid change to have and avoid the error. If so, can this change be included in future releases of jakarta-mail jar.

It is something to consider. When I check the jakarta.mail.internet.MimeUtility we already have mappings that include a locale. We might have to include other locale prefixes.

Do you know what mailer generated this content-type header?

@jmehrens jmehrens self-assigned this Sep 7, 2023
@jamejose
Copy link
Author

In my customer case it looks like they were using Outlook. But the problem can be recreated with any mail server and if we set 'Content-Type: text/html; charset="en_US.iso885915" header in the outgoing email.

@jmehrens
Copy link
Contributor

Committed to 2.0.3 as:

fd8a2e6

I added the mapping. It looks like there are other variants of this. I think if we need to revisit this for more mappings then I think we need to look at modifying the MimeUtility to perform a table lookup then charset lookup and if that fails substring the charset so there is no locale and try again. However, there could be issues with doing that too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants