From d48a87f0944cc3372f43100a1d713dffe16f2b13 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 1 Jun 2019 19:28:51 +0200 Subject: [PATCH] Check for empty UTF8 decoded subject --- .../main/java/eu/faircode/email/MessageHelper.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index 10d325796d..9d0d8529fc 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -37,6 +37,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; +import java.nio.CharBuffer; import java.nio.charset.CharacterCodingException; import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; @@ -661,7 +662,6 @@ public class MessageHelper { } catch (UnsupportedEncodingException ex) { Log.w(ex); } - return decodeMime(subject); } else { // Fix UTF-8 plain header try { @@ -671,14 +671,15 @@ public class MessageHelper { bytes[i] = (byte) kars[i]; CharsetDecoder cs = StandardCharsets.UTF_8.newDecoder(); - cs.decode(ByteBuffer.wrap(bytes)); - subject = new String(bytes, StandardCharsets.UTF_8); + CharBuffer out = cs.decode(ByteBuffer.wrap(bytes)); + if (out.length() > 0) + subject = new String(bytes, StandardCharsets.UTF_8); } catch (CharacterCodingException ex) { Log.w(ex); } - - return decodeMime(subject); } + + return decodeMime(subject); } Long getSize() throws MessagingException {