Loading k9mail/src/main/java/com/fsck/k9/helper/MessageHelper.java +9 −1 Original line number Diff line number Diff line Loading @@ -176,6 +176,14 @@ public class MessageHelper { } } return (!TextUtils.isEmpty(address.getPersonal())) ? address.getPersonal() : address.getAddress(); if (!TextUtils.isEmpty(address.getPersonal()) && !isSpoofAddress(address.getPersonal())) { return address.getPersonal(); } else { return address.getAddress(); } } private static boolean isSpoofAddress(String displayName) { return displayName.contains("@"); } } k9mail/src/test/java/com/fsck/k9/helper/MessageHelperTest.java +32 −5 Original line number Diff line number Diff line Loading @@ -21,13 +21,14 @@ import static junit.framework.Assert.assertTrue; @Config(manifest = Config.NONE) public class MessageHelperTest { private Contacts contacts; private Contacts mockContacts; private Contacts contactsWithFakeContact; private Contacts contactsWithFakeSpoofContact; @Before public void setUp() throws Exception { Context context = RuntimeEnvironment.application; contacts = new Contacts(context); mockContacts = new Contacts(context) { contactsWithFakeContact = new Contacts(context) { @Override public String getNameForAddress(String address) { if ("test@testor.com".equals(address)) { return "Tim Testor"; Loading @@ -36,6 +37,15 @@ public class MessageHelperTest { } } }; contactsWithFakeSpoofContact = new Contacts(context) { @Override public String getNameForAddress(String address) { if ("test@testor.com".equals(address)) { return "Tim@Testor"; } else { return null; } } }; } @Test Loading @@ -61,13 +71,14 @@ public class MessageHelperTest { @Test public void testToFriendlyWithContactLookup() throws Exception { Address address = new Address("test@testor.com"); assertEquals("Tim Testor", MessageHelper.toFriendly(address, mockContacts).toString()); assertEquals("Tim Testor", MessageHelper.toFriendly(address, contactsWithFakeContact).toString()); } @Test public void testToFriendlyWithChangeContactColor() throws Exception { Address address = new Address("test@testor.com"); CharSequence friendly = MessageHelper.toFriendly(address, mockContacts, true, true, Color.RED); CharSequence friendly = MessageHelper.toFriendly(address, contactsWithFakeContact, true, true, Color.RED); assertTrue(friendly instanceof SpannableString); assertEquals("Tim Testor", friendly.toString()); } Loading @@ -75,7 +86,23 @@ public class MessageHelperTest { @Test public void testToFriendlyWithoutCorrespondentNames() throws Exception { Address address = new Address("test@testor.com", "Tim Testor"); CharSequence friendly = MessageHelper.toFriendly(address, mockContacts, false, false, 0); CharSequence friendly = MessageHelper.toFriendly(address, contactsWithFakeContact, false, false, 0); assertEquals("test@testor.com", friendly.toString()); } @Test public void toFriendly_spoofPreventionOverridesPersonal() { Address address = new Address("test@testor.com", "potus@whitehouse.gov"); CharSequence friendly = MessageHelper.toFriendly(address, contacts); assertEquals("test@testor.com", friendly.toString()); } @Test public void toFriendly_spoofPreventionDoesntOverrideContact() { Address address = new Address("test@testor.com", "Tim Testor"); CharSequence friendly = MessageHelper.toFriendly(address, contactsWithFakeSpoofContact, true, false, 0); assertEquals("Tim@Testor", friendly.toString()); } } Loading
k9mail/src/main/java/com/fsck/k9/helper/MessageHelper.java +9 −1 Original line number Diff line number Diff line Loading @@ -176,6 +176,14 @@ public class MessageHelper { } } return (!TextUtils.isEmpty(address.getPersonal())) ? address.getPersonal() : address.getAddress(); if (!TextUtils.isEmpty(address.getPersonal()) && !isSpoofAddress(address.getPersonal())) { return address.getPersonal(); } else { return address.getAddress(); } } private static boolean isSpoofAddress(String displayName) { return displayName.contains("@"); } }
k9mail/src/test/java/com/fsck/k9/helper/MessageHelperTest.java +32 −5 Original line number Diff line number Diff line Loading @@ -21,13 +21,14 @@ import static junit.framework.Assert.assertTrue; @Config(manifest = Config.NONE) public class MessageHelperTest { private Contacts contacts; private Contacts mockContacts; private Contacts contactsWithFakeContact; private Contacts contactsWithFakeSpoofContact; @Before public void setUp() throws Exception { Context context = RuntimeEnvironment.application; contacts = new Contacts(context); mockContacts = new Contacts(context) { contactsWithFakeContact = new Contacts(context) { @Override public String getNameForAddress(String address) { if ("test@testor.com".equals(address)) { return "Tim Testor"; Loading @@ -36,6 +37,15 @@ public class MessageHelperTest { } } }; contactsWithFakeSpoofContact = new Contacts(context) { @Override public String getNameForAddress(String address) { if ("test@testor.com".equals(address)) { return "Tim@Testor"; } else { return null; } } }; } @Test Loading @@ -61,13 +71,14 @@ public class MessageHelperTest { @Test public void testToFriendlyWithContactLookup() throws Exception { Address address = new Address("test@testor.com"); assertEquals("Tim Testor", MessageHelper.toFriendly(address, mockContacts).toString()); assertEquals("Tim Testor", MessageHelper.toFriendly(address, contactsWithFakeContact).toString()); } @Test public void testToFriendlyWithChangeContactColor() throws Exception { Address address = new Address("test@testor.com"); CharSequence friendly = MessageHelper.toFriendly(address, mockContacts, true, true, Color.RED); CharSequence friendly = MessageHelper.toFriendly(address, contactsWithFakeContact, true, true, Color.RED); assertTrue(friendly instanceof SpannableString); assertEquals("Tim Testor", friendly.toString()); } Loading @@ -75,7 +86,23 @@ public class MessageHelperTest { @Test public void testToFriendlyWithoutCorrespondentNames() throws Exception { Address address = new Address("test@testor.com", "Tim Testor"); CharSequence friendly = MessageHelper.toFriendly(address, mockContacts, false, false, 0); CharSequence friendly = MessageHelper.toFriendly(address, contactsWithFakeContact, false, false, 0); assertEquals("test@testor.com", friendly.toString()); } @Test public void toFriendly_spoofPreventionOverridesPersonal() { Address address = new Address("test@testor.com", "potus@whitehouse.gov"); CharSequence friendly = MessageHelper.toFriendly(address, contacts); assertEquals("test@testor.com", friendly.toString()); } @Test public void toFriendly_spoofPreventionDoesntOverrideContact() { Address address = new Address("test@testor.com", "Tim Testor"); CharSequence friendly = MessageHelper.toFriendly(address, contactsWithFakeSpoofContact, true, false, 0); assertEquals("Tim@Testor", friendly.toString()); } }