From 86c26e895b1b7d2b70dc75bce9ec52ab75bc3827 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 30 Jan 2022 17:26:07 +0100 Subject: [PATCH] Refactoring --- app/src/main/java/eu/faircode/email/EntityRule.java | 8 +++++--- .../java/eu/faircode/email/FragmentDialogJunk.java | 13 ++++++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/EntityRule.java b/app/src/main/java/eu/faircode/email/EntityRule.java index 307bb7ce26..47e94d6513 100644 --- a/app/src/main/java/eu/faircode/email/EntityRule.java +++ b/app/src/main/java/eu/faircode/email/EntityRule.java @@ -1019,6 +1019,7 @@ public class EntityRule { if (message.from == null) return rules; + List domains = new ArrayList<>(); for (Address from : message.from) { String sender = ((InternetAddress) from).getAddress(); String name = MessageHelper.formatAddresses(new Address[]{from}); @@ -1029,10 +1030,11 @@ public class EntityRule { boolean regex = false; if (block_domain) { - int at = sender.indexOf('@'); - if (at > 0) { + String domain = UriHelper.getEmailDomain(sender); + if (!TextUtils.isEmpty(domain) && !domains.contains(domain)) { + domains.add(domain); regex = true; - sender = ".*@.*" + Pattern.quote(sender.substring(at + 1)) + ".*"; + sender = ".*@.*" + Pattern.quote(domain) + ".*"; } } diff --git a/app/src/main/java/eu/faircode/email/FragmentDialogJunk.java b/app/src/main/java/eu/faircode/email/FragmentDialogJunk.java index dde591490a..245408ec0f 100644 --- a/app/src/main/java/eu/faircode/email/FragmentDialogJunk.java +++ b/app/src/main/java/eu/faircode/email/FragmentDialogJunk.java @@ -323,22 +323,21 @@ public class FragmentDialogJunk extends FragmentDialogBase { } }); + List regex = new ArrayList<>(); + regex.addAll(COMMON_DOMAINS); + regex.addAll(EmailProvider.getDomainNames(context)); + boolean common = false; List domains = new ArrayList<>(); if (froms != null) for (Address from : froms) { String email = ((InternetAddress) from).getAddress(); - int at = (email == null ? -1 : email.indexOf('@')); - String domain = (at < 0 ? null : email.substring(at + 1).toLowerCase(Locale.ROOT)); - if (TextUtils.isEmpty(domain)) + String domain = UriHelper.getEmailDomain(email); + if (TextUtils.isEmpty(domain) || domains.contains(domain)) continue; domains.add(domain); - List regex = new ArrayList<>(); - regex.addAll(COMMON_DOMAINS); - regex.addAll(EmailProvider.getDomainNames(context)); - for (String r : regex) if (domain.matches(r)) { common = true;