Merge pull request #5650 from k9mail/show_gitlab_usernames
Show name part of certain addresses even if they contain an @ symbol
This commit is contained in:
commit
0c413e34a7
2 changed files with 18 additions and 1 deletions
|
@ -1,6 +1,8 @@
|
|||
package com.fsck.k9.helper;
|
||||
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
|
@ -27,6 +29,7 @@ public class MessageHelper {
|
|||
* @see #toFriendly(Address[], com.fsck.k9.helper.Contacts)
|
||||
*/
|
||||
private static final int TOO_MANY_ADDRESSES = 50;
|
||||
private static final Pattern SPOOF_ADDRESS_PATTERN = Pattern.compile("[^(]@");
|
||||
|
||||
private static MessageHelper sInstance;
|
||||
|
||||
|
@ -143,6 +146,6 @@ public class MessageHelper {
|
|||
}
|
||||
|
||||
private static boolean isSpoofAddress(String displayName) {
|
||||
return displayName.contains("@");
|
||||
return displayName.contains("@") && SPOOF_ADDRESS_PATTERN.matcher(displayName).find();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,6 +94,20 @@ public class MessageHelperTest extends RobolectricTest {
|
|||
assertEquals("test@testor.com", friendly.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toFriendly_atPrecededByOpeningParenthesisShouldNotTriggerSpoofPrevention() {
|
||||
Address address = new Address("gitlab@gitlab.example", "username (@username)");
|
||||
CharSequence friendly = MessageHelper.toFriendly(address, contacts);
|
||||
assertEquals("username (@username)", friendly.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toFriendly_nameStartingWithAtShouldNotTriggerSpoofPrevention() {
|
||||
Address address = new Address("address@domain.example", "@username");
|
||||
CharSequence friendly = MessageHelper.toFriendly(address, contacts);
|
||||
assertEquals("@username", friendly.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toFriendly_spoofPreventionDoesntOverrideContact() {
|
||||
Address address = new Address("test@testor.com", "Tim Testor");
|
||||
|
|
Loading…
Reference in a new issue