From ffcfb16227d45a99d5468e0d3d06ac5c50624a7f Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 14 Jan 2023 23:40:22 +0100 Subject: [PATCH] Added option to disable auto blocking junk senders --- .../eu/faircode/email/EntityOperation.java | 22 +++++++++++-------- .../email/FragmentOptionsBehavior.java | 11 +++++++++- .../res/layout/fragment_options_behavior.xml | 14 +++++++++++- app/src/main/res/values/strings.xml | 1 + 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/EntityOperation.java b/app/src/main/java/eu/faircode/email/EntityOperation.java index 4aa0de23c4..618bc0d155 100644 --- a/app/src/main/java/eu/faircode/email/EntityOperation.java +++ b/app/src/main/java/eu/faircode/email/EntityOperation.java @@ -211,6 +211,7 @@ public class EntityOperation { boolean autounflag = prefs.getBoolean("autounflag", false); boolean reset_importance = prefs.getBoolean("reset_importance", false); boolean reset_snooze = prefs.getBoolean("reset_snooze", true); + boolean auto_block_sender = prefs.getBoolean("auto_block_sender", true); if (jargs.opt(1) != null) { // rules, classify @@ -230,16 +231,19 @@ public class EntityOperation { return; if (EntityFolder.JUNK.equals(target.type) && - Objects.equals(source.account, target.account) && - (jargs.opt(3) == null || !jargs.optBoolean(3))) { + Objects.equals(source.account, target.account)) { + Boolean noblock = (Boolean) jargs.opt(3); jargs.remove(3); - // Prevent blocking self - List identities = db.identity().getComposableIdentities(null); - if (!message.fromSelf(identities)) { - EntityLog.log(context, "Auto block sender=" + MessageHelper.formatAddresses(message.from)); - EntityContact.update(context, - message.account, message.identity, message.from, - EntityContact.TYPE_JUNK, message.received); + boolean block = (noblock == null ? auto_block_sender : !noblock); + if (block) { + // Prevent blocking self + List identities = db.identity().getComposableIdentities(null); + if (!message.fromSelf(identities)) { + EntityLog.log(context, "Auto block sender=" + MessageHelper.formatAddresses(message.from)); + EntityContact.update(context, + message.account, message.identity, message.from, + EntityContact.TYPE_JUNK, message.received); + } } } diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java b/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java index e1d30dc4d6..9cc6f79888 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java @@ -100,6 +100,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe private SwitchCompat swAutoImportant; private SwitchCompat swResetImportance; private SwitchCompat swResetSnooze; + private SwitchCompat swAutoBlockSender; private SwitchCompat swSwipeReply; final static int MAX_SWIPE_SENSITIVITY = 10; @@ -113,7 +114,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe "autoexpand", "expand_first", "expand_all", "expand_one", "collapse_multiple", "autoclose", "onclose", "autoclose_unseen", "collapse_marked", "undo_timeout", - "autoread", "flag_snoozed", "autounflag", "auto_important", "reset_importance", "reset_snooze", + "autoread", "flag_snoozed", "autounflag", "auto_important", "reset_importance", "reset_snooze", "auto_block_sender", "swipe_reply" }; @@ -169,6 +170,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe swAutoImportant = view.findViewById(R.id.swAutoImportant); swResetImportance = view.findViewById(R.id.swResetImportance); swResetSnooze = view.findViewById(R.id.swResetSnooze); + swAutoBlockSender = view.findViewById(R.id.swAutoBlockSender); swSwipeReply = view.findViewById(R.id.swSwipeReply); setOptions(); @@ -514,6 +516,12 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe } }); + swAutoBlockSender.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("auto_block_sender", checked).apply(); + } + }); swSwipeReply.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override @@ -635,6 +643,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe swAutoImportant.setChecked(prefs.getBoolean("auto_important", false)); swResetImportance.setChecked(prefs.getBoolean("reset_importance", false)); swResetSnooze.setChecked(prefs.getBoolean("reset_snooze", true)); + swAutoBlockSender.setChecked(prefs.getBoolean("auto_block_sender", true)); swSwipeReply.setChecked(prefs.getBoolean("swipe_reply", false)); } diff --git a/app/src/main/res/layout/fragment_options_behavior.xml b/app/src/main/res/layout/fragment_options_behavior.xml index af6745a635..6d3a3298a2 100644 --- a/app/src/main/res/layout/fragment_options_behavior.xml +++ b/app/src/main/res/layout/fragment_options_behavior.xml @@ -723,6 +723,18 @@ app:layout_constraintTop_toBottomOf="@id/swResetImportance" app:switchPadding="12dp" /> + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e9a8165dea..dd523810c7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -650,6 +650,7 @@ Automatically make starred messages important Reset importance on moving messages Cancel snooze on moving messages + Automatically block the sender when reporting spam Swipe expanded messages to the right to reply Default snooze/delay time