diff --git a/app/src/main/java/eu/faircode/email/ActivitySetup.java b/app/src/main/java/eu/faircode/email/ActivitySetup.java index 72683a1892..7b4a0119ec 100644 --- a/app/src/main/java/eu/faircode/email/ActivitySetup.java +++ b/app/src/main/java/eu/faircode/email/ActivitySetup.java @@ -709,8 +709,39 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac } JSONArray jrules = new JSONArray(); - for (EntityRule rule : db.rule().getRules(folder.id)) + for (EntityRule rule : db.rule().getRules(folder.id)) { + try { + JSONObject jaction = new JSONObject(rule.action); + int type = jaction.getInt("type"); + switch (type) { + case EntityRule.TYPE_MOVE: + case EntityRule.TYPE_COPY: + long target = jaction.getLong("target"); + EntityFolder f = db.folder().getFolder(target); + EntityAccount a = (f == null ? null : db.account().getAccount(f.account)); + if (a != null) + jaction.put("targetAccountUuid", a.uuid); + if (f != null) + jaction.put("targetFolderName", f.name); + break; + case EntityRule.TYPE_ANSWER: + long identity = jaction.getLong("identity"); + long answer = jaction.getLong("answer"); + EntityIdentity i = db.identity().getIdentity(identity); + EntityAnswer t = db.answer().getAnswer(answer); + if (i != null) + jaction.put("identityUuid", i.uuid); + if (t != null) + jaction.put("answerUuid", t.uuid); + break; + } + rule.action = jaction.toString(); + } catch (Throwable ex) { + Log.e(ex); + } + jrules.put(rule.toJSON()); + } jfolder.put("rules", jrules); jfolders.put(jfolder); @@ -1169,17 +1200,48 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac switch (type) { case EntityRule.TYPE_MOVE: case EntityRule.TYPE_COPY: + String targetAccountUuid = jaction.optString("targetAccountUuid"); + String targetFolderName = jaction.optString("targetFolderName"); + if (!TextUtils.isEmpty(targetAccountUuid) && !TextUtils.isEmpty(targetFolderName)) { + EntityAccount a = db.account().getAccountByUUID(targetAccountUuid); + if (a != null) { + EntityFolder f = db.folder().getFolderByName(a.id, targetFolderName); + if (f != null) { + jaction.put("target", f.id); + break; + } + } + } + + // Legacy long target = jaction.getLong("target"); - Log.i("XLAT target " + target + " > " + xFolder.get(target)); - jaction.put("target", xFolder.get(target)); + Long tid = xFolder.get(target); + Log.i("XLAT target " + target + " > " + tid); + if (tid != null) + jaction.put("target", tid); break; case EntityRule.TYPE_ANSWER: + String identityUuid = jaction.optString("identityUuid"); + String answerUuid = jaction.optString("answerUuid"); + if (!TextUtils.isEmpty(identityUuid) && !TextUtils.isEmpty(answerUuid)) { + EntityIdentity i = db.identity().getIdentityByUUID(identityUuid); + EntityAnswer a = db.answer().getAnswerByUUID(answerUuid); + if (i != null && a != null) { + jaction.put("identity", i.id); + jaction.put("answer", a.id); + break; + } + } + + // Legacy long identity = jaction.getLong("identity"); long answer = jaction.getLong("answer"); - Log.i("XLAT identity " + identity + " > " + xIdentity.get(identity)); - Log.i("XLAT answer " + answer + " > " + xAnswer.get(answer)); - jaction.put("identity", xIdentity.get(identity)); - jaction.put("answer", xAnswer.get(answer)); + Long iid = xIdentity.get(identity); + Long aid = xAnswer.get(answer); + Log.i("XLAT identity " + identity + " > " + iid); + Log.i("XLAT answer " + answer + " > " + aid); + jaction.put("identity", iid); + jaction.put("answer", aid); break; }