From f9418593cab4e645ae2e6b7c45d651c127ffcb70 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 1 May 2022 22:41:55 +0200 Subject: [PATCH] Stop scanning at tld --- .../main/java/eu/faircode/email/EmailProvider.java | 2 ++ app/src/main/java/eu/faircode/email/UriHelper.java | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/app/src/main/java/eu/faircode/email/EmailProvider.java b/app/src/main/java/eu/faircode/email/EmailProvider.java index 1478acbb23..5a7df9ebd6 100644 --- a/app/src/main/java/eu/faircode/email/EmailProvider.java +++ b/app/src/main/java/eu/faircode/email/EmailProvider.java @@ -426,6 +426,8 @@ public class EmailProvider implements Parcelable { candidates.addAll(_fromDomain(context, target, email, discover)); int dot = target.indexOf('.'); target = target.substring(dot + 1); + if (UriHelper.isTld(context, target)) + break; } } diff --git a/app/src/main/java/eu/faircode/email/UriHelper.java b/app/src/main/java/eu/faircode/email/UriHelper.java index 73d4a32fe6..08b878ce74 100644 --- a/app/src/main/java/eu/faircode/email/UriHelper.java +++ b/app/src/main/java/eu/faircode/email/UriHelper.java @@ -94,6 +94,18 @@ public class UriHelper { return (host != null && _getSuffix(context, host) != null); } + static boolean isTld(Context context, String host) { + ensureSuffixList(context); + + synchronized (suffixList) { + int d = host.indexOf('.'); + String w = (d < 0 ? null : '*' + host.substring(d)); + return (!suffixList.contains('!' + host) && + !suffixList.contains(w) && + suffixList.contains(host)); + } + } + private static String _getSuffix(Context context, @NonNull String host) { ensureSuffixList(context);