Fix a decoding problem on the Email body

When decoding the Email body, email application used google default base64
function.  But it caused problem, so particular email did not sync any more.
So we have changed decoding function as a decoder from apache in order
not to occur problem

Change-Id: I7581123f21fbb4015153ca6f4a0c14c0f6a769fc
Signed-off-by: Sang-Jun Park <sj2202.park@samsung.com>
This commit is contained in:
Sang-Jun Park 2011-02-02 08:16:13 +09:00
parent 7d7ffaf6a3
commit 499fc762ee
2 changed files with 30 additions and 4 deletions

View File

@ -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);
}
}

View File

@ -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<Part> viewables, ArrayList<Part> attachments)
}