From 7234c33818f42992599a3964408295b265db640a Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 25 May 2020 15:01:30 +0200 Subject: [PATCH] Prevent answer loop --- .../main/java/eu/faircode/email/EntityRule.java | 15 ++++++++++++++- app/src/main/res/layout/fragment_rule.xml | 15 +++++++++++++-- app/src/main/res/values/strings.xml | 1 + 3 files changed, 28 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 fdc96f901b..e42f65ac6b 100644 --- a/app/src/main/java/eu/faircode/email/EntityRule.java +++ b/app/src/main/java/eu/faircode/email/EntityRule.java @@ -396,6 +396,19 @@ public class EntityRule { if (answer == null) throw new IllegalArgumentException("Rule answer not found"); + Address[] from = new InternetAddress[]{new InternetAddress(identity.email, identity.name)}; + + // Prevent loop + List messages = db.message().getMessagesByThread( + message.account, message.thread, null, message.folder); + for (EntityMessage threaded : messages) + if (!threaded.id.equals(message.id) && + MessageHelper.equal(threaded.from, from)) { + EntityLog.log(context, "Answer loop" + + " name=" + answer.name + + " from=" + MessageHelper.formatAddresses(from)); + return false; + } EntityMessage reply = new EntityMessage(); reply.account = message.account; @@ -406,7 +419,7 @@ public class EntityRule { reply.inreplyto = message.msgid; reply.thread = message.thread; reply.to = (message.reply == null || message.reply.length == 0 ? message.from : message.reply); - reply.from = new InternetAddress[]{new InternetAddress(identity.email, identity.name)}; + reply.from = from; if (cc) reply.cc = message.cc; reply.unsubscribe = "mailto:" + identity.email; diff --git a/app/src/main/res/layout/fragment_rule.xml b/app/src/main/res/layout/fragment_rule.xml index 58453d7887..190623eedb 100644 --- a/app/src/main/res/layout/fragment_rule.xml +++ b/app/src/main/res/layout/fragment_rule.xml @@ -656,6 +656,17 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/spAnswer" /> + + + app:layout_constraintTop_toBottomOf="@+id/tvAnswerRemark" /> + app:constraint_referenced_ids="tvAnswerIdentity,spIdent,tvAnswerTemplate,spAnswer,cbCc,tvAnswerRemark" /> Identity Reply template Reply to CC addresses + Only one reply will be sent for any conversation, to avoid reply loops Rule name missing Condition missing This will send the intent \'%1$s\' with the extras \'%2$s\'