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:
cketti 2021-09-09 12:47:00 +02:00 committed by GitHub
commit 0c413e34a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View file

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

View file

@ -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");