diff --git a/tests-on-jvm/.classpath b/tests-on-jvm/.classpath
new file mode 100644
index 000000000..aa8143d4e
--- /dev/null
+++ b/tests-on-jvm/.classpath
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/tests-on-jvm/.project b/tests-on-jvm/.project
new file mode 100644
index 000000000..7ab8d956c
--- /dev/null
+++ b/tests-on-jvm/.project
@@ -0,0 +1,17 @@
+
+
+ tests-on-jvm
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/tests-on-jvm/src/android/util/Log.java b/tests-on-jvm/src/android/util/Log.java
new file mode 100644
index 000000000..abb17e99d
--- /dev/null
+++ b/tests-on-jvm/src/android/util/Log.java
@@ -0,0 +1,10 @@
+package android.util;
+
+public class Log {
+ public static int v(String tag, String message) { return 0; }
+ public static int d(String tag, String message) { return 0; }
+ public static int i(String tag, String message) { return 0; }
+ public static int w(String tag, String message) { return 0; }
+ public static int e(String tag, String message) { return 0; }
+ public static int e(String tag, String message, Throwable th) { return 0; }
+}
diff --git a/tests-on-jvm/src/com/fsck/k9/mail/internet/DecoderUtilTest.java b/tests-on-jvm/src/com/fsck/k9/mail/internet/DecoderUtilTest.java
new file mode 100644
index 000000000..b1d25c873
--- /dev/null
+++ b/tests-on-jvm/src/com/fsck/k9/mail/internet/DecoderUtilTest.java
@@ -0,0 +1,111 @@
+package com.fsck.k9.mail.internet;
+
+import junit.framework.TestCase;
+
+public class DecoderUtilTest extends TestCase {
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testDecodeEncodedWords() {
+ String body, expect;
+ MimeMessage message;
+
+ body = "abc";
+ expect = "abc";
+ message = null;
+ assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
+
+ body = "=?us-ascii?q?abc?=";
+ expect = "abc";
+ message = null;
+ assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
+
+ body = "=?";
+ expect = "=?";
+ message = null;
+ assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
+
+ body = "=??";
+ expect = "=??";
+ message = null;
+ assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
+
+ body = "=???";
+ expect = "=???";
+ message = null;
+ assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
+
+ body = "=????";
+ expect = "=????";
+ message = null;
+ assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
+
+ body = "=????=";
+ expect = "=????=";
+ message = null;
+ assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
+
+ body = "=??q??=";
+ expect = "=??q??=";;
+ message = null;
+ assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
+
+ body = "=??q?a?=";
+ expect = "a";
+ message = null;
+ assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
+
+ body = "=??=";
+ expect = "=??=";
+ message = null;
+ assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
+
+ body = "=?x?=";
+ expect = "=?x?=";
+ message = null;
+ assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
+
+ body = "=?x??=";
+ expect = "=?x??=";
+ message = null;
+ assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
+
+ body = "=?x?q?=";
+ expect = "=?x?q?=";
+ message = null;
+ assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
+
+ body = "=?x?q??=";
+ expect = "=?x?q??=";
+ message = null;
+ assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
+
+ body = "=?x?q?X?=";
+ expect = "X";
+ message = null;
+ assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
+
+ // invalid base64 string
+ body = "=?us-ascii?b?abc?=";
+ expect = "";
+ message = null;
+ assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
+
+ // broken encoded header
+ body = "=?us-ascii?q?abc?= =?";
+ expect = "abc =?";
+ message = null;
+ assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
+
+ body = "=?x?= =?";
+ expect = "=?x?= =?";
+ message = null;
+ assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
+ }
+}
diff --git a/tests-on-jvm/src/com/fsck/k9/mail/internet/MimeUtilityTest.java b/tests-on-jvm/src/com/fsck/k9/mail/internet/MimeUtilityTest.java
new file mode 100644
index 000000000..e723cb562
--- /dev/null
+++ b/tests-on-jvm/src/com/fsck/k9/mail/internet/MimeUtilityTest.java
@@ -0,0 +1,147 @@
+package com.fsck.k9.mail.internet;
+
+import java.util.Locale;
+
+import com.fsck.k9.K9;
+import com.fsck.k9.mail.MessagingException;
+
+import junit.framework.TestCase;
+
+public class MimeUtilityTest extends TestCase {
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testGetHeaderParameter() {
+ String result;
+
+ /* Test edge cases */
+ result = MimeUtility.getHeaderParameter(";", null);
+ assertEquals(null, result);
+
+ result = MimeUtility.getHeaderParameter("name", "name");
+ assertEquals(null, result);
+
+ result = MimeUtility.getHeaderParameter("name=", "name");
+ assertEquals("", result);
+
+ result = MimeUtility.getHeaderParameter("name=\"", "name");
+ assertEquals("\"", result);
+
+ /* Test expected cases */
+ result = MimeUtility.getHeaderParameter("name=value", "name");
+ assertEquals("value", result);
+
+ result = MimeUtility.getHeaderParameter("name = value", "name");
+ assertEquals("value", result);
+
+ result = MimeUtility.getHeaderParameter("name=\"value\"", "name");
+ assertEquals("value", result);
+
+ result = MimeUtility.getHeaderParameter("name = \"value\"" , "name");
+ assertEquals("value", result);
+
+ result = MimeUtility.getHeaderParameter("name=\"\"", "name");
+ assertEquals("", result);
+
+ result = MimeUtility.getHeaderParameter("text/html ; charset=\"windows-1251\"", null);
+ assertEquals("text/html", result);
+
+ result = MimeUtility.getHeaderParameter("text/HTML ; charset=\"windows-1251\"", null);
+ assertEquals("text/HTML", result);
+ }
+
+ public void testFixupCharset() throws MessagingException {
+ String charsetOnMail;
+ String expect;
+
+ charsetOnMail = "CP932";
+ expect = "shift_jis";
+ assertEquals(expect, MimeUtility.fixupCharset(charsetOnMail, new MimeMessage()));
+
+// charsetOnMail = "koi8-u";
+// expect = "koi8-r";
+// assertEquals(expect, MimeUtility.fixupCharset(charsetOnMail, new MimeMessage()));
+
+ MimeMessage message;
+
+ message= new MimeMessage();
+ message.setHeader("From", "aaa@docomo.ne.jp");
+ charsetOnMail = "shift_jis";
+ expect = "x-docomo-shift_jis-2007";
+ assertEquals(expect, MimeUtility.fixupCharset(charsetOnMail, message));
+
+ message = new MimeMessage();
+ message.setHeader("From", "aaa@dwmail.jp");
+ charsetOnMail = "shift_jis";
+ expect = "x-docomo-shift_jis-2007";
+ assertEquals(expect, MimeUtility.fixupCharset(charsetOnMail, message));
+
+ message = new MimeMessage();
+ message.setHeader("From", "aaa@pdx.ne.jp");
+ charsetOnMail = "shift_jis";
+ expect = "x-docomo-shift_jis-2007";
+ assertEquals(expect, MimeUtility.fixupCharset(charsetOnMail, message));
+
+ message = new MimeMessage();
+ message.setHeader("From", "aaa@willcom.com");
+ charsetOnMail = "shift_jis";
+ expect = "x-docomo-shift_jis-2007";
+ assertEquals(expect, MimeUtility.fixupCharset(charsetOnMail, message));
+
+ message = new MimeMessage();
+ message.setHeader("From", "aaa@emnet.ne.jp");
+ charsetOnMail = "shift_jis";
+ expect = "x-docomo-shift_jis-2007";
+ assertEquals(expect, MimeUtility.fixupCharset(charsetOnMail, message));
+
+ message = new MimeMessage();
+ message.setHeader("From", "aaa@emobile.ne.jp");
+ charsetOnMail = "shift_jis";
+ expect = "x-docomo-shift_jis-2007";
+ assertEquals(expect, MimeUtility.fixupCharset(charsetOnMail, message));
+
+ message = new MimeMessage();
+ message.setHeader("From", "aaa@softbank.ne.jp");
+ charsetOnMail = "shift_jis";
+ expect = "x-softbank-shift_jis-2007";
+ assertEquals(expect, MimeUtility.fixupCharset(charsetOnMail, message));
+
+ message = new MimeMessage();
+ message.setHeader("From", "aaa@vodafone.ne.jp");
+ charsetOnMail = "shift_jis";
+ expect = "x-softbank-shift_jis-2007";
+ assertEquals(expect, MimeUtility.fixupCharset(charsetOnMail, message));
+
+ message = new MimeMessage();
+ message.setHeader("From", "aaa@disney.ne.jp");
+ charsetOnMail = "shift_jis";
+ expect = "x-softbank-shift_jis-2007";
+ assertEquals(expect, MimeUtility.fixupCharset(charsetOnMail, message));
+
+ message = new MimeMessage();
+ message.setHeader("From", "aaa@vertuclub.ne.jp");
+ charsetOnMail = "shift_jis";
+ expect = "x-softbank-shift_jis-2007";
+ assertEquals(expect, MimeUtility.fixupCharset(charsetOnMail, message));
+
+ message = new MimeMessage();
+ message.setHeader("From", "aaa@ezweb.ne.jp");
+ charsetOnMail = "shift_jis";
+ expect = "x-kddi-shift_jis-2007";
+ assertEquals(expect, MimeUtility.fixupCharset(charsetOnMail, message));
+
+ message = new MimeMessage();
+ message.setHeader("From", "aaa@ido.ne.jp");
+ charsetOnMail = "shift_jis";
+ expect = "x-kddi-shift_jis-2007";
+ assertEquals(expect, MimeUtility.fixupCharset(charsetOnMail, message));
+
+ }
+
+}