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();
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations