From c2de70e91d1366915373353d709ef1516b474d05 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 1 Apr 2021 18:35:52 +0200 Subject: [PATCH] Allow no template when forwarding --- .../java/eu/faircode/email/EntityRule.java | 29 ++++++++++++++----- .../java/eu/faircode/email/FragmentRule.java | 11 +++++-- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/EntityRule.java b/app/src/main/java/eu/faircode/email/EntityRule.java index c97e88c3e6..3cce69af0c 100644 --- a/app/src/main/java/eu/faircode/email/EntityRule.java +++ b/app/src/main/java/eu/faircode/email/EntityRule.java @@ -405,11 +405,15 @@ public class EntityRule { throw new IllegalArgumentException("Identity not found"); long aid = jargs.optLong("answer", -1); - if (aid < 0) - throw new IllegalArgumentException(context.getString(R.string.title_rule_answer_missing)); - EntityAnswer answer = db.answer().getAnswer(aid); - if (answer == null) - throw new IllegalArgumentException("Answer not found"); + if (aid < 0) { + String to = jargs.optString("to"); + if (TextUtils.isEmpty(to)) + throw new IllegalArgumentException(context.getString(R.string.title_rule_answer_missing)); + } else { + EntityAnswer answer = db.answer().getAnswer(aid); + if (answer == null) + throw new IllegalArgumentException("Template not found"); + } return; case TYPE_TTS: return; @@ -541,9 +545,18 @@ public class EntityRule { if (identity == null) throw new IllegalArgumentException("Rule identity not found name=" + rule.name); - EntityAnswer answer = db.answer().getAnswer(aid); - if (answer == null) - throw new IllegalArgumentException("Rule answer not found name=" + rule.name); + EntityAnswer answer; + if (aid < 0) { + if (TextUtils.isEmpty(to)) + throw new IllegalArgumentException("Rule template missing name=" + rule.name); + + answer = new EntityAnswer(); + answer.text = ""; + } else { + answer = db.answer().getAnswer(aid); + if (answer == null) + throw new IllegalArgumentException("Rule template not found name=" + rule.name); + } EntityFolder outbox = db.folder().getOutbox(); if (outbox == null) { diff --git a/app/src/main/java/eu/faircode/email/FragmentRule.java b/app/src/main/java/eu/faircode/email/FragmentRule.java index 28e5286247..0aece11480 100644 --- a/app/src/main/java/eu/faircode/email/FragmentRule.java +++ b/app/src/main/java/eu/faircode/email/FragmentRule.java @@ -632,6 +632,11 @@ public class FragmentRule extends FragmentBase { adapterIdentity.clear(); adapterIdentity.addAll(data.identities); + EntityAnswer none = new EntityAnswer(); + none.name = "-"; + none.favorite = false; + data.answers.add(0, none); + adapterAnswer.clear(); adapterAnswer.addAll(data.answers); @@ -970,7 +975,7 @@ public class FragmentRule extends FragmentBase { } long answer = jaction.optLong("answer", -1); - for (int pos = 0; pos < adapterAnswer.getCount(); pos++) + for (int pos = 1; pos < adapterAnswer.getCount(); pos++) if (adapterAnswer.getItem(pos).id.equals(answer)) { spAnswer.setSelection(pos); break; @@ -1117,6 +1122,7 @@ public class FragmentRule extends FragmentBase { JSONObject jrecipient = jcondition.optJSONObject("recipient"); JSONObject jsubject = jcondition.optJSONObject("subject"); JSONObject jheader = jcondition.optJSONObject("header"); + JSONObject jdate = jcondition.optJSONObject("date"); JSONObject jschedule = jcondition.optJSONObject("schedule"); if (jsender == null && @@ -1124,6 +1130,7 @@ public class FragmentRule extends FragmentBase { jsubject == null && !jcondition.optBoolean("attachments") && jheader == null && + jdate == null && jschedule == null) throw new IllegalArgumentException(context.getString(R.string.title_rule_condition_missing)); @@ -1295,7 +1302,7 @@ public class FragmentRule extends FragmentBase { EntityIdentity identity = (EntityIdentity) spIdent.getSelectedItem(); EntityAnswer answer = (EntityAnswer) spAnswer.getSelectedItem(); jaction.put("identity", identity == null ? -1 : identity.id); - jaction.put("answer", answer == null ? -1 : answer.id); + jaction.put("answer", answer == null || answer.id == null ? -1 : answer.id); jaction.put("to", etTo.getText().toString().trim()); jaction.put("cc", cbCc.isChecked()); jaction.put("attachments", cbWithAttachments.isChecked());