Search in sources :

Example 61 with Address

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);
}
Also used : Address(com.fsck.k9.mail.Address) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Date(java.util.Date) TextBody(com.fsck.k9.mail.internet.TextBody) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) MimeMultipart(com.fsck.k9.mail.internet.MimeMultipart) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part) Viewable(com.fsck.k9.mail.internet.Viewable) ViewableExtractedText(com.fsck.k9.mailstore.MessageViewInfoExtractor.ViewableExtractedText) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) K9RobolectricTest(com.fsck.k9.K9RobolectricTest) Test(org.junit.Test)

Example 62 with Address

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;
}
Also used : Address(com.fsck.k9.mail.Address) Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull)

Example 63 with Address

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);
}
Also used : Address(com.fsck.k9.mail.Address) ReplyToAddresses(com.fsck.k9.helper.ReplyToParser.ReplyToAddresses) RobolectricTest(com.fsck.k9.RobolectricTest) Test(org.junit.Test)

Example 64 with Address

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);
}
Also used : ReplyToAddresses(com.fsck.k9.helper.ReplyToParser.ReplyToAddresses) RobolectricTest(com.fsck.k9.RobolectricTest) Test(org.junit.Test)

Example 65 with Address

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());
}
Also used : Address(com.fsck.k9.mail.Address) RobolectricTest(com.fsck.k9.RobolectricTest) Test(org.junit.Test)

Aggregations

Address (com.fsck.k9.mail.Address)72 Test (org.junit.Test)40 Uri (android.net.Uri)13 RobolectricTest (com.fsck.k9.RobolectricTest)12 Message (com.fsck.k9.mail.Message)10 Date (java.util.Date)8 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)7 ArrayList (java.util.ArrayList)7 MessagingException (com.fsck.k9.mail.MessagingException)6 Contacts (com.fsck.k9.helper.Contacts)5 Recipient (com.fsck.k9.view.RecipientSelectView.Recipient)5 AddressStyle (com.zegoggles.smssync.preferences.AddressStyle)5 IOException (java.io.IOException)5 Intent (android.content.Intent)4 Cursor (android.database.Cursor)4 MatrixCursor (android.database.MatrixCursor)4 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)4 CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)4 TextBody (com.fsck.k9.mail.internet.TextBody)4 SpannableString (android.text.SpannableString)3