Search in sources :

Example 21 with Address

use of com.fsck.k9.mail.Address in project k-9 by k9mail.

the class MessageInfoHolder method create.

public static MessageInfoHolder create(Context context, LocalMessage message, Account account) {
    Contacts contactHelper = K9.isShowContactName() ? Contacts.getInstance(context) : null;
    MessageInfoHolder target = new MessageInfoHolder();
    target.message = message;
    target.compareDate = message.getSentDate();
    if (target.compareDate == null) {
        target.compareDate = message.getInternalDate();
    }
    target.read = message.isSet(Flag.SEEN);
    Address[] addrs = message.getFrom();
    String counterParty;
    if (addrs.length > 0 && account.isAnIdentity(addrs[0])) {
        CharSequence to = MessageHelper.toFriendly(message.getRecipients(RecipientType.TO), contactHelper);
        counterParty = to.toString();
        target.sender = new SpannableStringBuilder(context.getString(R.string.message_to_label)).append(to);
    } else {
        target.sender = MessageHelper.toFriendly(addrs, contactHelper);
        counterParty = target.sender.toString();
    }
    if (addrs.length > 0) {
        target.senderAddress = addrs[0].getAddress();
    } else {
        // a reasonable fallback "whomever we were corresponding with
        target.senderAddress = counterParty;
    }
    target.uid = message.getUid();
    target.uri = message.getUri();
    return target;
}
Also used : Contacts(com.fsck.k9.helper.Contacts) Address(com.fsck.k9.mail.Address) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 22 with Address

use of com.fsck.k9.mail.Address in project k-9 by k9mail.

the class MessageCompose method processMessageToReplyTo.

private void processMessageToReplyTo(MessageViewInfo messageViewInfo) throws MessagingException {
    Message message = messageViewInfo.message;
    if (messageViewInfo.subject != null) {
        final String subject = PREFIX.matcher(messageViewInfo.subject).replaceFirst("");
        if (!subject.toLowerCase(Locale.US).startsWith("re:")) {
            subjectView.setText("Re: " + subject);
        } else {
            subjectView.setText(subject);
        }
    } else {
        subjectView.setText("");
    }
    /*
         * If a reply-to was included with the message use that, otherwise use the from
         * or sender address.
         */
    boolean isReplyAll = action == Action.REPLY_ALL;
    recipientPresenter.initFromReplyToMessage(message, isReplyAll);
    if (message.getMessageId() != null && message.getMessageId().length() > 0) {
        repliedToMessageId = message.getMessageId();
        String[] refs = message.getReferences();
        if (refs != null && refs.length > 0) {
            referencedMessageIds = TextUtils.join("", refs) + " " + repliedToMessageId;
        } else {
            referencedMessageIds = repliedToMessageId;
        }
    } else {
        Timber.d("could not get Message-ID.");
    }
    // Quote the message and setup the UI.
    quotedMessagePresenter.initFromReplyToMessage(messageViewInfo, action);
    if (action == Action.REPLY || action == Action.REPLY_ALL) {
        setIdentityFromMessage(message);
    }
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message)

Example 23 with Address

use of com.fsck.k9.mail.Address in project k-9 by k9mail.

the class MailToTest method testGetCc_singleEmailAddress.

@Test
public void testGetCc_singleEmailAddress() {
    Uri uri = Uri.parse("mailto:test1@abc.com?cc=test3@abc.com");
    MailTo mailToHelper = MailTo.parse(uri);
    Address[] emailAddressList = mailToHelper.getCc();
    assertEquals(emailAddressList[0].getAddress(), "test3@abc.com");
}
Also used : Address(com.fsck.k9.mail.Address) Uri(android.net.Uri) Test(org.junit.Test)

Example 24 with Address

use of com.fsck.k9.mail.Address in project k-9 by k9mail.

the class ListHeadersTest method getListPostAddresses_withMailTo_shouldReturnCorrectAddress.

@Test
public void getListPostAddresses_withMailTo_shouldReturnCorrectAddress() throws Exception {
    for (String emailAddress : TEST_EMAIL_ADDRESSES) {
        String headerValue = "<mailto:" + emailAddress + ">";
        Message message = buildMimeMessageWithListPostValue(headerValue);
        Address[] result = ListHeaders.getListPostAddresses(message);
        assertExtractedAddressMatchesEmail(emailAddress, result);
    }
}
Also used : Message(com.fsck.k9.mail.Message) Address(com.fsck.k9.mail.Address) Test(org.junit.Test)

Example 25 with Address

use of com.fsck.k9.mail.Address in project k-9 by k9mail.

the class ListHeadersTest method getListPostAddresses_withMailtoWithNote_shouldReturnCorrectAddress.

@Test
public void getListPostAddresses_withMailtoWithNote_shouldReturnCorrectAddress() throws Exception {
    for (String emailAddress : TEST_EMAIL_ADDRESSES) {
        String headerValue = "<mailto:" + emailAddress + "> (Postings are Moderated)";
        Message message = buildMimeMessageWithListPostValue(headerValue);
        Address[] result = ListHeaders.getListPostAddresses(message);
        assertExtractedAddressMatchesEmail(emailAddress, result);
    }
}
Also used : Message(com.fsck.k9.mail.Message) Address(com.fsck.k9.mail.Address) 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