From b1d72808d7957b98194d0aca98879f4068f396c3 Mon Sep 17 00:00:00 2001 From: Tadashi Takaoka <> Date: Tue, 24 Mar 2009 22:44:38 -0700 Subject: [PATCH] Automated import from //branches/donutburger/...@142458,142458 --- .../james/mime4j/codec/EncoderUtil.java | 6 +++--- .../email/mail/internet/MimeUtilityTest.java | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/org/apache/james/mime4j/codec/EncoderUtil.java b/src/org/apache/james/mime4j/codec/EncoderUtil.java index d6f3998d4..c81a83c88 100644 --- a/src/org/apache/james/mime4j/codec/EncoderUtil.java +++ b/src/org/apache/james/mime4j/codec/EncoderUtil.java @@ -374,14 +374,14 @@ public class EncoderUtil { sb.append((char) BASE64_TABLE[data >> 18 & 0x3f]); sb.append((char) BASE64_TABLE[data >> 12 & 0x3f]); sb.append((char) BASE64_TABLE[data >> 6 & 0x3f]); - sb.append(BASE64_PAD); + sb.append((char) BASE64_PAD); } else if (idx == end - 1) { int data = (bytes[idx] & 0xff) << 16; sb.append((char) BASE64_TABLE[data >> 18 & 0x3f]); sb.append((char) BASE64_TABLE[data >> 12 & 0x3f]); - sb.append(BASE64_PAD); - sb.append(BASE64_PAD); + sb.append((char) BASE64_PAD); + sb.append((char) BASE64_PAD); } return sb.toString(); diff --git a/tests/src/com/android/email/mail/internet/MimeUtilityTest.java b/tests/src/com/android/email/mail/internet/MimeUtilityTest.java index 814774b3c..641fe4973 100644 --- a/tests/src/com/android/email/mail/internet/MimeUtilityTest.java +++ b/tests/src/com/android/email/mail/internet/MimeUtilityTest.java @@ -39,6 +39,14 @@ public class MimeUtilityTest extends TestCase { private final String SHORT_UNICODE = "\u2191\u2193\u2190\u2192"; private final String SHORT_UNICODE_ENCODED = "=?UTF-8?B?4oaR4oaT4oaQ4oaS?="; + /** dollar and euro sign */ + private final String PADDED2_UNICODE = "$\u20AC"; + private final String PADDED2_UNICODE_ENCODED = "=?UTF-8?B?JOKCrA==?="; + private final String PADDED1_UNICODE = "$$\u20AC"; + private final String PADDED1_UNICODE_ENCODED = "=?UTF-8?B?JCTigqw=?="; + private final String PADDED0_UNICODE = "$$$\u20AC"; + private final String PADDED0_UNICODE_ENCODED = "=?UTF-8?B?JCQk4oKs?="; + /** a string without any unicode */ private final String SHORT_PLAIN = "abcd"; @@ -141,6 +149,19 @@ public class MimeUtilityTest extends TestCase { assertSame(SHORT_PLAIN, result3); } + /** + * Test about base64 padding variety. + */ + public void testPaddingOfFoldAndEncode2() { + String result1 = MimeUtility.foldAndEncode2(PADDED2_UNICODE, 0); + String result2 = MimeUtility.foldAndEncode2(PADDED1_UNICODE, 0); + String result3 = MimeUtility.foldAndEncode2(PADDED0_UNICODE, 0); + + assertEquals("padding 2", PADDED2_UNICODE_ENCODED, result1); + assertEquals("padding 1", PADDED1_UNICODE_ENCODED, result2); + assertEquals("padding 0", PADDED0_UNICODE_ENCODED, result3); + } + // TODO: more tests for foldAndEncode(String s) /**