From 6997965336adef5d63e77c774ee8946ea6461486 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 19 Mar 2023 07:40:23 +0100 Subject: [PATCH] Skip suggesting no-reply addresses of received messages --- .../eu/faircode/email/FragmentCompose.java | 4 ++- .../java/eu/faircode/email/MessageHelper.java | 36 +++++++++++-------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 49cfb494b9..7069754590 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -1148,7 +1148,9 @@ public class FragmentCompose extends FragmentBase { if (suggest_sent) items.addAll(db.contact().searchContacts(null, EntityContact.TYPE_TO, wildcard)); if (suggest_received) - items.addAll(db.contact().searchContacts(null, EntityContact.TYPE_FROM, wildcard)); + for (EntityContact item : db.contact().searchContacts(null, EntityContact.TYPE_FROM, wildcard)) + if (!MessageHelper.isNoReply(item.email)) + items.add(item); for (EntityContact item : items) { EntityContact existing = map.get(item.email); if (existing == null) diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index fe56b80d87..0834f2c86c 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -5284,21 +5284,27 @@ public class MessageHelper { static boolean isNoReply(Address address) { if (address instanceof InternetAddress) { String email = ((InternetAddress) address).getAddress(); - String username = UriHelper.getEmailUser(email); - String domain = UriHelper.getEmailDomain(email); - - if (!TextUtils.isEmpty(username)) { - username = username.toLowerCase(Locale.ROOT); - for (String value : DO_NOT_REPLY) - if (username.contains(value)) - return true; - } - if (!TextUtils.isEmpty(domain)) { - domain = domain.toLowerCase(Locale.ROOT); - for (String value : DO_NOT_REPLY) - if (domain.startsWith(value)) - return true; - } + if (isNoReply(email)) + return true; + } + return false; + } + + static boolean isNoReply(String email) { + String username = UriHelper.getEmailUser(email); + if (!TextUtils.isEmpty(username)) { + username = username.toLowerCase(Locale.ROOT); + for (String value : DO_NOT_REPLY) + if (username.contains(value)) + return true; + } + + String domain = UriHelper.getEmailDomain(email); + if (!TextUtils.isEmpty(domain)) { + domain = domain.toLowerCase(Locale.ROOT); + for (String value : DO_NOT_REPLY) + if (domain.startsWith(value)) + return true; } return false;