Merge pull request #3120 from philipwhiuk/mailsploitFix
Show address if personal component is email address
This commit is contained in:
commit
a36254dbc0
2 changed files with 41 additions and 6 deletions
|
@ -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("@");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
|
@ -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
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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…
Reference in a new issue