diff --git a/legacy/core/src/main/java/com/fsck/k9/helper/MessageHelper.kt b/legacy/core/src/main/java/com/fsck/k9/helper/MessageHelper.kt index ef56c5c0df5..abadd5ea92f 100644 --- a/legacy/core/src/main/java/com/fsck/k9/helper/MessageHelper.kt +++ b/legacy/core/src/main/java/com/fsck/k9/helper/MessageHelper.kt @@ -153,10 +153,10 @@ class MessageHelper( } } val personal = address.personal - return if (!personal.isNullOrEmpty() && !isSpoofAddress(personal)) { - personal - } else { - address.address + return when { + personal.isNullOrEmpty() -> address.address + isSpoofAddress(personal) -> "$personal <${address.address}>" + else -> personal } } diff --git a/legacy/core/src/test/java/com/fsck/k9/helper/MessageHelperTest.kt b/legacy/core/src/test/java/com/fsck/k9/helper/MessageHelperTest.kt index dd0f46e5fc7..b10088bd851 100644 --- a/legacy/core/src/test/java/com/fsck/k9/helper/MessageHelperTest.kt +++ b/legacy/core/src/test/java/com/fsck/k9/helper/MessageHelperTest.kt @@ -133,7 +133,7 @@ class MessageHelperTest : RobolectricTest() { } @Test - fun toFriendly_spoofPreventionOverridesPersonal() { + fun toFriendly_spoofPreventionExpandsToShowBothPersonalAndAddress() { val address = Address("test@testor.com", "potus@whitehouse.gov") val friendly = toFriendly( @@ -143,7 +143,21 @@ class MessageHelperTest : RobolectricTest() { messageListPreferencesManager.getConfig().contactNameColor, contactRepository, ) - assertThat(friendly).isEqualTo("test@testor.com") + assertThat(friendly).isEqualTo("potus@whitehouse.gov ") + } + + @Test + fun toFriendly_firefoxRelayAddressShowsOriginalSenderAndRelayAddress() { + val address = Address("alias123@mozmail.com", "sender@example.com [via Relay]") + val friendly = + toFriendly( + address, + messageListPreferencesManager.getConfig().isShowCorrespondentNames, + messageListPreferencesManager.getConfig().isChangeContactNameColor, + messageListPreferencesManager.getConfig().contactNameColor, + contactRepository, + ) + assertThat(friendly).isEqualTo("sender@example.com [via Relay] ") } @Test diff --git a/legacy/ui/legacy/src/main/java/com/fsck/k9/ui/messageview/MessageViewRecipientFormatter.kt b/legacy/ui/legacy/src/main/java/com/fsck/k9/ui/messageview/MessageViewRecipientFormatter.kt index 8181886ad26..a0ee92065ac 100644 --- a/legacy/ui/legacy/src/main/java/com/fsck/k9/ui/messageview/MessageViewRecipientFormatter.kt +++ b/legacy/ui/legacy/src/main/java/com/fsck/k9/ui/messageview/MessageViewRecipientFormatter.kt @@ -61,9 +61,9 @@ internal class RealMessageViewRecipientFormatter( } private fun buildDisplayName(address: Address): CharSequence { - return address.personal?.takeIf { - it.isNotBlank() && !it.equals(meText, ignoreCase = true) && !isSpoofAddress(it) - } ?: address.address + val personal = address.personal?.takeIf { it.isNotBlank() && !it.equals(meText, ignoreCase = true) } + ?: return address.address + return if (isSpoofAddress(personal)) "$personal <${address.address}>" else personal } private fun isSpoofAddress(displayName: String): Boolean { diff --git a/legacy/ui/legacy/src/test/java/com/fsck/k9/ui/messageview/MessageViewRecipientFormatterTest.kt b/legacy/ui/legacy/src/test/java/com/fsck/k9/ui/messageview/MessageViewRecipientFormatterTest.kt index ad2d08b17b7..70b079227c9 100644 --- a/legacy/ui/legacy/src/test/java/com/fsck/k9/ui/messageview/MessageViewRecipientFormatterTest.kt +++ b/legacy/ui/legacy/src/test/java/com/fsck/k9/ui/messageview/MessageViewRecipientFormatterTest.kt @@ -152,7 +152,7 @@ class MessageViewRecipientFormatterTest : RobolectricTest() { } @Test - fun `do not show display name that looks like an email address`() { + fun `spoof prevention expands to show both display name and actual address`() { val recipientFormatter = createRecipientFormatter() val displayName = recipientFormatter.getDisplayName( @@ -160,7 +160,19 @@ class MessageViewRecipientFormatterTest : RobolectricTest() { account, ) - assertThat(displayName).isEqualTo("mallory@domain.example") + assertThat(displayName).isEqualTo("potus@whitehouse.gov ") + } + + @Test + fun `firefox relay address shows original sender and relay address`() { + val recipientFormatter = createRecipientFormatter() + + val displayName = recipientFormatter.getDisplayName( + Address("alias123@mozmail.com", "sender@example.com [via Relay]"), + account, + ) + + assertThat(displayName).isEqualTo("sender@example.com [via Relay] ") } @Test