From 498df5db73acaa6599029c48a2b793737e60d76d Mon Sep 17 00:00:00 2001 From: Philip Whitehouse Date: Sat, 2 Sep 2017 11:17:50 +0100 Subject: [PATCH] Add RFC2047 tests and fix a resulting whitespace bug --- .../fsck/k9/mail/internet/DecoderUtil.java | 6 +-- .../k9/mail/internet/DecoderUtilTest.java | 38 +++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) 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)); + } }