remove 8bit encoding tests

This commit is contained in:
Vincent Breitmoser 2016-08-08 19:47:48 +02:00
parent 674cd3bf5a
commit 042fc3de6d

View file

@ -1,5 +1,6 @@
package com.fsck.k9.mail; package com.fsck.k9.mail;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
@ -8,8 +9,7 @@ import java.io.OutputStream;
import java.util.Date; import java.util.Date;
import java.util.TimeZone; import java.util.TimeZone;
import android.support.test.InstrumentationRegistry; import android.content.Context;
import android.support.test.runner.AndroidJUnit4;
import com.fsck.k9.mail.Message.RecipientType; import com.fsck.k9.mail.Message.RecipientType;
import com.fsck.k9.mail.internet.BinaryTempFileBody; import com.fsck.k9.mail.internet.BinaryTempFileBody;
@ -26,137 +26,27 @@ import org.apache.james.mime4j.util.MimeUtil;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
@RunWith(AndroidJUnit4.class) @RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE, sdk = 21)
public class MessageTest { public class MessageTest {
private Context context;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Tokyo")); context = RuntimeEnvironment.application;
BinaryTempFileBody.setTempDirectory(InstrumentationRegistry.getTargetContext().getCacheDir());
}
private static final String EIGHT_BIT_RESULT = TimeZone.setDefault(TimeZone.getTimeZone("Asia/Tokyo"));
"From: from@example.com\r\n" BinaryTempFileBody.setTempDirectory(context.getCacheDir());
+ "To: to@example.com\r\n" }
+ "Subject: Test Message\r\n"
+ "Date: Wed, 28 Aug 2013 08:51:09 -0400\r\n"
+ "MIME-Version: 1.0\r\n"
+ "Content-Type: multipart/mixed; boundary=\"----Boundary103\"\r\n"
+ "Content-Transfer-Encoding: 8bit\r\n"
+ "\r\n"
+ "------Boundary103\r\n"
+ "Content-Type: text/plain;\r\n"
+ " charset=utf-8\r\n"
+ "Content-Transfer-Encoding: 8bit\r\n"
+ "\r\n"
+ "Testing.\r\n"
+ "This is a text body with some greek characters.\r\n"
+ "αβγδεζηθ\r\n"
+ "End of test.\r\n"
+ "\r\n"
+ "------Boundary103\r\n"
+ "Content-Type: text/plain;\r\n"
+ " charset=utf-8\r\n"
+ "Content-Transfer-Encoding: quoted-printable\r\n"
+ "\r\n"
+ "Testing=2E\r\n"
+ "This is a text body with some greek characters=2E\r\n"
+ "=CE=B1=CE=B2=CE=B3=CE=B4=CE=B5=CE=B6=CE=B7=CE=B8\r\n"
+ "End of test=2E\r\n"
+ "\r\n"
+ "------Boundary103\r\n"
+ "Content-Type: application/octet-stream\r\n"
+ "Content-Transfer-Encoding: base64\r\n"
+ "\r\n"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\r\n"
+ "\r\n"
+ "------Boundary103\r\n"
+ "Content-Type: message/rfc822\r\n"
+ "Content-Disposition: attachment\r\n"
+ "Content-Transfer-Encoding: 8bit\r\n"
+ "\r\n"
+ "From: from@example.com\r\n"
+ "To: to@example.com\r\n"
+ "Subject: Test Message\r\n"
+ "Date: Wed, 28 Aug 2013 08:51:09 -0400\r\n"
+ "MIME-Version: 1.0\r\n"
+ "Content-Type: multipart/mixed; boundary=\"----Boundary102\"\r\n"
+ "Content-Transfer-Encoding: 8bit\r\n"
+ "\r\n"
+ "------Boundary102\r\n"
+ "Content-Type: text/plain;\r\n"
+ " charset=utf-8\r\n"
+ "Content-Transfer-Encoding: 8bit\r\n"
+ "\r\n"
+ "Testing.\r\n"
+ "This is a text body with some greek characters.\r\n"
+ "αβγδεζηθ\r\n"
+ "End of test.\r\n"
+ "\r\n"
+ "------Boundary102\r\n"
+ "Content-Type: text/plain;\r\n"
+ " charset=utf-8\r\n"
+ "Content-Transfer-Encoding: quoted-printable\r\n"
+ "\r\n"
+ "Testing=2E\r\n"
+ "This is a text body with some greek characters=2E\r\n"
+ "=CE=B1=CE=B2=CE=B3=CE=B4=CE=B5=CE=B6=CE=B7=CE=B8\r\n"
+ "End of test=2E\r\n"
+ "\r\n"
+ "------Boundary102\r\n"
+ "Content-Type: application/octet-stream\r\n"
+ "Content-Transfer-Encoding: base64\r\n"
+ "\r\n"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\r\n"
+ "\r\n"
+ "------Boundary102\r\n"
+ "Content-Type: message/rfc822\r\n"
+ "Content-Disposition: attachment\r\n"
+ "Content-Transfer-Encoding: 8bit\r\n"
+ "\r\n"
+ "From: from@example.com\r\n"
+ "To: to@example.com\r\n"
+ "Subject: Test Message\r\n"
+ "Date: Wed, 28 Aug 2013 08:51:09 -0400\r\n"
+ "MIME-Version: 1.0\r\n"
+ "Content-Type: multipart/mixed; boundary=\"----Boundary101\"\r\n"
+ "Content-Transfer-Encoding: 8bit\r\n"
+ "\r\n"
+ "------Boundary101\r\n"
+ "Content-Type: text/plain;\r\n"
+ " charset=utf-8\r\n"
+ "Content-Transfer-Encoding: 8bit\r\n"
+ "\r\n"
+ "Testing.\r\n"
+ "This is a text body with some greek characters.\r\n"
+ "αβγδεζηθ\r\n"
+ "End of test.\r\n"
+ "\r\n"
+ "------Boundary101\r\n"
+ "Content-Type: text/plain;\r\n"
+ " charset=utf-8\r\n"
+ "Content-Transfer-Encoding: quoted-printable\r\n"
+ "\r\n"
+ "Testing=2E\r\n"
+ "This is a text body with some greek characters=2E\r\n"
+ "=CE=B1=CE=B2=CE=B3=CE=B4=CE=B5=CE=B6=CE=B7=CE=B8\r\n"
+ "End of test=2E\r\n"
+ "\r\n"
+ "------Boundary101\r\n"
+ "Content-Type: application/octet-stream\r\n"
+ "Content-Transfer-Encoding: base64\r\n"
+ "\r\n"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\r\n"
+ "\r\n"
+ "------Boundary101--\r\n"
+ "\r\n"
+ "------Boundary102--\r\n"
+ "\r\n"
+ "------Boundary103--\r\n";
private static final String SEVEN_BIT_RESULT = private static final String SEVEN_BIT_RESULT =
"From: from@example.com\r\n" "From: from@example.com\r\n"
@ -168,19 +58,9 @@ public class MessageTest {
+ "Content-Transfer-Encoding: 7bit\r\n" + "Content-Transfer-Encoding: 7bit\r\n"
+ "\r\n" + "\r\n"
+ "------Boundary103\r\n" + "------Boundary103\r\n"
+ "Content-Transfer-Encoding: quoted-printable\r\n"
+ "Content-Type: text/plain;\r\n" + "Content-Type: text/plain;\r\n"
+ " charset=utf-8\r\n" + " charset=utf-8\r\n"
+ "Content-Transfer-Encoding: quoted-printable\r\n"
+ "\r\n"
+ "Testing=2E\r\n"
+ "This is a text body with some greek characters=2E\r\n"
+ "=CE=B1=CE=B2=CE=B3=CE=B4=CE=B5=CE=B6=CE=B7=CE=B8\r\n"
+ "End of test=2E\r\n"
+ "\r\n"
+ "------Boundary103\r\n"
+ "Content-Type: text/plain;\r\n"
+ " charset=utf-8\r\n"
+ "Content-Transfer-Encoding: quoted-printable\r\n"
+ "\r\n" + "\r\n"
+ "Testing=2E\r\n" + "Testing=2E\r\n"
+ "This is a text body with some greek characters=2E\r\n" + "This is a text body with some greek characters=2E\r\n"
@ -207,19 +87,9 @@ public class MessageTest {
+ "Content-Transfer-Encoding: 7bit\r\n" + "Content-Transfer-Encoding: 7bit\r\n"
+ "\r\n" + "\r\n"
+ "------Boundary102\r\n" + "------Boundary102\r\n"
+ "Content-Transfer-Encoding: quoted-printable\r\n"
+ "Content-Type: text/plain;\r\n" + "Content-Type: text/plain;\r\n"
+ " charset=utf-8\r\n" + " charset=utf-8\r\n"
+ "Content-Transfer-Encoding: quoted-printable\r\n"
+ "\r\n"
+ "Testing=2E\r\n"
+ "This is a text body with some greek characters=2E\r\n"
+ "=CE=B1=CE=B2=CE=B3=CE=B4=CE=B5=CE=B6=CE=B7=CE=B8\r\n"
+ "End of test=2E\r\n"
+ "\r\n"
+ "------Boundary102\r\n"
+ "Content-Type: text/plain;\r\n"
+ " charset=utf-8\r\n"
+ "Content-Transfer-Encoding: quoted-printable\r\n"
+ "\r\n" + "\r\n"
+ "Testing=2E\r\n" + "Testing=2E\r\n"
+ "This is a text body with some greek characters=2E\r\n" + "This is a text body with some greek characters=2E\r\n"
@ -246,19 +116,9 @@ public class MessageTest {
+ "Content-Transfer-Encoding: 7bit\r\n" + "Content-Transfer-Encoding: 7bit\r\n"
+ "\r\n" + "\r\n"
+ "------Boundary101\r\n" + "------Boundary101\r\n"
+ "Content-Transfer-Encoding: quoted-printable\r\n"
+ "Content-Type: text/plain;\r\n" + "Content-Type: text/plain;\r\n"
+ " charset=utf-8\r\n" + " charset=utf-8\r\n"
+ "Content-Transfer-Encoding: quoted-printable\r\n"
+ "\r\n"
+ "Testing=2E\r\n"
+ "This is a text body with some greek characters=2E\r\n"
+ "=CE=B1=CE=B2=CE=B3=CE=B4=CE=B5=CE=B6=CE=B7=CE=B8\r\n"
+ "End of test=2E\r\n"
+ "\r\n"
+ "------Boundary101\r\n"
+ "Content-Type: text/plain;\r\n"
+ " charset=utf-8\r\n"
+ "Content-Transfer-Encoding: quoted-printable\r\n"
+ "\r\n" + "\r\n"
+ "Testing=2E\r\n" + "Testing=2E\r\n"
+ "This is a text body with some greek characters=2E\r\n" + "This is a text body with some greek characters=2E\r\n"
@ -279,22 +139,12 @@ public class MessageTest {
private static final String TO_BODY_PART_RESULT = private static final String TO_BODY_PART_RESULT =
"Content-Type: multipart/mixed; boundary=\"----Boundary103\"\r\n" "Content-Type: multipart/mixed; boundary=\"----Boundary103\"\r\n"
+ "Content-Transfer-Encoding: 8bit\r\n" + "Content-Transfer-Encoding: 7bit\r\n"
+ "\r\n" + "\r\n"
+ "------Boundary103\r\n" + "------Boundary103\r\n"
+ "Content-Type: text/plain;\r\n"
+ " charset=utf-8\r\n"
+ "Content-Transfer-Encoding: 8bit\r\n"
+ "\r\n"
+ "Testing.\r\n"
+ "This is a text body with some greek characters.\r\n"
+ "αβγδεζηθ\r\n"
+ "End of test.\r\n"
+ "\r\n"
+ "------Boundary103\r\n"
+ "Content-Type: text/plain;\r\n"
+ " charset=utf-8\r\n"
+ "Content-Transfer-Encoding: quoted-printable\r\n" + "Content-Transfer-Encoding: quoted-printable\r\n"
+ "Content-Type: text/plain;\r\n"
+ " charset=utf-8\r\n"
+ "\r\n" + "\r\n"
+ "Testing=2E\r\n" + "Testing=2E\r\n"
+ "This is a text body with some greek characters=2E\r\n" + "This is a text body with some greek characters=2E\r\n"
@ -310,7 +160,7 @@ public class MessageTest {
+ "------Boundary103\r\n" + "------Boundary103\r\n"
+ "Content-Type: message/rfc822\r\n" + "Content-Type: message/rfc822\r\n"
+ "Content-Disposition: attachment\r\n" + "Content-Disposition: attachment\r\n"
+ "Content-Transfer-Encoding: 8bit\r\n" + "Content-Transfer-Encoding: 7bit\r\n"
+ "\r\n" + "\r\n"
+ "From: from@example.com\r\n" + "From: from@example.com\r\n"
+ "To: to@example.com\r\n" + "To: to@example.com\r\n"
@ -318,22 +168,12 @@ public class MessageTest {
+ "Date: Wed, 28 Aug 2013 08:51:09 -0400\r\n" + "Date: Wed, 28 Aug 2013 08:51:09 -0400\r\n"
+ "MIME-Version: 1.0\r\n" + "MIME-Version: 1.0\r\n"
+ "Content-Type: multipart/mixed; boundary=\"----Boundary102\"\r\n" + "Content-Type: multipart/mixed; boundary=\"----Boundary102\"\r\n"
+ "Content-Transfer-Encoding: 8bit\r\n" + "Content-Transfer-Encoding: 7bit\r\n"
+ "\r\n" + "\r\n"
+ "------Boundary102\r\n" + "------Boundary102\r\n"
+ "Content-Type: text/plain;\r\n"
+ " charset=utf-8\r\n"
+ "Content-Transfer-Encoding: 8bit\r\n"
+ "\r\n"
+ "Testing.\r\n"
+ "This is a text body with some greek characters.\r\n"
+ "αβγδεζηθ\r\n"
+ "End of test.\r\n"
+ "\r\n"
+ "------Boundary102\r\n"
+ "Content-Type: text/plain;\r\n"
+ " charset=utf-8\r\n"
+ "Content-Transfer-Encoding: quoted-printable\r\n" + "Content-Transfer-Encoding: quoted-printable\r\n"
+ "Content-Type: text/plain;\r\n"
+ " charset=utf-8\r\n"
+ "\r\n" + "\r\n"
+ "Testing=2E\r\n" + "Testing=2E\r\n"
+ "This is a text body with some greek characters=2E\r\n" + "This is a text body with some greek characters=2E\r\n"
@ -349,7 +189,7 @@ public class MessageTest {
+ "------Boundary102\r\n" + "------Boundary102\r\n"
+ "Content-Type: message/rfc822\r\n" + "Content-Type: message/rfc822\r\n"
+ "Content-Disposition: attachment\r\n" + "Content-Disposition: attachment\r\n"
+ "Content-Transfer-Encoding: 8bit\r\n" + "Content-Transfer-Encoding: 7bit\r\n"
+ "\r\n" + "\r\n"
+ "From: from@example.com\r\n" + "From: from@example.com\r\n"
+ "To: to@example.com\r\n" + "To: to@example.com\r\n"
@ -357,22 +197,12 @@ public class MessageTest {
+ "Date: Wed, 28 Aug 2013 08:51:09 -0400\r\n" + "Date: Wed, 28 Aug 2013 08:51:09 -0400\r\n"
+ "MIME-Version: 1.0\r\n" + "MIME-Version: 1.0\r\n"
+ "Content-Type: multipart/mixed; boundary=\"----Boundary101\"\r\n" + "Content-Type: multipart/mixed; boundary=\"----Boundary101\"\r\n"
+ "Content-Transfer-Encoding: 8bit\r\n" + "Content-Transfer-Encoding: 7bit\r\n"
+ "\r\n" + "\r\n"
+ "------Boundary101\r\n" + "------Boundary101\r\n"
+ "Content-Type: text/plain;\r\n"
+ " charset=utf-8\r\n"
+ "Content-Transfer-Encoding: 8bit\r\n"
+ "\r\n"
+ "Testing.\r\n"
+ "This is a text body with some greek characters.\r\n"
+ "αβγδεζηθ\r\n"
+ "End of test.\r\n"
+ "\r\n"
+ "------Boundary101\r\n"
+ "Content-Type: text/plain;\r\n"
+ " charset=utf-8\r\n"
+ "Content-Transfer-Encoding: quoted-printable\r\n" + "Content-Transfer-Encoding: quoted-printable\r\n"
+ "Content-Type: text/plain;\r\n"
+ " charset=utf-8\r\n"
+ "\r\n" + "\r\n"
+ "Testing=2E\r\n" + "Testing=2E\r\n"
+ "This is a text body with some greek characters=2E\r\n" + "This is a text body with some greek characters=2E\r\n"
@ -423,19 +253,12 @@ public class MessageTest {
MimeMessage message; MimeMessage message;
ByteArrayOutputStream out; ByteArrayOutputStream out;
BinaryTempFileBody.setTempDirectory(InstrumentationRegistry.getTargetContext().getCacheDir()); BinaryTempFileBody.setTempDirectory(context.getCacheDir());
mMimeBoundary = 101; mMimeBoundary = 101;
message = nestedMessage(nestedMessage(sampleMessage())); message = nestedMessage(nestedMessage(sampleMessage()));
out = new ByteArrayOutputStream(); out = new ByteArrayOutputStream();
message.writeTo(out); message.writeTo(out);
assertEquals(EIGHT_BIT_RESULT, out.toString());
mMimeBoundary = 101;
message = nestedMessage(nestedMessage(sampleMessage()));
message.setUsing7bitTransport();
out = new ByteArrayOutputStream();
message.writeTo(out);
assertEquals(SEVEN_BIT_RESULT, out.toString()); assertEquals(SEVEN_BIT_RESULT, out.toString());
} }
@ -452,7 +275,7 @@ public class MessageTest {
MimeBodyPart bodyPart = new MimeBodyPart(tempMessageBody, "message/rfc822"); MimeBodyPart bodyPart = new MimeBodyPart(tempMessageBody, "message/rfc822");
bodyPart.setHeader(MimeHeader.HEADER_CONTENT_DISPOSITION, "attachment"); bodyPart.setHeader(MimeHeader.HEADER_CONTENT_DISPOSITION, "attachment");
bodyPart.setEncoding(MimeUtil.ENC_8BIT); bodyPart.setEncoding(MimeUtil.ENC_7BIT);
MimeMessage parentMessage = sampleMessage(); MimeMessage parentMessage = sampleMessage();
((Multipart) parentMessage.getBody()).addBodyPart(bodyPart); ((Multipart) parentMessage.getBody()).addBodyPart(bodyPart);
@ -466,11 +289,10 @@ public class MessageTest {
message.setRecipient(RecipientType.TO, new Address("to@example.com")); message.setRecipient(RecipientType.TO, new Address("to@example.com"));
message.setSubject("Test Message"); message.setSubject("Test Message");
message.setHeader("Date", "Wed, 28 Aug 2013 08:51:09 -0400"); message.setHeader("Date", "Wed, 28 Aug 2013 08:51:09 -0400");
message.setEncoding(MimeUtil.ENC_8BIT); message.setEncoding(MimeUtil.ENC_7BIT);
MimeMultipart multipartBody = new MimeMultipart("multipart/mixed", generateBoundary()); MimeMultipart multipartBody = new MimeMultipart("multipart/mixed", generateBoundary());
multipartBody.addBodyPart(textBodyPart(MimeUtil.ENC_8BIT)); multipartBody.addBodyPart(textBodyPart());
multipartBody.addBodyPart(textBodyPart(MimeUtil.ENC_QUOTED_PRINTABLE));
multipartBody.addBodyPart(binaryBodyPart()); multipartBody.addBodyPart(binaryBodyPart());
MimeMessageHelper.setBody(message, multipartBody); MimeMessageHelper.setBody(message, multipartBody);
@ -501,17 +323,17 @@ public class MessageTest {
return bodyPart; return bodyPart;
} }
private MimeBodyPart textBodyPart(String encoding) private MimeBodyPart textBodyPart() throws MessagingException {
throws MessagingException {
TextBody textBody = new TextBody( TextBody textBody = new TextBody(
"Testing.\r\n" "Testing.\r\n"
+ "This is a text body with some greek characters.\r\n" + "This is a text body with some greek characters.\r\n"
+ "αβγδεζηθ\r\n" + "αβγδεζηθ\r\n"
+ "End of test.\r\n"); + "End of test.\r\n");
textBody.setCharset("utf-8"); textBody.setCharset("utf-8");
MimeBodyPart bodyPart = new MimeBodyPart(textBody, "text/plain");
MimeBodyPart bodyPart = new MimeBodyPart();
MimeMessageHelper.setBody(bodyPart, textBody);
CharsetSupport.setCharset("utf-8", bodyPart); CharsetSupport.setCharset("utf-8", bodyPart);
bodyPart.setEncoding(encoding);
return bodyPart; return bodyPart;
} }
@ -524,7 +346,7 @@ public class MessageTest {
MimeMessage message; MimeMessage message;
ByteArrayOutputStream out; ByteArrayOutputStream out;
BinaryTempFileBody.setTempDirectory(InstrumentationRegistry.getTargetContext().getCacheDir()); BinaryTempFileBody.setTempDirectory(context.getCacheDir());
mMimeBoundary = 101; mMimeBoundary = 101;
message = nestedMessage(nestedMessage(sampleMessage())); message = nestedMessage(nestedMessage(sampleMessage()));