From 9156e8f699f6ab8c47bd23fffc989f53068521e0 Mon Sep 17 00:00:00 2001 From: cketti Date: Mon, 6 Sep 2021 07:58:05 +0200 Subject: [PATCH] Show name part of certain addresses even if they contain an @ symbol --- .../java/com/fsck/k9/helper/MessageHelper.java | 5 ++++- .../java/com/fsck/k9/helper/MessageHelperTest.java | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/core/src/main/java/com/fsck/k9/helper/MessageHelper.java b/app/core/src/main/java/com/fsck/k9/helper/MessageHelper.java index 5595d47f8..cb9e865da 100644 --- a/app/core/src/main/java/com/fsck/k9/helper/MessageHelper.java +++ b/app/core/src/main/java/com/fsck/k9/helper/MessageHelper.java @@ -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(); } } diff --git a/app/core/src/test/java/com/fsck/k9/helper/MessageHelperTest.java b/app/core/src/test/java/com/fsck/k9/helper/MessageHelperTest.java index f5b7cc0eb..85347a322 100644 --- a/app/core/src/test/java/com/fsck/k9/helper/MessageHelperTest.java +++ b/app/core/src/test/java/com/fsck/k9/helper/MessageHelperTest.java @@ -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");