diff --git a/src/com/android/email/mail/internet/MimeUtility.java b/src/com/android/email/mail/internet/MimeUtility.java index 47cd6152e..008328a44 100644 --- a/src/com/android/email/mail/internet/MimeUtility.java +++ b/src/com/android/email/mail/internet/MimeUtility.java @@ -26,13 +26,12 @@ import com.android.email.mail.Part; import org.apache.commons.io.IOUtils; import org.apache.james.mime4j.codec.EncoderUtil; +import org.apache.james.mime4j.decoder.Base64InputStream; import org.apache.james.mime4j.decoder.DecoderUtil; import org.apache.james.mime4j.decoder.QuotedPrintableInputStream; import org.apache.james.mime4j.util.CharsetUtil; import android.util.Log; -import android.util.Base64; -import android.util.Base64InputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -361,7 +360,7 @@ public class MimeUtility { in = new QuotedPrintableInputStream(in); } else if ("base64".equalsIgnoreCase(contentTransferEncoding)) { - in = new Base64InputStream(in, Base64.DEFAULT); + in = new Base64InputStream(in); } } diff --git a/tests/src/com/android/email/mail/internet/MimeUtilityTest.java b/tests/src/com/android/email/mail/internet/MimeUtilityTest.java index 8052a62df..b0a82fe2b 100644 --- a/tests/src/com/android/email/mail/internet/MimeUtilityTest.java +++ b/tests/src/com/android/email/mail/internet/MimeUtilityTest.java @@ -24,6 +24,10 @@ import com.android.email.mail.Part; import com.android.email.mail.MessageTestUtils.MessageBuilder; import com.android.email.mail.MessageTestUtils.MultipartBuilder; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + import android.test.suitebuilder.annotation.SmallTest; import junit.framework.TestCase; @@ -49,6 +53,16 @@ public class MimeUtilityTest extends TestCase { /** a string without any unicode */ private final String SHORT_PLAIN = "abcd"; + + /** Good base64 string */ + private final String GOOD_BASE64 = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + + /** Bad base64 string */ + private final String BAD_BASE64 = "CgpTZW50IGZyb20gU2Ftc3VuZyB0YWJsZXQ="; + + /** Encoding type */ + private final String BASE64 = "base64"; /** long subject which will be split into two MIME/Base64 chunks */ private final String LONG_UNICODE_SPLIT = @@ -501,7 +515,20 @@ public class MimeUtilityTest extends TestCase { assertTrue(MimeUtility.mimeTypeMatches("match/this", arrayTwo)); } - // TODO: tests for decodeBody(InputStream in, String contentTransferEncoding) + // TODO: tests for decodeBody(InputStream in, String contentTransferEncoding) + + /** + * Confirm that decodeBody() does not crash when + * given bad Base64 data. + */ + public void testDecodeBody_BadBase64() throws IOException { + InputStream in = new ByteArrayInputStream(GOOD_BASE64.getBytes("us-ascii")); + assertNotNull(MimeUtility.decodeBody(in, BASE64)); + + in = new ByteArrayInputStream(BAD_BASE64.getBytes("us-ascii")); + assertNotNull(MimeUtility.decodeBody(in, BASE64)); + } + // TODO: tests for collectParts(Part part, ArrayList viewables, ArrayList attachments) }