use of com.fsck.k9.mail.internet.Viewable.Alternative in project k-9 by k9mail.
the class MessageDecryptVerifierTest method findPrimaryCryptoPart_withMultipartAlternativeContainingPgpInline.
@Test
public void findPrimaryCryptoPart_withMultipartAlternativeContainingPgpInline() throws Exception {
List<Part> outputExtraParts = new ArrayList<>();
BodyPart pgpInlinePart = bodypart("text/plain", PGP_INLINE_DATA);
Message message = messageFromBody(multipart("alternative", pgpInlinePart, bodypart("text/html")));
Part cryptoPart = MessageDecryptVerifier.findPrimaryEncryptedOrSignedPart(message, outputExtraParts);
assertSame(pgpInlinePart, cryptoPart);
}
use of com.fsck.k9.mail.internet.Viewable.Alternative in project k-9 by k9mail.
the class MessageViewInfoExtractorTest method testMultipartDigestWithMessages.
@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<Part> outputNonViewableParts = new ArrayList<>();
ArrayList<Viewable> 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 = "<table style=\"border: 0\">" + "<tr><th style=\"text-align: left; vertical-align: top;\">Subject:</th><td>(No subject)</td></tr>" + "</table>" + "<pre class=\"k9mail\">text body of first message<br /></pre>" + "<p style=\"margin-top: 2.5em; margin-bottom: 1em; border-bottom: 1px solid #000\"></p>" + "<table style=\"border: 0\">" + "<tr><th style=\"text-align: left; vertical-align: top;\">Subject:</th><td>subject of second message</td></tr>" + "</table>" + "<pre class=\"k9mail\">text part of second message<br /></pre>";
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));
}
use of com.fsck.k9.mail.internet.Viewable.Alternative in project k-9 by k9mail.
the class TextPartFinderTest method findFirstTextPart_withMultipartAlternativeNotContainingTextPart.
@Test
public void findFirstTextPart_withMultipartAlternativeNotContainingTextPart() throws Exception {
Part part = createMultipart("multipart/alternative", createPart("image/gif"), createPart("application/pdf"));
Part result = textPartFinder.findFirstTextPart(part);
assertNull(result);
}
use of com.fsck.k9.mail.internet.Viewable.Alternative in project k-9 by k9mail.
the class TextPartFinderTest method findFirstTextPart_withMultipartMixedContainingMultipartAlternativeWithTextPlainPartLast.
@Test
public void findFirstTextPart_withMultipartMixedContainingMultipartAlternativeWithTextPlainPartLast() throws Exception {
BodyPart expected = createTextPart("text/plain");
Part part = createMultipart("multipart/mixed", createMultipart("multipart/alternative", createTextPart("text/html"), expected));
Part result = textPartFinder.findFirstTextPart(part);
assertEquals(expected, result);
}
use of com.fsck.k9.mail.internet.Viewable.Alternative in project k-9 by k9mail.
the class TextPartFinderTest method findFirstTextPart_withMultipartAlternativeContainingOnlyTextHtmlPart.
@Test
public void findFirstTextPart_withMultipartAlternativeContainingOnlyTextHtmlPart() throws Exception {
BodyPart expected = createTextPart("text/html");
Part part = createMultipart("multipart/alternative", createPart("image/gif"), expected, createTextPart("text/html"));
Part result = textPartFinder.findFirstTextPart(part);
assertEquals(expected, result);
}
Aggregations