Loading app/core/src/test/java/com/fsck/k9/message/MessageBuilderTest.java +8 −4 Original line number Diff line number Diff line Loading @@ -84,7 +84,8 @@ public class MessageBuilderTest extends RobolectricTest { "text =E2=98=AD"; private static final String MESSAGE_CONTENT_WITH_ATTACH = "" + "Content-Type: multipart/mixed; boundary=\"" + BOUNDARY_1 + "\"\r\n" + "Content-Type: multipart/mixed;\r\n" + " boundary=" + BOUNDARY_1 + "\r\n" + "Content-Transfer-Encoding: 7bit\r\n" + "\r\n" + "--" + BOUNDARY_1 + "\r\n" + Loading @@ -107,7 +108,8 @@ public class MessageBuilderTest extends RobolectricTest { "--" + BOUNDARY_1 + "--\r\n"; private static final String MESSAGE_CONTENT_WITH_LONG_FILE_NAME = "Content-Type: multipart/mixed; boundary=\"" + BOUNDARY_1 + "\"\r\n" + "Content-Type: multipart/mixed;\r\n" + " boundary=" + BOUNDARY_1 + "\r\n" + "Content-Transfer-Encoding: 7bit\r\n" + "\r\n" + "--" + BOUNDARY_1 + "\r\n" + Loading @@ -133,7 +135,8 @@ public class MessageBuilderTest extends RobolectricTest { private static final String ATTACHMENT_FILENAME_NON_ASCII = "テスト文書.txt"; private static final String MESSAGE_CONTENT_WITH_ATTACH_NON_ASCII_FILENAME = "" + "Content-Type: multipart/mixed; boundary=\"" + BOUNDARY_1 + "\"\r\n" + "Content-Type: multipart/mixed;\r\n" + " boundary=" + BOUNDARY_1 + "\r\n" + "Content-Transfer-Encoding: 7bit\r\n" + "\r\n" + "--" + BOUNDARY_1 + "\r\n" + Loading @@ -156,7 +159,8 @@ public class MessageBuilderTest extends RobolectricTest { "--" + BOUNDARY_1 + "--\r\n"; private static final String MESSAGE_CONTENT_WITH_MESSAGE_ATTACH = "" + "Content-Type: multipart/mixed; boundary=\"" + BOUNDARY_1 + "\"\r\n" + "Content-Type: multipart/mixed;\r\n" + " boundary=" + BOUNDARY_1 + "\r\n" + "Content-Transfer-Encoding: 7bit\r\n" + "\r\n" + "--" + BOUNDARY_1 + "\r\n" + Loading mail/common/src/main/java/com/fsck/k9/mail/internet/Headers.kt +16 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,22 @@ object Headers { return MimeParameterEncoder.encode(mimeType, mapOf("name" to name)) } @JvmStatic fun contentType(mimeType: String, charset: String, name: String?): String { val parameters = if (name == null) { mapOf("charset" to charset) } else { mapOf("charset" to charset, "name" to name) } return MimeParameterEncoder.encode(mimeType, parameters) } @JvmStatic fun contentTypeForMultipart(mimeType: String, boundary: String): String { return MimeParameterEncoder.encode(mimeType, mapOf("boundary" to boundary)) } @JvmStatic @JvmOverloads fun contentDisposition(disposition: String, fileName: String, size: Long? = null): String { Loading mail/common/src/main/java/com/fsck/k9/mail/internet/MimeMessageHelper.java +9 −11 Original line number Diff line number Diff line Loading @@ -23,23 +23,21 @@ public class MimeMessageHelper { if (body instanceof Multipart) { Multipart multipart = ((Multipart) body); multipart.setParent(part); String mimeType = multipart.getMimeType(); String contentType = String.format("%s; boundary=\"%s\"", mimeType, multipart.getBoundary()); String contentType = Headers.contentTypeForMultipart(multipart.getMimeType(), multipart.getBoundary()); part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, contentType); // note: if this is ever changed to 8bit, multipart/signed parts must always be 7bit! setEncoding(part, MimeUtil.ENC_7BIT); } else if (body instanceof TextBody) { String contentType; if (MimeUtility.mimeTypeMatches(part.getMimeType(), "text/*")) { contentType = String.format("%s;\r\n charset=utf-8", part.getMimeType()); String name = MimeUtility.getHeaderParameter(part.getContentType(), "name"); if (name != null) { contentType += String.format(";\r\n name=\"%s\"", name); } MimeValue contentTypeHeader = MimeParameterDecoder.decode(part.getContentType()); String mimeType = contentTypeHeader.getValue(); if (MimeUtility.mimeTypeMatches(mimeType, "text/*")) { String name = contentTypeHeader.getParameters().get("name"); String contentType = Headers.contentType(mimeType, "utf-8", name); part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, contentType); } else { contentType = part.getMimeType(); part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, mimeType); } part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, contentType); setEncoding(part, MimeUtil.ENC_QUOTED_PRINTABLE); } else if (body instanceof RawDataBody) { Loading mail/common/src/test/java/com/fsck/k9/mail/MessageTest.kt +12 −6 Original line number Diff line number Diff line Loading @@ -67,7 +67,8 @@ class MessageTest { Subject: Test Message Date: Wed, 28 Aug 2013 08:51:09 -0400 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----Boundary103" Content-Type: multipart/mixed; boundary=----Boundary103 Content-Transfer-Encoding: 7bit ------Boundary103 Loading Loading @@ -96,7 +97,8 @@ class MessageTest { Subject: Test Message Date: Wed, 28 Aug 2013 08:51:09 -0400 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----Boundary102" Content-Type: multipart/mixed; boundary=----Boundary102 Content-Transfer-Encoding: 7bit ------Boundary102 Loading Loading @@ -125,7 +127,8 @@ class MessageTest { Subject: Test Message Date: Wed, 28 Aug 2013 08:51:09 -0400 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----Boundary101" Content-Type: multipart/mixed; boundary=----Boundary101 Content-Transfer-Encoding: 7bit ------Boundary101 Loading Loading @@ -163,7 +166,8 @@ class MessageTest { bodyPart.writeTo(out) assertThat(out.toString()).isEqualTo(""" Content-Type: multipart/mixed; boundary="----Boundary103" Content-Type: multipart/mixed; boundary=----Boundary103 Content-Transfer-Encoding: 7bit ------Boundary103 Loading Loading @@ -192,7 +196,8 @@ class MessageTest { Subject: Test Message Date: Wed, 28 Aug 2013 08:51:09 -0400 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----Boundary102" Content-Type: multipart/mixed; boundary=----Boundary102 Content-Transfer-Encoding: 7bit ------Boundary102 Loading Loading @@ -221,7 +226,8 @@ class MessageTest { Subject: Test Message Date: Wed, 28 Aug 2013 08:51:09 -0400 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----Boundary101" Content-Type: multipart/mixed; boundary=----Boundary101 Content-Transfer-Encoding: 7bit ------Boundary101 Loading Loading
app/core/src/test/java/com/fsck/k9/message/MessageBuilderTest.java +8 −4 Original line number Diff line number Diff line Loading @@ -84,7 +84,8 @@ public class MessageBuilderTest extends RobolectricTest { "text =E2=98=AD"; private static final String MESSAGE_CONTENT_WITH_ATTACH = "" + "Content-Type: multipart/mixed; boundary=\"" + BOUNDARY_1 + "\"\r\n" + "Content-Type: multipart/mixed;\r\n" + " boundary=" + BOUNDARY_1 + "\r\n" + "Content-Transfer-Encoding: 7bit\r\n" + "\r\n" + "--" + BOUNDARY_1 + "\r\n" + Loading @@ -107,7 +108,8 @@ public class MessageBuilderTest extends RobolectricTest { "--" + BOUNDARY_1 + "--\r\n"; private static final String MESSAGE_CONTENT_WITH_LONG_FILE_NAME = "Content-Type: multipart/mixed; boundary=\"" + BOUNDARY_1 + "\"\r\n" + "Content-Type: multipart/mixed;\r\n" + " boundary=" + BOUNDARY_1 + "\r\n" + "Content-Transfer-Encoding: 7bit\r\n" + "\r\n" + "--" + BOUNDARY_1 + "\r\n" + Loading @@ -133,7 +135,8 @@ public class MessageBuilderTest extends RobolectricTest { private static final String ATTACHMENT_FILENAME_NON_ASCII = "テスト文書.txt"; private static final String MESSAGE_CONTENT_WITH_ATTACH_NON_ASCII_FILENAME = "" + "Content-Type: multipart/mixed; boundary=\"" + BOUNDARY_1 + "\"\r\n" + "Content-Type: multipart/mixed;\r\n" + " boundary=" + BOUNDARY_1 + "\r\n" + "Content-Transfer-Encoding: 7bit\r\n" + "\r\n" + "--" + BOUNDARY_1 + "\r\n" + Loading @@ -156,7 +159,8 @@ public class MessageBuilderTest extends RobolectricTest { "--" + BOUNDARY_1 + "--\r\n"; private static final String MESSAGE_CONTENT_WITH_MESSAGE_ATTACH = "" + "Content-Type: multipart/mixed; boundary=\"" + BOUNDARY_1 + "\"\r\n" + "Content-Type: multipart/mixed;\r\n" + " boundary=" + BOUNDARY_1 + "\r\n" + "Content-Transfer-Encoding: 7bit\r\n" + "\r\n" + "--" + BOUNDARY_1 + "\r\n" + Loading
mail/common/src/main/java/com/fsck/k9/mail/internet/Headers.kt +16 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,22 @@ object Headers { return MimeParameterEncoder.encode(mimeType, mapOf("name" to name)) } @JvmStatic fun contentType(mimeType: String, charset: String, name: String?): String { val parameters = if (name == null) { mapOf("charset" to charset) } else { mapOf("charset" to charset, "name" to name) } return MimeParameterEncoder.encode(mimeType, parameters) } @JvmStatic fun contentTypeForMultipart(mimeType: String, boundary: String): String { return MimeParameterEncoder.encode(mimeType, mapOf("boundary" to boundary)) } @JvmStatic @JvmOverloads fun contentDisposition(disposition: String, fileName: String, size: Long? = null): String { Loading
mail/common/src/main/java/com/fsck/k9/mail/internet/MimeMessageHelper.java +9 −11 Original line number Diff line number Diff line Loading @@ -23,23 +23,21 @@ public class MimeMessageHelper { if (body instanceof Multipart) { Multipart multipart = ((Multipart) body); multipart.setParent(part); String mimeType = multipart.getMimeType(); String contentType = String.format("%s; boundary=\"%s\"", mimeType, multipart.getBoundary()); String contentType = Headers.contentTypeForMultipart(multipart.getMimeType(), multipart.getBoundary()); part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, contentType); // note: if this is ever changed to 8bit, multipart/signed parts must always be 7bit! setEncoding(part, MimeUtil.ENC_7BIT); } else if (body instanceof TextBody) { String contentType; if (MimeUtility.mimeTypeMatches(part.getMimeType(), "text/*")) { contentType = String.format("%s;\r\n charset=utf-8", part.getMimeType()); String name = MimeUtility.getHeaderParameter(part.getContentType(), "name"); if (name != null) { contentType += String.format(";\r\n name=\"%s\"", name); } MimeValue contentTypeHeader = MimeParameterDecoder.decode(part.getContentType()); String mimeType = contentTypeHeader.getValue(); if (MimeUtility.mimeTypeMatches(mimeType, "text/*")) { String name = contentTypeHeader.getParameters().get("name"); String contentType = Headers.contentType(mimeType, "utf-8", name); part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, contentType); } else { contentType = part.getMimeType(); part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, mimeType); } part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, contentType); setEncoding(part, MimeUtil.ENC_QUOTED_PRINTABLE); } else if (body instanceof RawDataBody) { Loading
mail/common/src/test/java/com/fsck/k9/mail/MessageTest.kt +12 −6 Original line number Diff line number Diff line Loading @@ -67,7 +67,8 @@ class MessageTest { Subject: Test Message Date: Wed, 28 Aug 2013 08:51:09 -0400 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----Boundary103" Content-Type: multipart/mixed; boundary=----Boundary103 Content-Transfer-Encoding: 7bit ------Boundary103 Loading Loading @@ -96,7 +97,8 @@ class MessageTest { Subject: Test Message Date: Wed, 28 Aug 2013 08:51:09 -0400 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----Boundary102" Content-Type: multipart/mixed; boundary=----Boundary102 Content-Transfer-Encoding: 7bit ------Boundary102 Loading Loading @@ -125,7 +127,8 @@ class MessageTest { Subject: Test Message Date: Wed, 28 Aug 2013 08:51:09 -0400 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----Boundary101" Content-Type: multipart/mixed; boundary=----Boundary101 Content-Transfer-Encoding: 7bit ------Boundary101 Loading Loading @@ -163,7 +166,8 @@ class MessageTest { bodyPart.writeTo(out) assertThat(out.toString()).isEqualTo(""" Content-Type: multipart/mixed; boundary="----Boundary103" Content-Type: multipart/mixed; boundary=----Boundary103 Content-Transfer-Encoding: 7bit ------Boundary103 Loading Loading @@ -192,7 +196,8 @@ class MessageTest { Subject: Test Message Date: Wed, 28 Aug 2013 08:51:09 -0400 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----Boundary102" Content-Type: multipart/mixed; boundary=----Boundary102 Content-Transfer-Encoding: 7bit ------Boundary102 Loading Loading @@ -221,7 +226,8 @@ class MessageTest { Subject: Test Message Date: Wed, 28 Aug 2013 08:51:09 -0400 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----Boundary101" Content-Type: multipart/mixed; boundary=----Boundary101 Content-Transfer-Encoding: 7bit ------Boundary101 Loading