Search in sources :

Example 31 with Address

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

the class MessageHeader method populate.

public void populate(final Message message, final Account account, boolean showStar) {
    Address fromAddress = null;
    Address[] fromAddresses = message.getFrom();
    if (fromAddresses.length > 0) {
        fromAddress = fromAddresses[0];
    }
    final Contacts contacts = K9.isShowContactName() ? mContacts : null;
    final CharSequence from = mMessageHelper.getSenderDisplayName(fromAddress);
    final CharSequence to = MessageHelper.toFriendly(message.getRecipients(Message.RecipientType.TO), contacts);
    final CharSequence cc = MessageHelper.toFriendly(message.getRecipients(Message.RecipientType.CC), contacts);
    final CharSequence bcc = MessageHelper.toFriendly(message.getRecipients(Message.RecipientType.BCC), contacts);
    mMessage = message;
    mAccount = account;
    if (K9.isShowContactPicture()) {
        mContactBadge.setVisibility(View.VISIBLE);
        mContactsPictureLoader = ContactPicture.getContactPictureLoader();
    } else {
        mContactBadge.setVisibility(View.GONE);
    }
    if (shouldShowSender(message)) {
        mSenderView.setVisibility(VISIBLE);
        String sender = getResources().getString(R.string.message_view_sender_label, MessageHelper.toFriendly(message.getSender(), contacts));
        mSenderView.setText(sender);
    } else {
        mSenderView.setVisibility(View.GONE);
    }
    String dateTime = DateUtils.formatDateTime(mContext, message.getSentDate().getTime(), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_YEAR);
    mDateView.setText(dateTime);
    if (K9.isShowContactPicture()) {
        if (fromAddress != null) {
            mContactBadge.setContact(fromAddress);
            mContactsPictureLoader.setContactPicture(mContactBadge, fromAddress);
        } else {
            mContactBadge.setImageResource(R.drawable.ic_contact_picture);
        }
    }
    mFromView.setText(from);
    updateAddressField(mToView, to, mToLabel);
    updateAddressField(mCcView, cc, mCcLabel);
    updateAddressField(mBccView, bcc, mBccLabel);
    mAnsweredIcon.setVisibility(message.isSet(Flag.ANSWERED) ? View.VISIBLE : View.GONE);
    mForwardedIcon.setVisibility(message.isSet(Flag.FORWARDED) ? View.VISIBLE : View.GONE);
    if (showStar) {
        mFlagged.setVisibility(View.VISIBLE);
        mFlagged.setChecked(message.isSet(Flag.FLAGGED));
    } else {
        mFlagged.setVisibility(View.GONE);
    }
    mChip.setBackgroundColor(mAccount.getChipColor());
    setVisibility(View.VISIBLE);
}
Also used : Address(com.fsck.k9.mail.Address) Contacts(com.fsck.k9.helper.Contacts)

Example 32 with Address

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

the class ReplyToParser method getRecipientsToReplyAllTo.

public ReplyToAddresses getRecipientsToReplyAllTo(Message message, Account account) {
    List<Address> replyToAddresses = Arrays.asList(getRecipientsToReplyTo(message, account).to);
    HashSet<Address> alreadyAddedAddresses = new HashSet<>(replyToAddresses);
    ArrayList<Address> toAddresses = new ArrayList<>(replyToAddresses);
    ArrayList<Address> ccAddresses = new ArrayList<>();
    for (Address address : message.getFrom()) {
        if (!alreadyAddedAddresses.contains(address) && !account.isAnIdentity(address)) {
            toAddresses.add(address);
            alreadyAddedAddresses.add(address);
        }
    }
    for (Address address : message.getRecipients(RecipientType.TO)) {
        if (!alreadyAddedAddresses.contains(address) && !account.isAnIdentity(address)) {
            toAddresses.add(address);
            alreadyAddedAddresses.add(address);
        }
    }
    for (Address address : message.getRecipients(RecipientType.CC)) {
        if (!alreadyAddedAddresses.contains(address) && !account.isAnIdentity(address)) {
            ccAddresses.add(address);
            alreadyAddedAddresses.add(address);
        }
    }
    return new ReplyToAddresses(toAddresses, ccAddresses);
}
Also used : Address(com.fsck.k9.mail.Address) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 33 with Address

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

the class ListHeaders method extractAddress.

private static Address extractAddress(String headerValue) {
    if (headerValue == null || headerValue.isEmpty()) {
        return null;
    }
    Matcher matcher = MAILTO_CONTAINER_PATTERN.matcher(headerValue);
    if (!matcher.find()) {
        return null;
    }
    Uri mailToUri = Uri.parse(matcher.group(1));
    Address[] emailAddress = MailTo.parse(mailToUri).getTo();
    return emailAddress.length >= 1 ? emailAddress[0] : null;
}
Also used : Address(com.fsck.k9.mail.Address) Matcher(java.util.regex.Matcher) Uri(android.net.Uri)

Example 34 with Address

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

the class MailToTest method testGetTo_multipleEmailAddress.

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

Example 35 with Address

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

the class MailToTest method testGetBcc_multipleEmailAddress.

@Test
public void testGetBcc_multipleEmailAddress() {
    Uri uri = Uri.parse("mailto:?bcc=test3@abc.com&bcc=test4@abc.com");
    MailTo mailToHelper = MailTo.parse(uri);
    Address[] emailAddressList = mailToHelper.getBcc();
    assertEquals(emailAddressList[0].getAddress(), "test3@abc.com");
    assertEquals(emailAddressList[1].getAddress(), "test4@abc.com");
}
Also used : Address(com.fsck.k9.mail.Address) Uri(android.net.Uri) 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