From 76e99796a5ff5c2c19c5855f47dbba3061546dbc Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 8 Aug 2021 12:57:55 +0200 Subject: [PATCH] Check URI against block lists --- .../main/java/eu/faircode/email/DnsBlockList.java | 13 ++++++++++++- .../eu/faircode/email/FragmentDialogOpenLink.java | 6 +++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/DnsBlockList.java b/app/src/main/java/eu/faircode/email/DnsBlockList.java index 588e9f29cd..7d3146e459 100644 --- a/app/src/main/java/eu/faircode/email/DnsBlockList.java +++ b/app/src/main/java/eu/faircode/email/DnsBlockList.java @@ -24,6 +24,7 @@ import android.content.SharedPreferences; import android.net.Uri; import android.text.TextUtils; +import androidx.core.net.MailTo; import androidx.preference.PreferenceManager; import java.net.Inet4Address; @@ -162,7 +163,17 @@ public class DnsBlockList { return (hasDomain ? false : null); } - static Boolean isJunk(Context context, String domain) { + static Boolean isJunk(Context context, Uri uri) { + String domain = null; + if ("mailto".equalsIgnoreCase(uri.getScheme())) { + MailTo email = MailTo.parse(uri.toString()); + domain = UriHelper.getEmailDomain(email.getTo()); + } else + domain = uri.getHost(); + + if (domain == null) + return null; + return isJunk(context, domain, false, BLOCK_LISTS); } diff --git a/app/src/main/java/eu/faircode/email/FragmentDialogOpenLink.java b/app/src/main/java/eu/faircode/email/FragmentDialogOpenLink.java index f36e4ff624..1b2b12f5c9 100644 --- a/app/src/main/java/eu/faircode/email/FragmentDialogOpenLink.java +++ b/app/src/main/java/eu/faircode/email/FragmentDialogOpenLink.java @@ -408,13 +408,13 @@ public class FragmentDialogOpenLink extends FragmentDialogBase { if (check_links_dbl && tvSuspicious.getVisibility() != View.VISIBLE) { Bundle args = new Bundle(); - args.putString("host", host); + args.putParcelable("uri", uri); new SimpleTask() { @Override protected Boolean onExecute(Context context, Bundle args) throws Throwable { - String host = args.getString("host"); - return DnsBlockList.isJunk(context, host); + Uri uri = args.getParcelable("uri"); + return DnsBlockList.isJunk(context, uri); } @Override