mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-04 16:16:33 +02:00
Added/improved charset mapping
This commit is contained in:
@@ -1251,28 +1251,27 @@ public class MessageHelper {
|
||||
|
||||
try {
|
||||
ContentType ct = new ContentType(part.getContentType());
|
||||
|
||||
String charset = ct.getParameter("charset");
|
||||
|
||||
// Fix common mistakes
|
||||
if (charset != null) {
|
||||
if (charset == null)
|
||||
charset = StandardCharsets.ISO_8859_1.name();
|
||||
else {
|
||||
charset = charset.replace("\"", "");
|
||||
if ("ASCII".equals(charset.toUpperCase()))
|
||||
charset = "US-ASCII";
|
||||
else if (charset.toLowerCase().endsWith("8859-16")) // not supported by Android
|
||||
charset = null; // Use ISO8859-1 instead
|
||||
}
|
||||
charset = MimeUtility.javaCharset(charset);
|
||||
|
||||
if (TextUtils.isEmpty(charset) || "US-ASCII".equals(charset.toUpperCase())) {
|
||||
// The first 127 characters are the same as in US-ASCII
|
||||
result = new String(result.getBytes(StandardCharsets.ISO_8859_1));
|
||||
} else {
|
||||
// See UnknownCharsetProvider class
|
||||
if ("US-ASCII".equals(Charset.forName(charset).name())) {
|
||||
Log.w("Unsupported encoding charset=" + charset);
|
||||
if (!Charset.isSupported(charset)) {
|
||||
// x-binaryenc
|
||||
// UseInqueCodePage
|
||||
// none
|
||||
// unknown-8bit
|
||||
// X-UNKNOWN
|
||||
Log.e("Unsupported encoding charset=" + charset);
|
||||
warnings.add(context.getString(R.string.title_no_charset, charset));
|
||||
result = new String(result.getBytes(StandardCharsets.ISO_8859_1));
|
||||
charset = StandardCharsets.ISO_8859_1.name();
|
||||
}
|
||||
}
|
||||
|
||||
result = new String(result.getBytes(Charset.forName(charset)));
|
||||
} catch (ParseException ex) {
|
||||
Log.w(ex);
|
||||
warnings.add(Log.formatThrowable(ex, false));
|
||||
|
||||
Reference in New Issue
Block a user