From 9a1c3b04feee5848ab927017de73a644434be737 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 11 Feb 2022 11:30:30 +0100 Subject: [PATCH] Added rule action option to include message text --- .../java/eu/faircode/email/EntityRule.java | 34 +++++++++++-------- .../java/eu/faircode/email/FragmentRule.java | 5 +++ app/src/main/res/layout/fragment_rule.xml | 14 ++++++-- app/src/main/res/values/strings.xml | 1 + 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/EntityRule.java b/app/src/main/java/eu/faircode/email/EntityRule.java index aaa0739568..fbbb76f18b 100644 --- a/app/src/main/java/eu/faircode/email/EntityRule.java +++ b/app/src/main/java/eu/faircode/email/EntityRule.java @@ -676,6 +676,7 @@ public class EntityRule { long iid = jargs.getLong("identity"); long aid = jargs.getLong("answer"); + boolean add_text = jargs.optBoolean("text", true); String to = jargs.optString("to"); boolean cc = jargs.optBoolean("cc"); boolean attachments = jargs.optBoolean("attachments"); @@ -758,26 +759,29 @@ public class EntityRule { reply.id = db.message().insertMessage(reply); String body = answer.getHtml(message.from); - Document msg = JsoupEx.parse(body); - Element div = msg.createElement("div"); + if (add_text) { + Document msg = JsoupEx.parse(body); - Element p = message.getReplyHeader(context, msg, separate_reply, extended_reply); - div.appendChild(p); + Element div = msg.createElement("div"); - Document answering = JsoupEx.parse(message.getFile(context)); - Element e = answering.body(); - if (quote) { - String style = e.attr("style"); - style = HtmlHelper.mergeStyles(style, HtmlHelper.getQuoteStyle(e)); - e.tagName("blockquote").attr("style", style); - } else - e.tagName("p"); - div.appendChild(e); + Element p = message.getReplyHeader(context, msg, separate_reply, extended_reply); + div.appendChild(p); + + Document answering = JsoupEx.parse(message.getFile(context)); + Element e = answering.body(); + if (quote) { + String style = e.attr("style"); + style = HtmlHelper.mergeStyles(style, HtmlHelper.getQuoteStyle(e)); + e.tagName("blockquote").attr("style", style); + } else + e.tagName("p"); + div.appendChild(e); - msg.body().appendChild(div); + msg.body().appendChild(div); - body = msg.outerHtml(); + body = msg.outerHtml(); + } File file = reply.getFile(context); Helper.writeText(file, body); diff --git a/app/src/main/java/eu/faircode/email/FragmentRule.java b/app/src/main/java/eu/faircode/email/FragmentRule.java index 400f2af3d1..59dc861580 100644 --- a/app/src/main/java/eu/faircode/email/FragmentRule.java +++ b/app/src/main/java/eu/faircode/email/FragmentRule.java @@ -140,6 +140,7 @@ public class FragmentRule extends FragmentBase { private Spinner spIdent; private Spinner spAnswer; + private CheckBox cbIncludeMessageText; private EditText etTo; private ImageButton ibTo; private CheckBox cbCc; @@ -290,6 +291,7 @@ public class FragmentRule extends FragmentBase { spIdent = view.findViewById(R.id.spIdent); spAnswer = view.findViewById(R.id.spAnswer); + cbIncludeMessageText = view.findViewById(R.id.cbIncludeMessageText); etTo = view.findViewById(R.id.etTo); ibTo = view.findViewById(R.id.ibTo); cbCc = view.findViewById(R.id.cbCc); @@ -1137,6 +1139,8 @@ public class FragmentRule extends FragmentBase { break; } + cbIncludeMessageText.setChecked(jaction.optBoolean("text", true)); + etTo.setText(jaction.optString("to")); cbCc.setChecked(jaction.optBoolean("cc")); cbWithAttachments.setChecked(jaction.optBoolean("attachments")); @@ -1477,6 +1481,7 @@ public class FragmentRule extends FragmentBase { EntityAnswer answer = (EntityAnswer) spAnswer.getSelectedItem(); jaction.put("identity", identity == null ? -1 : identity.id); jaction.put("answer", answer == null || answer.id == null ? -1 : answer.id); + jaction.put("text", cbIncludeMessageText.isChecked()); jaction.put("to", etTo.getText().toString().trim()); jaction.put("cc", cbCc.isChecked()); jaction.put("attachments", cbWithAttachments.isChecked()); diff --git a/app/src/main/res/layout/fragment_rule.xml b/app/src/main/res/layout/fragment_rule.xml index 82234fc0de..7a2331cbf1 100644 --- a/app/src/main/res/layout/fragment_rule.xml +++ b/app/src/main/res/layout/fragment_rule.xml @@ -840,6 +840,16 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tvAnswerTemplate" /> + + + app:layout_constraintTop_toBottomOf="@id/cbIncludeMessageText" /> + app:constraint_referenced_ids="tvAnswerIdentity,spIdent,tvAnswerTemplate,spAnswer,cbIncludeMessageText,tvTo,etTo,ibTo,cbCc,cbWithAttachments,tvAnswerRemark" /> All messages in same conversation and folder Identity Reply template + Include message text Forward to Reply to CC addresses With attachments