Merge pull request #2048 from k9mail/GH-2044_do_not_crash_on_unknown_content_transfer_encoding
Don't crash on unknown content transfer encoding
This commit is contained in:
commit
3e8ad4b195
4 changed files with 14 additions and 16 deletions
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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: <adam@example.org>\r\n" +
|
||||
"To: <eva@example.org>\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
|
||||
|
|
Loading…
Reference in a new issue