diff --git a/k9mail-library/src/main/java/com/fsck/k9/mail/internet/MimeUtility.java b/k9mail-library/src/main/java/com/fsck/k9/mail/internet/MimeUtility.java index 85544abec..a966af987 100644 --- a/k9mail-library/src/main/java/com/fsck/k9/mail/internet/MimeUtility.java +++ b/k9mail-library/src/main/java/com/fsck/k9/mail/internet/MimeUtility.java @@ -9,6 +9,7 @@ import java.util.Locale; import java.util.regex.Pattern; import android.support.annotation.NonNull; +import android.util.Log; import com.fsck.k9.mail.Body; import com.fsck.k9.mail.BodyPart; @@ -21,6 +22,8 @@ import org.apache.james.mime4j.codec.Base64InputStream; import org.apache.james.mime4j.codec.QuotedPrintableInputStream; import org.apache.james.mime4j.util.MimeUtil; +import static com.fsck.k9.mail.K9MailLib.LOG_TAG; + public class MimeUtility { public static final String DEFAULT_ATTACHMENT_MIME_TYPE = "application/octet-stream"; @@ -1047,7 +1050,8 @@ public class MimeUtility { } }; } else { - throw new UnsupportedContentTransferEncodingException(encoding); + Log.w(LOG_TAG, "Unsupported encoding: " + encoding); + inputStream = rawInputStream; } } else { inputStream = body.getInputStream(); diff --git a/k9mail-library/src/main/java/com/fsck/k9/mail/internet/UnsupportedContentTransferEncodingException.java b/k9mail-library/src/main/java/com/fsck/k9/mail/internet/UnsupportedContentTransferEncodingException.java deleted file mode 100644 index 808d29194..000000000 --- a/k9mail-library/src/main/java/com/fsck/k9/mail/internet/UnsupportedContentTransferEncodingException.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.fsck.k9.mail.internet; - -import com.fsck.k9.mail.MessagingException; - -public class UnsupportedContentTransferEncodingException extends MessagingException { - public UnsupportedContentTransferEncodingException(String encoding) { - super("Unsupported encoding: "+encoding); - } -} diff --git a/k9mail-library/src/test/java/com/fsck/k9/mail/internet/MessageExtractorTest.java b/k9mail-library/src/test/java/com/fsck/k9/mail/internet/MessageExtractorTest.java index cb60c5316..5fa528b3d 100644 --- a/k9mail-library/src/test/java/com/fsck/k9/mail/internet/MessageExtractorTest.java +++ b/k9mail-library/src/test/java/com/fsck/k9/mail/internet/MessageExtractorTest.java @@ -73,14 +73,15 @@ public class MessageExtractorTest { } @Test - public void getTextFromPart_withUnknownEncoding_shouldReturnNull() throws Exception { + public void getTextFromPart_withUnknownEncoding_shouldReturnUnmodifiedBodyContents() throws Exception { part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, "text/plain"); - BinaryMemoryBody body = new BinaryMemoryBody("Sample text body".getBytes(), "unknown encoding"); + String bodyText = "Sample text body"; + BinaryMemoryBody body = new BinaryMemoryBody(bodyText.getBytes(), "unknown encoding"); part.setBody(body); String result = MessageExtractor.getTextFromPart(part); - assertNull(result); + assertEquals(bodyText, result); } @Test diff --git a/k9mail-library/src/test/java/com/fsck/k9/mail/internet/MimeMessageParseTest.java b/k9mail-library/src/test/java/com/fsck/k9/mail/internet/MimeMessageParseTest.java index 07363861e..0ac57dae6 100644 --- a/k9mail-library/src/test/java/com/fsck/k9/mail/internet/MimeMessageParseTest.java +++ b/k9mail-library/src/test/java/com/fsck/k9/mail/internet/MimeMessageParseTest.java @@ -138,8 +138,8 @@ public class MimeMessageParseTest { ""); } - @Test(expected = UnsupportedContentTransferEncodingException.class) - public void testSinglePartUnknownEncoding_throwsUnsupportedEncodingException() throws Exception { + @Test + public void decodeBody_withUnknownEncoding_shouldReturnUnmodifiedBodyContents() throws Exception { MimeMessage msg = parseWithoutRecurse(toStream( "From: \r\n" + "To: \r\n" + @@ -150,7 +150,9 @@ public class MimeMessageParseTest { "\r\n" + "dGhpcyBpcyBzb21lIG1vcmUgdGVzdCB0ZXh0Lg==\r\n")); - MimeUtility.decodeBody(msg.getBody()); + InputStream inputStream = MimeUtility.decodeBody(msg.getBody()); + + assertEquals("dGhpcyBpcyBzb21lIG1vcmUgdGVzdCB0ZXh0Lg==\r\n", streamToString(inputStream)); } @Test