Closed josdejong closed 4 years ago
I figured it out:
Email email = ...
Attachment htmlBody = email.htmlEmailBody;
if (htmlBody != null) {
String html = IOUtils.toString(htmlBody.getIs(), htmlBody.getBd().getCharset());
}
Here getBd()
returns a BodyDescriptor
with the parsed content type, charset, etc.
Hi,
I am happy that the library is proving to be a great help to you.
The solution you found out for your problem is correct.
Meanwhile the test case that you have cited is to handle special case of handling chinese character set only. Sometimes the charset specified in the email is not sufficient enough to decode all the characters of the email text, the problem is probably because some character set implementations are buggy. So for those cases the chinese character set that covers all the possible characters available for decoding is used. 'GB18030' is one such chinese character set.
Ah, thanks for the clarification. Nice that its possible to select your own charset if needed.
First, thanks for sharing this library, it works like a charm :+1:
I sometimes have emails containing a charset like
iso-8859-1
in an email:Using
htmlEmailBody
I get anAttachment
with an input stream. When turning the stream into a string, I have to know which charset is used to encode the email. But how can get this information from the email?See also the following test of this library, where a hardcoded charset
"GB18030"
is used to decode. How can I determine that encoding from the email itself? https://github.com/ram-sharma-6453/email-mime-parser/blob/c304baf8948a30a124ba6e2c6ba8dfb27bf41c9f/src/test/java/tech/blueglacier/parser/ParserTest.java#L264-L270