From f87d59a7f3c7459af78b3449b43ae89b1bb4e6f9 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 25 Jun 2021 07:56:22 +0200 Subject: [PATCH] Charset text/plain simplification --- .../java/eu/faircode/email/MessageHelper.java | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index c603c9c668..c9dad76f24 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -1884,22 +1884,19 @@ public class MessageHelper { } if (h.isPlainText()) { - if (charset == null || StandardCharsets.ISO_8859_1.equals(cs)) { + if (StandardCharsets.ISO_8859_1.equals(cs) && CharsetHelper.isUTF8(result)) { + Log.i("Charset upgrade=UTF8"); + result = new String(result.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8); + } else if (charset == null) { Charset detected = CharsetHelper.detect(result); - if (StandardCharsets.ISO_8859_1.equals(cs) && - StandardCharsets.UTF_8.equals(detected)) { - Log.i("Charset upgrade=UTF8"); - result = new String(result.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8); - } else { - if (detected == null) { - if (CharsetHelper.isUTF8(result)) { - Log.i("Charset plain=UTF8"); - result = new String(result.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8); - } - } else { - Log.i("Charset plain=" + detected.name()); - result = new String(result.getBytes(StandardCharsets.ISO_8859_1), detected); + if (detected == null) { + if (CharsetHelper.isUTF8(result)) { + Log.i("Charset plain=UTF8"); + result = new String(result.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8); } + } else { + Log.i("Charset plain=" + detected.name()); + result = new String(result.getBytes(StandardCharsets.ISO_8859_1), detected); } }