use of com.fsck.k9.mail.Address in project k-9 by k9mail.
the class MessageViewInfoExtractorTest method testTextPlusRfc822Message.
@Test
public void testTextPlusRfc822Message() throws MessagingException {
setLanguage("en");
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, 2, 17), false);
innerMessage.setHeader("To", "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<>();
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 dir=\"auto\" 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 dir=\"auto\" class=\"k9mail\">" + innerBodyText + "</pre>";
assertEquals(expectedText, container.text);
assertEquals(expectedHtml, container.html);
}
use of com.fsck.k9.mail.Address in project k-9 by k9mail.
the class K9ChooserTargetService method prepareIntentExtras.
@NonNull
private Bundle prepareIntentExtras(Recipient recipient) {
Address address = recipient.address;
Bundle extras = new Bundle();
extras.putStringArray(Intent.EXTRA_EMAIL, new String[] { address.toString() });
extras.putStringArray(Intent.EXTRA_CC, new String[0]);
extras.putStringArray(Intent.EXTRA_BCC, new String[0]);
return extras;
}
use of com.fsck.k9.mail.Address in project k-9 by k9mail.
the class ReplyToParserTest method getRecipientsToReplyAllTo_should_excludeIdentityAddresses.
@Test
public void getRecipientsToReplyAllTo_should_excludeIdentityAddresses() throws Exception {
when(message.getReplyTo()).thenReturn(EMPTY_ADDRESSES);
when(message.getHeader(ListHeaders.LIST_POST_HEADER)).thenReturn(new String[0]);
when(message.getFrom()).thenReturn(EMPTY_ADDRESSES);
when(message.getRecipients(RecipientType.TO)).thenReturn(TO_ADDRESSES);
when(message.getRecipients(RecipientType.CC)).thenReturn(CC_ADDRESSES);
Address excludedCcAddress = CC_ADDRESSES[1];
Address excludedToAddress = TO_ADDRESSES[0];
when(account.isAnIdentity(eq(excludedToAddress))).thenReturn(true);
when(account.isAnIdentity(eq(excludedCcAddress))).thenReturn(true);
ReplyToAddresses recipientsToReplyAllTo = replyToParser.getRecipientsToReplyAllTo(message, account);
assertArrayEquals(arrayExcept(TO_ADDRESSES, excludedToAddress), recipientsToReplyAllTo.to);
assertArrayEquals(arrayExcept(CC_ADDRESSES, excludedCcAddress), recipientsToReplyAllTo.cc);
}
use of com.fsck.k9.mail.Address in project k-9 by k9mail.
the class ReplyToParserTest method getRecipientsToReplyTo_should_prefer_from_ifOtherIsIdentity.
@Test
public void getRecipientsToReplyTo_should_prefer_from_ifOtherIsIdentity() throws Exception {
when(message.getReplyTo()).thenReturn(REPLY_TO_ADDRESSES);
when(message.getHeader(ListHeaders.LIST_POST_HEADER)).thenReturn(LIST_POST_HEADER_VALUES);
when(message.getFrom()).thenReturn(FROM_ADDRESSES);
when(message.getRecipients(RecipientType.TO)).thenReturn(TO_ADDRESSES);
when(account.isAnIdentity(any(Address[].class))).thenReturn(true);
ReplyToAddresses result = replyToParser.getRecipientsToReplyTo(message, account);
assertArrayEquals(TO_ADDRESSES, result.to);
assertArrayEquals(EMPTY_ADDRESSES, result.cc);
}
use of com.fsck.k9.mail.Address in project k-9 by k9mail.
the class MessageHelperTest method toFriendly_nameStartingWithAtShouldNotTriggerSpoofPrevention.
@Test
public void toFriendly_nameStartingWithAtShouldNotTriggerSpoofPrevention() {
Address address = new Address("address@domain.example", "@username");
CharSequence friendly = MessageHelper.toFriendly(address, contacts);
assertEquals("@username", friendly.toString());
}
Aggregations