use of com.fsck.k9.mail.internet.MimeMultipart in project k-9 by k9mail.
the class MessageViewInfoExtractorTest method testMultipartPlainTextMessage.
@Test
public void testMultipartPlainTextMessage() throws MessagingException {
String bodyText1 = "text body 1";
String bodyText2 = "text body 2";
// Create text/plain bodies
TextBody body1 = new TextBody(bodyText1);
TextBody body2 = new TextBody(bodyText2);
// Create multipart/mixed part
MimeMultipart multipart = MimeMultipart.newInstance();
MimeBodyPart bodyPart1 = new MimeBodyPart(body1, "text/plain");
MimeBodyPart bodyPart2 = new MimeBodyPart(body2, "text/plain");
multipart.addBodyPart(bodyPart1);
multipart.addBodyPart(bodyPart2);
// Create message
MimeMessage message = new MimeMessage();
MimeMessageHelper.setBody(message, multipart);
// Extract text
List<Part> outputNonViewableParts = new ArrayList<>();
ArrayList<Viewable> outputViewableParts = new ArrayList<>();
MessageExtractor.findViewablesAndAttachments(message, outputViewableParts, outputNonViewableParts);
ViewableExtractedText container = messageViewInfoExtractor.extractTextFromViewables(outputViewableParts);
String expectedText = bodyText1 + "\r\n\r\n" + "------------------------------------------------------------------------\r\n\r\n" + bodyText2;
String expectedHtml = "<pre class=\"k9mail\">" + bodyText1 + "</pre>" + "<p style=\"margin-top: 2.5em; margin-bottom: 1em; " + "border-bottom: 1px solid #000\"></p>" + "<pre class=\"k9mail\">" + bodyText2 + "</pre>";
assertEquals(expectedText, container.text);
assertEquals(expectedHtml, getHtmlBodyText(container.html));
}
use of com.fsck.k9.mail.internet.MimeMultipart in project k-9 by k9mail.
the class MessageViewInfoExtractorTest method testTextPlusRfc822Message.
@Test
public void testTextPlusRfc822Message() throws MessagingException {
Locale.setDefault(Locale.US);
TimeZone.setDefault(TimeZone.getTimeZone("GMT+01:00"));
String innerBodyText = "Hey there. I'm inside a message/rfc822 (inline) attachment.";
// Create text/plain body
TextBody textBody = new TextBody(BODY_TEXT);
// Create inner text/plain body
TextBody innerBody = new TextBody(innerBodyText);
// Create message/rfc822 body
MimeMessage innerMessage = new MimeMessage();
innerMessage.addSentDate(new Date(112, 02, 17), false);
innerMessage.setRecipients(RecipientType.TO, new Address[] { new Address("to@example.com") });
innerMessage.setSubject("Subject");
innerMessage.setFrom(new Address("from@example.com"));
MimeMessageHelper.setBody(innerMessage, innerBody);
// Create multipart/mixed part
MimeMultipart multipart = MimeMultipart.newInstance();
MimeBodyPart bodyPart1 = new MimeBodyPart(textBody, "text/plain");
MimeBodyPart bodyPart2 = new MimeBodyPart(innerMessage, "message/rfc822");
bodyPart2.setHeader("Content-Disposition", "inline; filename=\"message.eml\"");
multipart.addBodyPart(bodyPart1);
multipart.addBodyPart(bodyPart2);
// Create message
MimeMessage message = new MimeMessage();
MimeMessageHelper.setBody(message, multipart);
// Extract text
List<Part> outputNonViewableParts = new ArrayList<Part>();
ArrayList<Viewable> outputViewableParts = new ArrayList<>();
MessageExtractor.findViewablesAndAttachments(message, outputViewableParts, outputNonViewableParts);
ViewableExtractedText container = messageViewInfoExtractor.extractTextFromViewables(outputViewableParts);
String expectedText = BODY_TEXT + "\r\n\r\n" + "----- message.eml ------------------------------------------------------" + "\r\n\r\n" + "From: from@example.com" + "\r\n" + "To: to@example.com" + "\r\n" + "Sent: Sat Mar 17 00:00:00 GMT+01:00 2012" + "\r\n" + "Subject: Subject" + "\r\n" + "\r\n" + innerBodyText;
String expectedHtml = "<pre class=\"k9mail\">" + BODY_TEXT_HTML + "</pre>" + "<p style=\"margin-top: 2.5em; margin-bottom: 1em; border-bottom: " + "1px solid #000\">message.eml</p>" + "<table style=\"border: 0\">" + "<tr>" + "<th style=\"text-align: left; vertical-align: top;\">From:</th>" + "<td>from@example.com</td>" + "</tr><tr>" + "<th style=\"text-align: left; vertical-align: top;\">To:</th>" + "<td>to@example.com</td>" + "</tr><tr>" + "<th style=\"text-align: left; vertical-align: top;\">Sent:</th>" + "<td>Sat Mar 17 00:00:00 GMT+01:00 2012</td>" + "</tr><tr>" + "<th style=\"text-align: left; vertical-align: top;\">Subject:</th>" + "<td>Subject</td>" + "</tr>" + "</table>" + "<pre class=\"k9mail\">" + innerBodyText + "</pre>";
assertEquals(expectedText, container.text);
assertEquals(expectedHtml, getHtmlBodyText(container.html));
}
use of com.fsck.k9.mail.internet.MimeMultipart in project k-9 by k9mail.
the class MessageDecryptVerifierTest method findEncryptedPartsShouldReturnEmptyEncryptedPart.
@Test
public void findEncryptedPartsShouldReturnEmptyEncryptedPart() throws Exception {
MimeMessage message = new MimeMessage();
MimeMultipart multipartEncrypted = MimeMultipart.newInstance();
multipartEncrypted.setSubType("encrypted");
MimeMessageHelper.setBody(message, multipartEncrypted);
setContentTypeWithProtocol(message, MIME_TYPE_MULTIPART_ENCRYPTED, PROTCOL_PGP_ENCRYPTED);
List<Part> encryptedParts = MessageDecryptVerifier.findEncryptedParts(message);
assertEquals(1, encryptedParts.size());
assertSame(message, encryptedParts.get(0));
}
use of com.fsck.k9.mail.internet.MimeMultipart in project k-9 by k9mail.
the class MessageTest method sampleMessage.
private MimeMessage sampleMessage() throws MessagingException, IOException {
MimeMessage message = new MimeMessage();
message.setFrom(new Address("from@example.com"));
message.setRecipient(RecipientType.TO, new Address("to@example.com"));
message.setSubject("Test Message");
message.setHeader("Date", "Wed, 28 Aug 2013 08:51:09 -0400");
message.setEncoding(MimeUtil.ENC_7BIT);
MimeMultipart multipartBody = new MimeMultipart("multipart/mixed", generateBoundary());
multipartBody.addBodyPart(textBodyPart());
multipartBody.addBodyPart(binaryBodyPart());
MimeMessageHelper.setBody(message, multipartBody);
return message;
}
Aggregations