1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-08-13 17:03:48 -04:00

Respect "Show contact names" option when determining sender for

notification.

Fixes #4765.
This commit is contained in:
Danny Baumann 2013-01-02 16:13:27 +01:00
parent c0e0ac9d34
commit be68a6cbe6

View File

@ -48,6 +48,7 @@ import com.fsck.k9.Preferences;
import com.fsck.k9.R; import com.fsck.k9.R;
import com.fsck.k9.activity.FolderList; import com.fsck.k9.activity.FolderList;
import com.fsck.k9.activity.MessageList; import com.fsck.k9.activity.MessageList;
import com.fsck.k9.helper.Contacts;
import com.fsck.k9.helper.HtmlConverter; import com.fsck.k9.helper.HtmlConverter;
import com.fsck.k9.helper.power.TracingPowerManager; import com.fsck.k9.helper.power.TracingPowerManager;
import com.fsck.k9.helper.power.TracingPowerManager.TracingWakeLock; import com.fsck.k9.helper.power.TracingPowerManager.TracingWakeLock;
@ -4419,25 +4420,24 @@ public class MessagingController implements Runnable {
private CharSequence getMessageSender(Context context, Account account, Message message) { private CharSequence getMessageSender(Context context, Account account, Message message) {
try { try {
String from = null;
boolean isSelf = false; boolean isSelf = false;
final Contacts contacts = K9.showContactName() ? Contacts.getInstance(context) : null;
final Address[] fromAddrs = message.getFrom();
if (message.getFrom() != null) { if (fromAddrs != null) {
Address[] fromAddrs = message.getFrom();
if (fromAddrs.length > 0) {
from = fromAddrs[0].toFriendly().toString();
}
isSelf = account.isAnIdentity(fromAddrs); isSelf = account.isAnIdentity(fromAddrs);
if (!isSelf && fromAddrs.length > 0) {
return fromAddrs[0].toFriendly(contacts).toString();
}
} }
if (from != null && !isSelf) { if (isSelf) {
return from;
} else if (isSelf) {
// show To: if the message was sent from me // show To: if the message was sent from me
Address[] rcpts = message.getRecipients(Message.RecipientType.TO); Address[] rcpts = message.getRecipients(Message.RecipientType.TO);
String to = rcpts.length > 0 ? rcpts[0].toFriendly().toString() : null;
if (to != null) { if (rcpts != null && rcpts.length > 0) {
return context.getString(R.string.message_to_fmt, to); return context.getString(R.string.message_to_fmt,
rcpts[0].toFriendly(contacts).toString());
} }
return context.getString(R.string.general_no_sender); return context.getString(R.string.general_no_sender);