diff --git a/k9mail-library/src/main/java/com/fsck/k9/mail/internet/DecoderUtil.java b/k9mail-library/src/main/java/com/fsck/k9/mail/internet/DecoderUtil.java index 16c613584..7d7a350b7 100644 --- a/k9mail-library/src/main/java/com/fsck/k9/mail/internet/DecoderUtil.java +++ b/k9mail-library/src/main/java/com/fsck/k9/mail/internet/DecoderUtil.java @@ -161,7 +161,7 @@ class DecoderUtil { sb.append(body.substring(begin, end)); previousWord = null; } else { - sb.append(sep); +// sb.append(sep); } } else { if (previousWord != null) { @@ -169,11 +169,11 @@ class DecoderUtil { previousWord.encodedText += word.encodedText; } else { sb.append(decodeEncodedWord(previousWord)); - sb.append(sep); + sb.append(sep.trim()); previousWord = word; } } else { - sb.append(sep); + sb.append(sep.trim()); previousWord = word; } } diff --git a/k9mail-library/src/test/java/com/fsck/k9/mail/internet/DecoderUtilTest.java b/k9mail-library/src/test/java/com/fsck/k9/mail/internet/DecoderUtilTest.java index e53070262..3a6a12a00 100644 --- a/k9mail-library/src/test/java/com/fsck/k9/mail/internet/DecoderUtilTest.java +++ b/k9mail-library/src/test/java/com/fsck/k9/mail/internet/DecoderUtilTest.java @@ -194,4 +194,42 @@ public class DecoderUtilTest { message = null; assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message)); } + + @Test + public void decodeEncodedWords_withRFC2047examples_decodesCorrectly() { + body = "(=?ISO-8859-1?Q?a?=)"; + expect = "(a)"; + message = null; + assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message)); + + body = "(=?ISO-8859-1?Q?a?= b)"; + expect = "(a b)"; + message = null; + assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message)); + + body = "(=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?=)"; + expect = "(ab)"; + message = null; + assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message)); + + body = "(=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?=)"; + expect = "(ab)"; + message = null; + assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message)); + + body = "(=?ISO-8859-1?Q?a?= \n =?ISO-8859-1?Q?b?=)"; + expect = "(ab)"; + message = null; + assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message)); + + body = "(=?ISO-8859-1?Q?a_b?=)"; + expect = "(a b)"; + message = null; + assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message)); + + body = "(=?ISO-8859-1?Q?a?= =?ISO-8859-2?Q?_b?=)"; + expect = "(a b)"; + message = null; + assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message)); + } }