From 09b771bd03f7ea68c6cf7873b4878f7453fd6a6c Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 25 Oct 2020 07:58:53 +0100 Subject: [PATCH] Skip converting to 16 bits charsets --- .../main/java/eu/faircode/email/MessageHelper.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index 877c0317cb..502a7ea05d 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -124,6 +124,12 @@ public class MessageHelper { private static final int FORMAT_FLOWED_LINE_LENGTH = 72; private static final long MIN_REQUIRED_SPACE = 250 * 1024L * 1024L; + private static final List CHARSET16 = Collections.unmodifiableList(Arrays.asList( + StandardCharsets.UTF_16, + StandardCharsets.UTF_16BE, + StandardCharsets.UTF_16LE + )); + // https://tools.ietf.org/html/rfc4021 static void setSystemProperties(Context context) { @@ -1793,13 +1799,13 @@ public class MessageHelper { if (!TextUtils.isEmpty(charset)) try { - Charset detected = CharsetHelper.detect(result); - Log.i("Charset detected=" + detected + " meta=" + meta); + Log.i("Charset meta=" + meta); Charset c = Charset.forName(charset); if (c.equals(StandardCharsets.UTF_8) && !CharsetHelper.isUTF8(result)) break; - if (c.equals(StandardCharsets.UTF_16) && !c.equals(detected)) + if (CHARSET16.contains(c)) break; + Log.e("Converting meta=" + c); result = new String(result.getBytes(StandardCharsets.ISO_8859_1), c); break; } catch (Throwable ex) {