From 4e1e9db31494634b3eec0e14be562814f9b3bc52 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 25 Sep 2019 08:32:05 +0200 Subject: [PATCH] Charset improvements --- FAQ.md | 3 +++ app/src/main/java/eu/faircode/email/MessageHelper.java | 8 ++++++-- .../java/eu/faircode/email/UnknownCharsetProvider.java | 6 ++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/FAQ.md b/FAQ.md index 97dffea448..3c1292af57 100644 --- a/FAQ.md +++ b/FAQ.md @@ -718,6 +718,9 @@ Account permissions are required to periodically refresh the [OAuth](https://dev (a kind of password used to login to your Gmail account). Just start the wizard (but do not select an account) to grant the required permissions again. +The warning *... Unsupported encoding ...* means that the character set of the message is unknown or not supported. +FairEmail will assume ISO-8859-1 (Latin1), which will in most cases result in showing the message correctly. + See [here](https://linux.die.net/man/3/connect) for what error codes like EHOSTUNREACH and ETIMEDOUT mean. Possible causes are: diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index f8662fbf7a..7e14d5310e 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -882,15 +882,19 @@ public class MessageHelper { if (charset != null) { charset = charset.replace("\"", ""); if ("ASCII".equals(charset.toUpperCase())) - charset = "us-ascii"; + charset = "US-ASCII"; } 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 { - if ("US-ASCII".equals(Charset.forName(charset).name())) + // See UnknownCharsetProvider class + if ("US-ASCII".equals(Charset.forName(charset).name())) { + Log.w("Unsupported encoding charset=" + charset); warnings.add(context.getString(R.string.title_no_charset, charset)); + result = new String(result.getBytes(StandardCharsets.ISO_8859_1)); + } } } catch (ParseException ex) { Log.w(ex); diff --git a/app/src/main/java/eu/faircode/email/UnknownCharsetProvider.java b/app/src/main/java/eu/faircode/email/UnknownCharsetProvider.java index 4ac16266bc..74f052a7bd 100644 --- a/app/src/main/java/eu/faircode/email/UnknownCharsetProvider.java +++ b/app/src/main/java/eu/faircode/email/UnknownCharsetProvider.java @@ -20,6 +20,7 @@ package eu.faircode.email; */ import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.nio.charset.spi.CharsetProvider; import java.util.Collections; import java.util.Iterator; @@ -36,8 +37,9 @@ public class UnknownCharsetProvider extends CharsetProvider { // UseInqueCodePage // none // unknown-8bit + // X-UNKNOWN // https://javaee.github.io/javamail/FAQ#unsupen - Log.w("Unknown charset=" + name); - return Charset.forName("US-ASCII"); + Log.e("Unknown charset=" + name); + return StandardCharsets.US_ASCII; } }