From 9ca4808a720e510a5c5bed1807914f69288f9811 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 4 May 2022 17:38:59 +0200 Subject: [PATCH] Added option to use blocklists for POP3 --- app/src/main/java/eu/faircode/email/Core.java | 23 ++++++++++++++++++- .../email/FragmentOptionsSynchronize.java | 15 +++++++++++- .../layout/fragment_options_synchronize.xml | 14 ++++++++++- app/src/main/res/values/strings.xml | 1 + 4 files changed, 50 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 211b1c020e..b9d287ce1f 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -2763,6 +2763,8 @@ class Core { boolean notify_known = prefs.getBoolean("notify_known", false); boolean download_eml = prefs.getBoolean("download_eml", false); boolean download_plain = prefs.getBoolean("download_plain", false); + boolean check_blocklist = prefs.getBoolean("check_blocklist", false); + boolean use_blocklist_pop = prefs.getBoolean("use_blocklist_pop", false); boolean pro = ActivityBilling.isPro(context); boolean force = jargs.optBoolean(5, false); @@ -3052,7 +3054,26 @@ class Core { // No reply_domain // No MX check - // No blocklist + + if (check_blocklist && use_blocklist_pop) { + message.blocklist = DnsBlockList.isJunk(context, + imessage.getHeader("Received")); + + if (message.blocklist == null || !message.blocklist) { + List
senders = new ArrayList<>(); + if (message.reply != null) + senders.addAll(Arrays.asList(message.reply)); + if (message.from != null) + senders.addAll(Arrays.asList(message.from)); + message.blocklist = DnsBlockList.isJunk(context, senders); + } + + if (Boolean.TRUE.equals(message.blocklist)) { + EntityLog.log(context, account.name + " POP blocklist=" + + MessageHelper.formatAddresses(message.from)); + continue; + } + } if (message.from != null) { EntityContact badboy = null; diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsSynchronize.java b/app/src/main/java/eu/faircode/email/FragmentOptionsSynchronize.java index fb265ddd59..fb9cafb945 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsSynchronize.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsSynchronize.java @@ -102,6 +102,7 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr private SwitchCompat swCheckMx; private SwitchCompat swCheckBlocklist; private SwitchCompat swUseBlocklist; + private SwitchCompat swUseBlocklistPop; private RecyclerView rvBlocklist; private AdapterBlocklist badapter; @@ -115,7 +116,8 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr "sync_nodate", "sync_unseen", "sync_flagged", "delete_unseen", "sync_kept", "gmail_thread_id", "outlook_thread_id", "subject_threading", "sync_folders", "sync_folders_poll", "sync_shared_folders", "subscriptions", - "check_authentication", "check_tls", "check_reply_domain", "check_mx", "check_blocklist", "use_blocklist", + "check_authentication", "check_tls", "check_reply_domain", "check_mx", + "check_blocklist", "use_blocklist", "use_blocklist_pop", "tune_keep_alive" }; @@ -177,6 +179,7 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr swCheckMx = view.findViewById(R.id.swCheckMx); swCheckBlocklist = view.findViewById(R.id.swCheckBlocklist); swUseBlocklist = view.findViewById(R.id.swUseBlocklist); + swUseBlocklistPop = view.findViewById(R.id.swUseBlocklistPop); rvBlocklist = view.findViewById(R.id.rvBlocklist); grpExempted = view.findViewById(R.id.grpExempted); @@ -454,6 +457,7 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { prefs.edit().putBoolean("check_blocklist", checked).apply(); swUseBlocklist.setEnabled(checked); + swUseBlocklistPop.setEnabled(checked); } }); @@ -464,6 +468,13 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr } }); + swUseBlocklistPop.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("use_blocklist_pop", checked).apply(); + } + }); + rvBlocklist.setHasFixedSize(false); rvBlocklist.setLayoutManager(new LinearLayoutManager(getContext())); badapter = new AdapterBlocklist(getContext(), DnsBlockList.getListsAvailable()); @@ -575,6 +586,8 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr swCheckBlocklist.setChecked(prefs.getBoolean("check_blocklist", false)); swUseBlocklist.setChecked(prefs.getBoolean("use_blocklist", false)); swUseBlocklist.setEnabled(swCheckBlocklist.isChecked()); + swUseBlocklistPop.setChecked(prefs.getBoolean("use_blocklist_pop", false)); + swUseBlocklistPop.setEnabled(swCheckBlocklist.isChecked()); } private String formatHour(Context context, int minutes) { diff --git a/app/src/main/res/layout/fragment_options_synchronize.xml b/app/src/main/res/layout/fragment_options_synchronize.xml index d08c0cc1c9..21e6f200f7 100644 --- a/app/src/main/res/layout/fragment_options_synchronize.xml +++ b/app/src/main/res/layout/fragment_options_synchronize.xml @@ -926,6 +926,18 @@ app:layout_constraintTop_toBottomOf="@id/tvCheckBlocklistWarning" app:switchPadding="12dp" /> + + + app:layout_constraintTop_toBottomOf="@id/swUseBlocklistPop" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3b4c08f522..581b4a640e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -378,6 +378,7 @@ Check sender email addresses on synchronizing messages Check if the sender\'s domain name is on a spam block list Move messages from domains on a block list to the spam folder + Skip messages from domains on a block list (POP3 only) Automatically tune the keep-alive interval Show keyboard by default