From 7d697046ce6312c3e2faa3341fec1445494d168b Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 21 Jan 2019 17:46:51 +0000 Subject: [PATCH] Fixed subject decode workaround --- .../java/eu/faircode/email/MessageHelper.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index b787181ba3..54b4b0933b 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -496,15 +496,21 @@ public class MessageHelper { String getSubject() throws MessagingException, UnsupportedEncodingException { String subject = imessage.getSubject(); - if (subject != null && subject.contains("=?")) { - String prev; - do { - prev = subject; - subject = MimeUtility.decodeText(subject); - Log.i("Mime decode " + prev + " -> " + subject); - } - while (!subject.equals(prev)); + if (subject == null) + return subject; + + int i = 0; + int s = subject.indexOf("=?", i); + int e = subject.indexOf("?=", i); + while (s >= 0 && e >= 0 && i < subject.length()) { + String decode = subject.substring(s, e + 2); + String decoded = MimeUtility.decodeText(decode); + subject = subject.substring(0, i) + decoded + subject.substring(e + 2); + i += decoded.length(); + s = subject.indexOf("=?", i); + e = subject.indexOf("?=", i); } + return subject; }