1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 11:42:16 -05:00
This commit is contained in:
Jan Berkel 2014-12-23 10:13:57 +01:00
parent c96a11212e
commit fe8e779b32
7 changed files with 155 additions and 125 deletions

View File

@ -1,17 +1,20 @@
package com.fsck.k9.mail;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class AddressTest {
/**
* test the possibility to parse "From:" fields with no email.
* for example: From: News for Vector Limited - Google Finance
* http://code.google.com/p/k9mail/issues/detail?id=3814
*/
@Test public void testParseWithMissingEmail() {
Address[] addresses = Address.parse("NAME ONLY");
@Test
public void testParseWithMissingEmail() {
Address[] addresses = Address.parse("NAME ONLY");
assertEquals(1, addresses.length);
assertEquals(null, addresses[0].getAddress());
assertEquals("NAME ONLY", addresses[0].getPersonal());
@ -20,17 +23,20 @@ public class AddressTest {
/**
* test name + valid email
*/
@Test public void testPraseWithValidEmail() {
Address[] addresses = Address.parse("Max Mustermann <maxmuster@mann.com>");
@Test
public void testPraseWithValidEmail() {
Address[] addresses = Address.parse("Max Mustermann <maxmuster@mann.com>");
assertEquals(1, addresses.length);
assertEquals("maxmuster@mann.com", addresses[0].getAddress());
assertEquals("Max Mustermann", addresses[0].getPersonal());
}
/**
* test with multi email addresses
*/
@Test public void testPraseWithValidEmailMulti() {
Address[] addresses = Address.parse("lorem@ipsum.us,mark@twain.com");
@Test
public void testPraseWithValidEmailMulti() {
Address[] addresses = Address.parse("lorem@ipsum.us,mark@twain.com");
assertEquals(2, addresses.length);
assertEquals("lorem@ipsum.us", addresses[0].getAddress());
assertEquals(null, addresses[0].getPersonal());

View File

@ -5,9 +5,10 @@ import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class Address_quoteAtoms
{
@Test public void testNoQuote() {
public class Address_quoteAtoms {
@Test
public void testNoQuote() {
// Alpha
noQuote("a");
noQuote("aa");

View File

@ -8,7 +8,8 @@ import java.io.ByteArrayOutputStream;
import static org.junit.Assert.assertEquals;
public class EOLConvertingOutputStreamTest {
public class EOLConvertingOutputStreamTest {
private EOLConvertingOutputStream subject;
private ByteArrayOutputStream out;
@ -18,37 +19,43 @@ public class EOLConvertingOutputStreamTest {
subject = new EOLConvertingOutputStream(out);
}
@Test public void testFilterWithoutCRorLF() throws Exception {
@Test
public void testFilterWithoutCRorLF() throws Exception {
subject.write("Unchanged".getBytes());
subject.flush();
assertEquals("Unchanged", out.toString());
}
@Test public void testFilterWithCRLF() throws Exception {
@Test
public void testFilterWithCRLF() throws Exception {
subject.write("Filter\r\nNext Line".getBytes());
subject.flush();
assertEquals("Filter\r\nNext Line", out.toString());
}
@Test public void testFilterWithJustCR() throws Exception {
@Test
public void testFilterWithJustCR() throws Exception {
subject.write("\n\n\n".getBytes());
subject.flush();
assertEquals("\r\n\r\n\r\n", out.toString());
}
@Test public void testFilterWithCR() throws Exception {
@Test
public void testFilterWithCR() throws Exception {
subject.write("Filter\rNext Line".getBytes());
subject.flush();
assertEquals("Filter\r\nNext Line", out.toString());
}
@Test public void testFilterWithLF() throws Exception {
@Test
public void testFilterWithLF() throws Exception {
subject.write("Filter\nNext Line".getBytes());
subject.flush();
assertEquals("Filter\r\nNext Line", out.toString());
}
@Test public void testFlushWithCR() throws Exception {
@Test
public void testFlushWithCR() throws Exception {
subject.write("Flush\r".getBytes());
subject.flush();
assertEquals("Flush\r\n", out.toString());
@ -56,14 +63,16 @@ public class EOLConvertingOutputStreamTest {
assertEquals("Flush\r\n\r\n\r\n", out.toString());
}
@Test public void testFlushWithCRNotFollowedByLF() throws Exception {
@Test
public void testFlushWithCRNotFollowedByLF() throws Exception {
subject.write("Flush\r".getBytes());
subject.flush();
subject.write("Next line".getBytes());
assertEquals("Flush\r\nNext line", out.toString());
}
@Test public void testFlushWithLF() throws Exception {
@Test
public void testFlushWithLF() throws Exception {
subject.write("Flush\n".getBytes());
subject.flush();
subject.write("\n".getBytes());

View File

@ -5,9 +5,11 @@ import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class CharsetSupportTest {
@Test public void testFixupCharset() throws Exception {
public class CharsetSupportTest {
@Test
public void testFixupCharset() throws Exception {
String charsetOnMail;
String expect;
@ -21,7 +23,7 @@ public class CharsetSupportTest {
MimeMessage message;
message= new MimeMessage();
message = new MimeMessage();
message.setHeader("From", "aaa@docomo.ne.jp");
charsetOnMail = "shift_jis";
expect = "x-docomo-shift_jis-2007";

View File

@ -5,9 +5,11 @@ import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class DecoderUtilTest {
@Test public void testDecodeEncodedWords() {
@Test
public void testDecodeEncodedWords() {
String body, expect;
MimeMessage message;
@ -47,7 +49,8 @@ public class DecoderUtilTest {
assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
body = "=??q??=";
expect = "=??q??=";;
expect = "=??q??=";
;
message = null;
assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));

View File

@ -1,5 +1,6 @@
package com.fsck.k9.mail.internet;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
@ -21,22 +22,23 @@ import com.fsck.k9.mail.Multipart;
import static org.junit.Assert.assertEquals;
public class MimeMessageParseTest {
public class MimeMessageParseTest {
@Before
public void setup() {
BinaryTempFileBody.setTempDirectory(new File(System.getProperty("java.io.tmpdir")));
}
@Test public void testSinglePart7BitNoRecurse() throws Exception {
@Test
public void testSinglePart7BitNoRecurse() throws Exception {
MimeMessage msg = parseWithoutRecurse(toStream(
"From: <adam@example.org>\r\n" +
"To: <eva@example.org>\r\n" +
"Subject: Testmail\r\n" +
"MIME-Version: 1.0\r\n" +
"Content-type: text/plain\r\n" +
"Content-Transfer-Encoding: 7bit\r\n" +
"\r\n" +
"this is some test text."));
"To: <eva@example.org>\r\n" +
"Subject: Testmail\r\n" +
"MIME-Version: 1.0\r\n" +
"Content-type: text/plain\r\n" +
"Content-Transfer-Encoding: 7bit\r\n" +
"\r\n" +
"this is some test text."));
checkAddresses(msg.getFrom(), "adam@example.org");
checkAddresses(msg.getRecipients(RecipientType.TO), "eva@example.org");
@ -45,16 +47,17 @@ public class MimeMessageParseTest {
assertEquals("this is some test text.", streamToString(msg.getBody().getInputStream()));
}
@Test public void testSinglePart8BitRecurse() throws Exception {
@Test
public void testSinglePart8BitRecurse() throws Exception {
MimeMessage msg = parseWithRecurse(toStream(
"From: <adam@example.org>\r\n" +
"To: <eva@example.org>\r\n" +
"Subject: Testmail\r\n" +
"MIME-Version: 1.0\r\n" +
"Content-type: text/plain; encoding=ISO-8859-1\r\n" +
"Content-Transfer-Encoding: 8bit\r\n" +
"\r\n" +
"gefährliche Umlaute"));
"To: <eva@example.org>\r\n" +
"Subject: Testmail\r\n" +
"MIME-Version: 1.0\r\n" +
"Content-type: text/plain; encoding=ISO-8859-1\r\n" +
"Content-Transfer-Encoding: 8bit\r\n" +
"\r\n" +
"gefährliche Umlaute"));
checkAddresses(msg.getFrom(), "adam@example.org");
checkAddresses(msg.getRecipients(RecipientType.TO), "eva@example.org");
@ -63,16 +66,17 @@ public class MimeMessageParseTest {
assertEquals("gefährliche Umlaute", streamToString(msg.getBody().getInputStream()));
}
@Test public void testSinglePartBase64NoRecurse() throws Exception {
@Test
public void testSinglePartBase64NoRecurse() throws Exception {
MimeMessage msg = parseWithoutRecurse(toStream(
"From: <adam@example.org>\r\n" +
"To: <eva@example.org>\r\n" +
"Subject: Testmail\r\n" +
"MIME-Version: 1.0\r\n" +
"Content-type: text/plain\r\n" +
"Content-Transfer-Encoding: base64\r\n" +
"\r\n" +
"dGhpcyBpcyBzb21lIG1vcmUgdGVzdCB0ZXh0Lg==\r\n"));
"To: <eva@example.org>\r\n" +
"Subject: Testmail\r\n" +
"MIME-Version: 1.0\r\n" +
"Content-type: text/plain\r\n" +
"Content-Transfer-Encoding: base64\r\n" +
"\r\n" +
"dGhpcyBpcyBzb21lIG1vcmUgdGVzdCB0ZXh0Lg==\r\n"));
checkAddresses(msg.getFrom(), "adam@example.org");
checkAddresses(msg.getRecipients(RecipientType.TO), "eva@example.org");
@ -81,26 +85,27 @@ public class MimeMessageParseTest {
assertEquals("this is some more test text.", streamToString(msg.getBody().getInputStream()));
}
@Test public void testMultipartSingleLayerNoRecurse() throws Exception {
@Test
public void testMultipartSingleLayerNoRecurse() throws Exception {
MimeMessage msg = parseWithoutRecurse(toStream(
"From: <x@example.org>\r\n" +
"To: <y@example.org>\r\n" +
"Subject: Testmail 2\r\n" +
"MIME-Version: 1.0\n" +
"Content-Type: multipart/mixed; boundary=frontier\n" +
"\n" +
"This is a message with multiple parts in MIME format.\n" +
"--frontier\n" +
"Content-Type: text/plain\n" +
"\n" +
"This is the body of the message.\n" +
"--frontier\n" +
"Content-Type: application/octet-stream\n" +
"Content-Transfer-Encoding: base64\n" +
"\n" +
"PGh0bWw+CiAgPGhlYWQ+CiAgPC9oZWFkPgogIDxib2R5PgogICAgPHA+VGhpcyBpcyB0aGUg\n" +
"Ym9keSBvZiB0aGUgbWVzc2FnZS48L3A+CiAgPC9ib2R5Pgo8L2h0bWw+Cg=\n" +
"--frontier--"));
"To: <y@example.org>\r\n" +
"Subject: Testmail 2\r\n" +
"MIME-Version: 1.0\n" +
"Content-Type: multipart/mixed; boundary=frontier\n" +
"\n" +
"This is a message with multiple parts in MIME format.\n" +
"--frontier\n" +
"Content-Type: text/plain\n" +
"\n" +
"This is the body of the message.\n" +
"--frontier\n" +
"Content-Type: application/octet-stream\n" +
"Content-Transfer-Encoding: base64\n" +
"\n" +
"PGh0bWw+CiAgPGhlYWQ+CiAgPC9oZWFkPgogIDxib2R5PgogICAgPHA+VGhpcyBpcyB0aGUg\n" +
"Ym9keSBvZiB0aGUgbWVzc2FnZS48L3A+CiAgPC9ib2R5Pgo8L2h0bWw+Cg=\n" +
"--frontier--"));
checkAddresses(msg.getFrom(), "x@example.org");
checkAddresses(msg.getRecipients(RecipientType.TO), "y@example.org");
@ -109,35 +114,36 @@ public class MimeMessageParseTest {
checkLeafParts(msg,
"This is the body of the message.",
"<html>\n" +
" <head>\n" +
" </head>\n" +
" <body>\n" +
" <p>This is the body of the message.</p>\n" +
" </body>\n" +
"</html>\n" +
"");
" <head>\n" +
" </head>\n" +
" <body>\n" +
" <p>This is the body of the message.</p>\n" +
" </body>\n" +
"</html>\n" +
"");
}
@Test public void testMultipartSingleLayerRecurse() throws Exception {
@Test
public void testMultipartSingleLayerRecurse() throws Exception {
MimeMessage msg = parseWithRecurse(toStream(
"From: <x@example.org>\r\n" +
"To: <y@example.org>\r\n" +
"Subject: Testmail 2\r\n" +
"MIME-Version: 1.0\n" +
"Content-Type: multipart/mixed; boundary=frontier\n" +
"\n" +
"This is a message with multiple parts in MIME format.\n" +
"--frontier\n" +
"Content-Type: text/plain\n" +
"\n" +
"This is the body of the message.\n" +
"--frontier\n" +
"Content-Type: application/octet-stream\n" +
"Content-Transfer-Encoding: base64\n" +
"\n" +
"PGh0bWw+CiAgPGhlYWQ+CiAgPC9oZWFkPgogIDxib2R5PgogICAgPHA+VGhpcyBpcyB0aGUg\n" +
"Ym9keSBvZiB0aGUgbWVzc2FnZS48L3A+CiAgPC9ib2R5Pgo8L2h0bWw+Cg=\n" +
"--frontier--"));
"To: <y@example.org>\r\n" +
"Subject: Testmail 2\r\n" +
"MIME-Version: 1.0\n" +
"Content-Type: multipart/mixed; boundary=frontier\n" +
"\n" +
"This is a message with multiple parts in MIME format.\n" +
"--frontier\n" +
"Content-Type: text/plain\n" +
"\n" +
"This is the body of the message.\n" +
"--frontier\n" +
"Content-Type: application/octet-stream\n" +
"Content-Transfer-Encoding: base64\n" +
"\n" +
"PGh0bWw+CiAgPGhlYWQ+CiAgPC9oZWFkPgogIDxib2R5PgogICAgPHA+VGhpcyBpcyB0aGUg\n" +
"Ym9keSBvZiB0aGUgbWVzc2FnZS48L3A+CiAgPC9ib2R5Pgo8L2h0bWw+Cg=\n" +
"--frontier--"));
checkAddresses(msg.getFrom(), "x@example.org");
checkAddresses(msg.getRecipients(RecipientType.TO), "y@example.org");
@ -146,41 +152,42 @@ public class MimeMessageParseTest {
checkLeafParts(msg,
"This is the body of the message.",
"<html>\n" +
" <head>\n" +
" </head>\n" +
" <body>\n" +
" <p>This is the body of the message.</p>\n" +
" </body>\n" +
"</html>\n" +
"");
" <head>\n" +
" </head>\n" +
" <body>\n" +
" <p>This is the body of the message.</p>\n" +
" </body>\n" +
"</html>\n" +
"");
}
@Test public void testMultipartTwoLayersRecurse() throws Exception {
@Test
public void testMultipartTwoLayersRecurse() throws Exception {
MimeMessage msg = parseWithRecurse(toStream(
"From: <x@example.org>\r\n" +
"To: <y@example.org>\r\n" +
"Subject: Testmail 2\r\n" +
"MIME-Version: 1.0\n" +
"Content-Type: multipart/mixed; boundary=1\n" +
"\n" +
"This is a message with multiple parts in MIME format.\n" +
"--1\n" +
"Content-Type: text/plain\n" +
"\n" +
"some text in the first part\n" +
"--1\n" +
"Content-Type: multipart/alternative; boundary=2\n" +
"\n" +
"--2\n" +
"Content-Type: text/plain\n" +
"\n" +
"alternative 1\n" +
"--2\n" +
"Content-Type: text/plain\n" +
"\n" +
"alternative 2\n" +
"--2--\n" +
"--1--"));
"To: <y@example.org>\r\n" +
"Subject: Testmail 2\r\n" +
"MIME-Version: 1.0\n" +
"Content-Type: multipart/mixed; boundary=1\n" +
"\n" +
"This is a message with multiple parts in MIME format.\n" +
"--1\n" +
"Content-Type: text/plain\n" +
"\n" +
"some text in the first part\n" +
"--1\n" +
"Content-Type: multipart/alternative; boundary=2\n" +
"\n" +
"--2\n" +
"Content-Type: text/plain\n" +
"\n" +
"alternative 1\n" +
"--2\n" +
"Content-Type: text/plain\n" +
"\n" +
"alternative 2\n" +
"--2--\n" +
"--1--"));
checkAddresses(msg.getFrom(), "x@example.org");
checkAddresses(msg.getRecipients(RecipientType.TO), "y@example.org");

View File

@ -5,8 +5,10 @@ import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class MimeUtilityTest {
@Test public void testGetHeaderParameter() {
public class MimeUtilityTest {
@Test
public void testGetHeaderParameter() {
String result;
/* Test edge cases */
@ -32,7 +34,7 @@ public class MimeUtilityTest {
result = MimeUtility.getHeaderParameter("name=\"value\"", "name");
assertEquals("value", result);
result = MimeUtility.getHeaderParameter("name = \"value\"" , "name");
result = MimeUtility.getHeaderParameter("name = \"value\"", "name");
assertEquals("value", result);
result = MimeUtility.getHeaderParameter("name=\"\"", "name");