From b13a7d62e2e3926d53b53dd1f7e67bdc925497d1 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 23 May 2019 15:57:44 +0200 Subject: [PATCH] Prevent crash --- app/src/main/java/eu/faircode/email/EntityRule.java | 12 ++++++++++++ .../main/java/eu/faircode/email/FragmentRule.java | 6 +++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/EntityRule.java b/app/src/main/java/eu/faircode/email/EntityRule.java index 15752d6356..99aefd4129 100644 --- a/app/src/main/java/eu/faircode/email/EntityRule.java +++ b/app/src/main/java/eu/faircode/email/EntityRule.java @@ -236,11 +236,23 @@ public class EntityRule { private void onActionMove(Context context, EntityMessage message, JSONObject jargs) throws JSONException { long target = jargs.getLong("target"); + + DB db = DB.getInstance(context); + EntityFolder folder = db.folder().getFolder(target); + if (folder == null) + throw new IllegalArgumentException("Rule move to folder not found"); + EntityOperation.queue(context, message, EntityOperation.MOVE, target, false); } private void onActionCopy(Context context, EntityMessage message, JSONObject jargs) throws JSONException { long target = jargs.getLong("target"); + + DB db = DB.getInstance(context); + EntityFolder folder = db.folder().getFolder(target); + if (folder == null) + throw new IllegalArgumentException("Rule copy to folder not found"); + EntityOperation.queue(context, message, EntityOperation.COPY, target, false); } diff --git a/app/src/main/java/eu/faircode/email/FragmentRule.java b/app/src/main/java/eu/faircode/email/FragmentRule.java index 3fbc20c7e6..908c6b9578 100644 --- a/app/src/main/java/eu/faircode/email/FragmentRule.java +++ b/app/src/main/java/eu/faircode/email/FragmentRule.java @@ -837,15 +837,15 @@ public class FragmentRule extends FragmentBase { case EntityRule.TYPE_MOVE: case EntityRule.TYPE_COPY: EntityFolder target = (EntityFolder) spTarget.getSelectedItem(); - jaction.put("target", target.id); + jaction.put("target", target == null ? -1 : target.id); break; case EntityRule.TYPE_ANSWER: EntityIdentity identity = (EntityIdentity) spIdent.getSelectedItem(); EntityAnswer answer = (EntityAnswer) spAnswer.getSelectedItem(); boolean cc = cbCc.isChecked(); - jaction.put("identity", identity.id); - jaction.put("answer", answer.id); + jaction.put("identity", identity == null ? -1 : identity.id); + jaction.put("answer", answer == null ? -1 : answer.id); jaction.put("cc", cc); break; }