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 2027e1a21..16c613584 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 @@ -158,18 +158,24 @@ class DecoderUtil { if (previousWord != null) { sb.append(decodeEncodedWord(previousWord)); sb.append(sep); + sb.append(body.substring(begin, end)); previousWord = null; - } - } else if (previousWord != null) { - if (previousWord.encoding.equals(word.encoding) && previousWord.charset.equals(word.charset)) { - previousWord.encodedText += word.encodedText; } else { - sb.append(decodeEncodedWord(previousWord)); + sb.append(sep); + } + } else { + if (previousWord != null) { + if (previousWord.encoding.equals(word.encoding) && previousWord.charset.equals(word.charset)) { + previousWord.encodedText += word.encodedText; + } else { + sb.append(decodeEncodedWord(previousWord)); + sb.append(sep); + previousWord = word; + } + } else { sb.append(sep); previousWord = word; } - } else { - previousWord = word; } if (previousWord == null) { 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 36f1402f5..e53070262 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 @@ -25,7 +25,6 @@ public class DecoderUtilTest { @Test public void decodeEncodedWords_withAsciiCharset_encoded_data_returns_text() { - body = "=?us-ascii?q?abc?="; expect = "abc"; message = null; @@ -76,7 +75,6 @@ public class DecoderUtilTest { public void decodeEncodedWords_withMissingCharset_returnAsText() { body = "=??q??="; expect = "=??q??="; - ; message = null; assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message)); } @@ -92,7 +90,6 @@ public class DecoderUtilTest { @Test public void decodeEncodedWords_withNoTextCharsetOrEncoding_returnAsText() { - body = "=??="; expect = "=??="; message = null; @@ -101,7 +98,6 @@ public class DecoderUtilTest { @Test public void decodeEncodedWords_with_MissingEncodingAndData_returnAsText() { - body = "=?x?="; expect = "=?x?="; message = null; @@ -110,7 +106,6 @@ public class DecoderUtilTest { @Test public void decodeEncodedWords_withMissingEncoding_returnAsText() { - body = "=?x??="; expect = "=?x??="; message = null; @@ -119,7 +114,6 @@ public class DecoderUtilTest { @Test public void decodeEncodedWords_with_incompleteEncodingFormat_returnAsText() { - body = "=?x?q?="; expect = "=?x?q?="; message = null; @@ -128,7 +122,6 @@ public class DecoderUtilTest { @Test public void decodeEncodedWords_with_unrecognisedEncoding_withEmptyEncodedData_returnAsText() { - body = "=?x?q??="; expect = "=?x?q??="; message = null; @@ -137,7 +130,6 @@ public class DecoderUtilTest { @Test public void decodeEncodedWords_withUnrecognisedEncoding_withEncodedData_return_encoded_data() { - body = "=?x?q?X?="; expect = "X"; message = null; @@ -160,6 +152,14 @@ public class DecoderUtilTest { assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message)); } + @Test + public void decodeEncodedWords_withPartiallyEncodedAfter_returnsBothSections() { + body = "def=?us-ascii?q?abc?="; + expect = "defabc"; + message = null; + assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message)); + } + @Test public void decodeEncodedWords_withUnrecognisedCharset_returnsEncodedData() { body = "=?x?= =?";