From 0beff4cdb8f51e1a53911a95b70d3a12823713aa Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 6 Dec 2016 23:27:13 +0100 Subject: [PATCH 1/2] use message/rfc822 as default content type for multipart/digest subparts --- .../java/com/fsck/k9/mail/internet/MimeBodyPart.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/k9mail-library/src/main/java/com/fsck/k9/mail/internet/MimeBodyPart.java b/k9mail-library/src/main/java/com/fsck/k9/mail/internet/MimeBodyPart.java index 5a784cb14..f5e5725ec 100644 --- a/k9mail-library/src/main/java/com/fsck/k9/mail/internet/MimeBodyPart.java +++ b/k9mail-library/src/main/java/com/fsck/k9/mail/internet/MimeBodyPart.java @@ -4,6 +4,7 @@ package com.fsck.k9.mail.internet; import com.fsck.k9.mail.Body; import com.fsck.k9.mail.BodyPart; import com.fsck.k9.mail.MessagingException; +import com.fsck.k9.mail.Multipart; import java.io.BufferedWriter; import java.io.IOException; @@ -93,7 +94,14 @@ public class MimeBodyPart extends BodyPart { @Override public String getContentType() { String contentType = getFirstHeader(MimeHeader.HEADER_CONTENT_TYPE); - return (contentType == null) ? "text/plain" : MimeUtility.unfoldAndDecode(contentType); + if (contentType != null) { + return MimeUtility.unfoldAndDecode(contentType); + } + Multipart parent = getParent(); + if (parent != null && "multipart/digest".equals(parent.getMimeType())) { + return "message/rfc822"; + } + return "text/plain"; } @Override From 7bd85189ce65683fe3b99b2e79a07f91394e61c7 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Wed, 7 Dec 2016 00:03:15 +0100 Subject: [PATCH 2/2] add test for multipart/digest message --- .../MessageViewInfoExtractorTest.java | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/k9mail/src/test/java/com/fsck/k9/mailstore/MessageViewInfoExtractorTest.java b/k9mail/src/test/java/com/fsck/k9/mailstore/MessageViewInfoExtractorTest.java index 995b02436..ca97e8e79 100644 --- a/k9mail/src/test/java/com/fsck/k9/mailstore/MessageViewInfoExtractorTest.java +++ b/k9mail/src/test/java/com/fsck/k9/mailstore/MessageViewInfoExtractorTest.java @@ -1,6 +1,7 @@ package com.fsck.k9.mailstore; +import java.io.ByteArrayInputStream; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -25,6 +26,7 @@ import com.fsck.k9.mail.internet.MimeMessageHelper; import com.fsck.k9.mail.internet.MimeMultipart; import com.fsck.k9.mail.internet.TextBody; import com.fsck.k9.mail.internet.Viewable; +import com.fsck.k9.mail.internet.Viewable.MessageHeader; import com.fsck.k9.mailstore.MessageViewInfoExtractor.ViewableExtractedText; import org.junit.Before; import org.junit.Test; @@ -266,6 +268,71 @@ public class MessageViewInfoExtractorTest { assertEquals(expectedHtml, getHtmlBodyText(container.html)); } + @Test + public void testMultipartDigestWithMessages() throws Exception { + String data = "Content-Type: multipart/digest; boundary=\"bndry\"\r\n" + + "\r\n" + + "--bndry\r\n" + + "\r\n" + + "Content-Type: text/plain\r\n" + + "\r\n" + + "text body of first message\r\n" + + "\r\n" + + "--bndry\r\n" + + "\r\n" + + "Subject: subject of second message\r\n" + + "Content-Type: multipart/alternative; boundary=\"bndry2\"\r\n" + + "\r\n" + + "--bndry2\r\n" + + "Content-Type: text/plain\r\n" + + "\r\n" + + "text part of second message\r\n" + + "\r\n" + + "--bndry2\r\n" + + "Content-Type: text/html\"\r\n" + + "\r\n" + + "html part of second message\r\n" + + "\r\n" + + "--bndry2--\r\n" + + "\r\n" + + "--bndry--\r\n"; + MimeMessage message = MimeMessage.parseMimeMessage(new ByteArrayInputStream(data.getBytes()), false); + + // Extract text + List outputNonViewableParts = new ArrayList<>(); + ArrayList outputViewableParts = new ArrayList<>(); + MessageExtractor.findViewablesAndAttachments(message, outputViewableParts, outputNonViewableParts); + + String expectedExtractedText = "Subject: (No subject)\r\n" + + "\r\n" + + "text body of first message\r\n" + + "\r\n" + + "\r\n" + + "------------------------------------------------------------------------\r\n" + + "\r\n" + + "Subject: subject of second message\r\n" + + "\r\n" + + "text part of second message\r\n"; + String expectedHtmlText = "" + + "" + + "
Subject:(No subject)
" + + "
text body of first message
" + + "

" + + "" + + "" + + "
Subject:subject of second message
" + + "
text part of second message
"; + + + assertEquals(4, outputViewableParts.size()); + assertEquals("subject of second message", ((MessageHeader) outputViewableParts.get(2)).getMessage().getSubject()); + + ViewableExtractedText firstMessageExtractedText = + messageViewInfoExtractor.extractTextFromViewables(outputViewableParts); + assertEquals(expectedExtractedText, firstMessageExtractedText.text); + assertEquals(expectedHtmlText, getHtmlBodyText(firstMessageExtractedText.html)); + } + private static String getHtmlBodyText(String htmlText) { htmlText = htmlText.substring(htmlText.indexOf("") +6); htmlText = htmlText.substring(0, htmlText.indexOf(""));