Search in sources :

Example 41 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) {
    final Contacts contacts = K9.showContactName() ? mContacts : null;
    final CharSequence from = MessageHelper.toFriendly(message.getFrom(), contacts);
    final CharSequence to = MessageHelper.toFriendly(message.getRecipients(Message.RecipientType.TO), contacts);
    final CharSequence cc = MessageHelper.toFriendly(message.getRecipients(Message.RecipientType.CC), contacts);
    Address[] fromAddrs = message.getFrom();
    Address[] toAddrs = message.getRecipients(Message.RecipientType.TO);
    Address[] ccAddrs = message.getRecipients(Message.RecipientType.CC);
    boolean fromMe = mMessageHelper.toMe(account, fromAddrs);
    Address counterpartyAddress = null;
    if (fromMe) {
        if (toAddrs.length > 0) {
            counterpartyAddress = toAddrs[0];
        } else if (ccAddrs.length > 0) {
            counterpartyAddress = ccAddrs[0];
        }
    } else if (fromAddrs.length > 0) {
        counterpartyAddress = fromAddrs[0];
    }
    /* We hide the subject by default for each new message, and MessageTitleView might show
         * it later by calling showSubjectLine(). */
    boolean newMessageShown = mMessage == null || mMessage.getId() != message.getId();
    if (newMessageShown) {
        mSubjectView.setVisibility(GONE);
    }
    mMessage = message;
    mAccount = account;
    if (K9.showContactPicture()) {
        mContactBadge.setVisibility(View.VISIBLE);
        mContactsPictureLoader = ContactPicture.getContactPictureLoader(mContext);
    } 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);
    }
    final String subject = message.getSubject();
    if (TextUtils.isEmpty(subject)) {
        mSubjectView.setText(mContext.getText(R.string.general_no_subject));
    } else {
        mSubjectView.setText(subject);
    }
    mSubjectView.setTextColor(0xff000000 | defaultSubjectColor);
    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.showContactPicture()) {
        if (counterpartyAddress != null) {
            Utility.setContactForBadge(mContactBadge, counterpartyAddress);
            mContactsPictureLoader.loadContactPicture(counterpartyAddress, mContactBadge);
        } else {
            mContactBadge.setImageResource(R.drawable.ic_contact_picture);
        }
    }
    mFromView.setText(from);
    updateAddressField(mToView, to, mToLabel);
    updateAddressField(mCcView, cc, mCcLabel);
    mAnsweredIcon.setVisibility(message.isSet(Flag.ANSWERED) ? View.VISIBLE : View.GONE);
    mForwardedIcon.setVisibility(message.isSet(Flag.FORWARDED) ? View.VISIBLE : View.GONE);
    mFlagged.setChecked(message.isSet(Flag.FLAGGED));
    mChip.setBackgroundColor(mAccount.getChipColor());
    setVisibility(View.VISIBLE);
    if (mSavedState != null) {
        if (mSavedState.additionalHeadersVisible) {
            showAdditionalHeaders();
        }
        mSavedState = null;
    } else {
        hideAdditionalHeaders();
    }
}
Also used : Contacts(com.fsck.k9.helper.Contacts) Address(com.fsck.k9.mail.Address) SpannableString(android.text.SpannableString)

Example 42 with Address

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

the class ContactPictureLoaderTest method calcUnknownContactLetter_withNoNameUsesAddress.

@Test
public void calcUnknownContactLetter_withNoNameUsesAddress() {
    Address address = new Address("<c@d.com>");
    String result = ContactPictureLoader.calcUnknownContactLetter(address);
    assertEquals("C", result);
}
Also used : Address(com.fsck.k9.mail.Address) Test(org.junit.Test)

Example 43 with Address

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

the class ContactPictureLoaderTest method calcUnknownContactLetter_ignoresUsePunctuation.

@Test
public void calcUnknownContactLetter_ignoresUsePunctuation() {
    Address address = new Address("-a <a@b.com>");
    String result = ContactPictureLoader.calcUnknownContactLetter(address);
    assertEquals("A", result);
}
Also used : Address(com.fsck.k9.mail.Address) Test(org.junit.Test)

Example 44 with Address

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

the class ContactPictureLoaderTest method calcUnknownContactLetter_withChinese.

@Test
public void calcUnknownContactLetter_withChinese() {
    Address address = new Address("千里之行﹐始于足下 <a@b.com>");
    String result = ContactPictureLoader.calcUnknownContactLetter(address);
    assertEquals("千", result);
}
Also used : Address(com.fsck.k9.mail.Address) Test(org.junit.Test)

Example 45 with Address

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

the class ContactPictureLoaderTest method calcUnknownContactLetter_withCombinedGlyphs.

@Test
public void calcUnknownContactLetter_withCombinedGlyphs() {
    Address address = new Address("à <a@b.com>");
    String result = ContactPictureLoader.calcUnknownContactLetter(address);
    assertEquals("À", result);
}
Also used : 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