From e6703354297dcd2fdf575c1398c223e091c3e47b Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 28 Dec 2021 08:59:08 +0100 Subject: [PATCH] Added rule action permanent delete --- CHANGELOG.md | 4 ++++ FAQ.md | 5 +---- app/src/main/assets/CHANGELOG.md | 4 ++++ .../java/eu/faircode/email/AdapterRule.java | 3 +++ .../java/eu/faircode/email/EntityRule.java | 13 ++++++++++++ .../java/eu/faircode/email/FragmentRule.java | 5 +++++ app/src/main/res/layout/fragment_rule.xml | 21 +++++++++++++++++++ app/src/main/res/values/strings.xml | 2 ++ metadata/en-US/changelogs/1800.txt | 4 ++++ 9 files changed, 57 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d684348141..803ba0c9ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ ### [Draconyx](https://en.wikipedia.org/wiki/Draconyx) +### Next version + +* Added rule action to permanently delete messages + ### 1.1800 - 2021-12-27 * Fixed crash when manually configuring an account diff --git a/FAQ.md b/FAQ.md index 7eaadbae65..1661d52745 100644 --- a/FAQ.md +++ b/FAQ.md @@ -2374,14 +2374,11 @@ You can select one of these actions to apply to matching messages: * Add keyword * Move * Copy (Gmail: label) +* Delete permanently (since version 1.1801) * Answer/forward (with template) * Text-to-speech (sender and subject) * Automation (Tasker, etc) -An small error in a rule condition can lead to a disaster, therefore irreversible actions, like permanent deletion, are unsupportable and won't be added. -If you want to permanently delete messages, you can use a filter rule to automatically move messages to the trash folder and set up auto deleting for the trash folder in the folder properties. -This way there is a chance to recover messages for when the filter condition was incorrect. - If you want to forward a message, consider to use a *move* action instead. This will be more reliable than forwarding because forwarded messages might be considered as spam. diff --git a/app/src/main/assets/CHANGELOG.md b/app/src/main/assets/CHANGELOG.md index d684348141..803ba0c9ab 100644 --- a/app/src/main/assets/CHANGELOG.md +++ b/app/src/main/assets/CHANGELOG.md @@ -4,6 +4,10 @@ ### [Draconyx](https://en.wikipedia.org/wiki/Draconyx) +### Next version + +* Added rule action to permanently delete messages + ### 1.1800 - 2021-12-27 * Fixed crash when manually configuring an account diff --git a/app/src/main/java/eu/faircode/email/AdapterRule.java b/app/src/main/java/eu/faircode/email/AdapterRule.java index b8a56946b3..589f22ad42 100644 --- a/app/src/main/java/eu/faircode/email/AdapterRule.java +++ b/app/src/main/java/eu/faircode/email/AdapterRule.java @@ -183,6 +183,9 @@ public class AdapterRule extends RecyclerView.Adapter { case EntityRule.TYPE_AUTOMATION: tvAction.setText(R.string.title_rule_automation); break; + case EntityRule.TYPE_DELETE: + tvAction.setText(R.string.title_rule_delete); + break; default: throw new IllegalArgumentException("Unknown action type=" + type); } diff --git a/app/src/main/java/eu/faircode/email/EntityRule.java b/app/src/main/java/eu/faircode/email/EntityRule.java index 125983a2e2..9c960a5313 100644 --- a/app/src/main/java/eu/faircode/email/EntityRule.java +++ b/app/src/main/java/eu/faircode/email/EntityRule.java @@ -113,6 +113,7 @@ public class EntityRule { static final int TYPE_HIDE = 12; static final int TYPE_IMPORTANCE = 13; static final int TYPE_TTS = 14; + static final int TYPE_DELETE = 15; static final String ACTION_AUTOMATION = BuildConfig.APPLICATION_ID + ".AUTOMATION"; static final String EXTRA_RULE = "rule"; @@ -464,6 +465,8 @@ public class EntityRule { return onActionTts(context, message, jaction); case TYPE_AUTOMATION: return onActionAutomation(context, message, jaction); + case TYPE_DELETE: + return onActionDelete(context, message, jaction); default: throw new IllegalArgumentException("Unknown rule type=" + type + " name=" + name); } @@ -528,6 +531,8 @@ public class EntityRule { return; case TYPE_AUTOMATION: return; + case TYPE_DELETE: + return; default: throw new IllegalArgumentException("Unknown rule type=" + type); } @@ -928,6 +933,14 @@ public class EntityRule { return true; } + private boolean onActionDelete(Context context, EntityMessage message, JSONObject jargs) { + EntityOperation.queue(context, message, EntityOperation.DELETE); + + message.ui_hide = true; + + return true; + } + private static Calendar getRelativeCalendar(int minutes, long reference) { int d = minutes / (24 * 60); int h = minutes / 60 % 24; diff --git a/app/src/main/java/eu/faircode/email/FragmentRule.java b/app/src/main/java/eu/faircode/email/FragmentRule.java index 69506e7c01..dd9a2bbeaf 100644 --- a/app/src/main/java/eu/faircode/email/FragmentRule.java +++ b/app/src/main/java/eu/faircode/email/FragmentRule.java @@ -161,6 +161,7 @@ public class FragmentRule extends FragmentBase { private Group grpAnswer; private Group grpTts; private Group grpAutomation; + private Group grpDelete; private ArrayAdapter adapterDay; private ArrayAdapter adapterAction; @@ -299,6 +300,7 @@ public class FragmentRule extends FragmentBase { grpAnswer = view.findViewById(R.id.grpAnswer); grpTts = view.findViewById(R.id.grpTts); grpAutomation = view.findViewById(R.id.grpAutomation); + grpDelete = view.findViewById(R.id.grpDelete); ibSender.setOnClickListener(new View.OnClickListener() { @Override @@ -456,6 +458,7 @@ public class FragmentRule extends FragmentBase { actions.add(new Action(EntityRule.TYPE_MOVE, getString(R.string.title_rule_move))); actions.add(new Action(EntityRule.TYPE_COPY, getString(R.string.title_rule_copy))); } + actions.add(new Action(EntityRule.TYPE_DELETE, getString(R.string.title_rule_delete))); actions.add(new Action(EntityRule.TYPE_ANSWER, getString(R.string.title_rule_answer))); actions.add(new Action(EntityRule.TYPE_TTS, getString(R.string.title_rule_tts))); actions.add(new Action(EntityRule.TYPE_AUTOMATION, getString(R.string.title_rule_automation))); @@ -587,6 +590,7 @@ public class FragmentRule extends FragmentBase { grpAnswer.setVisibility(View.GONE); grpTts.setVisibility(View.GONE); grpAutomation.setVisibility(View.GONE); + grpDelete.setVisibility(View.GONE); pbWait.setVisibility(View.VISIBLE); @@ -1050,6 +1054,7 @@ public class FragmentRule extends FragmentBase { grpAnswer.setVisibility(type == EntityRule.TYPE_ANSWER ? View.VISIBLE : View.GONE); grpTts.setVisibility(type == EntityRule.TYPE_TTS ? View.VISIBLE : View.GONE); grpAutomation.setVisibility(type == EntityRule.TYPE_AUTOMATION ? View.VISIBLE : View.GONE); + grpDelete.setVisibility(type == EntityRule.TYPE_DELETE ? View.VISIBLE : View.GONE); } private void onActionDelete() { diff --git a/app/src/main/res/layout/fragment_rule.xml b/app/src/main/res/layout/fragment_rule.xml index ab1950d3a5..ce397c0833 100644 --- a/app/src/main/res/layout/fragment_rule.xml +++ b/app/src/main/res/layout/fragment_rule.xml @@ -926,6 +926,21 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/btnTtsData" /> + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5b63ca0525..5dad521875 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1476,6 +1476,7 @@ Reply/forward Text to speech Automation + Delete permanently Edit rule Rule applies to @@ -1517,6 +1518,7 @@ Template missing Keyword missing This will send the intent \'%1$s\' with the extras \'%2$s\' + Permanent deletion is irreversible, so make sure the rule conditions are correct! Execute now Affected messages: %1$d diff --git a/metadata/en-US/changelogs/1800.txt b/metadata/en-US/changelogs/1800.txt index d684348141..803ba0c9ab 100644 --- a/metadata/en-US/changelogs/1800.txt +++ b/metadata/en-US/changelogs/1800.txt @@ -4,6 +4,10 @@ ### [Draconyx](https://en.wikipedia.org/wiki/Draconyx) +### Next version + +* Added rule action to permanently delete messages + ### 1.1800 - 2021-12-27 * Fixed crash when manually configuring an account