From 8b946b6df1e12e4057fc0f81e629a40592eb8e41 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 20 Apr 2022 11:24:53 +0200 Subject: [PATCH] Added rule option to reply/forward raw message file --- .../java/eu/faircode/email/EntityRule.java | 24 +++++++++++++++++++ .../java/eu/faircode/email/FragmentRule.java | 5 ++++ app/src/main/res/layout/fragment_rule.xml | 13 ++++++++-- app/src/main/res/values/strings.xml | 1 + 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/EntityRule.java b/app/src/main/java/eu/faircode/email/EntityRule.java index 554f48c218..bc1a80fc00 100644 --- a/app/src/main/java/eu/faircode/email/EntityRule.java +++ b/app/src/main/java/eu/faircode/email/EntityRule.java @@ -62,6 +62,7 @@ import java.util.regex.Pattern; import javax.mail.Address; import javax.mail.Header; import javax.mail.MessagingException; +import javax.mail.Part; import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; import javax.mail.internet.InternetHeaders; @@ -639,6 +640,7 @@ public class EntityRule { DB db = DB.getInstance(context); String to = jargs.optString("to"); boolean resend = jargs.optBoolean("resend"); + boolean attached = jargs.optBoolean("attached"); boolean attachments = jargs.optBoolean("attachments"); if (TextUtils.isEmpty(to) && @@ -667,6 +669,11 @@ public class EntityRule { EntityOperation.queue(context, message, EntityOperation.HEADERS); } + if (!resend && attached && !Boolean.TRUE.equals(message.raw)) { + complete = false; + EntityOperation.queue(context, message, EntityOperation.RAW); + } + if (!complete) { EntityOperation.queue(context, message, EntityOperation.RULE, this.id); return false; @@ -699,6 +706,7 @@ public class EntityRule { boolean attachments = jargs.optBoolean("attachments"); String to = jargs.optString("to"); boolean resend = jargs.optBoolean("resend"); + boolean attached = jargs.optBoolean("attached"); boolean cc = jargs.optBoolean("cc"); boolean isReply = TextUtils.isEmpty(to); @@ -835,6 +843,22 @@ public class EntityRule { if (attachments || resend) EntityAttachment.copy(context, message.id, reply.id); + if (!resend && attached) { + EntityAttachment attachment = new EntityAttachment(); + attachment.message = reply.id; + attachment.sequence = 1; + attachment.name = "email.eml"; + attachment.type = "message/rfc822"; + attachment.disposition = Part.ATTACHMENT; + attachment.progress = 0; + attachment.id = db.attachment().insertAttachment(attachment); + + File source = message.getRawFile(context); + File target = attachment.getFile(context); + Helper.copy(source, target); + db.attachment().setDownloaded(attachment.id, target.length()); + } + EntityOperation.queue(context, reply, EntityOperation.SEND); // Batch send operations, wait until after commit diff --git a/app/src/main/java/eu/faircode/email/FragmentRule.java b/app/src/main/java/eu/faircode/email/FragmentRule.java index dcddc0b544..a1c0d11296 100644 --- a/app/src/main/java/eu/faircode/email/FragmentRule.java +++ b/app/src/main/java/eu/faircode/email/FragmentRule.java @@ -148,6 +148,7 @@ public class FragmentRule extends FragmentBase { private EditText etTo; private ImageButton ibTo; private CheckBox cbResend; + private CheckBox cbAttached; private CheckBox cbCc; private Button btnTtsSetup; @@ -301,6 +302,7 @@ public class FragmentRule extends FragmentBase { etTo = view.findViewById(R.id.etTo); ibTo = view.findViewById(R.id.ibTo); cbResend = view.findViewById(R.id.cbResend); + cbAttached = view.findViewById(R.id.cbAttached); cbCc = view.findViewById(R.id.cbCc); btnTtsSetup = view.findViewById(R.id.btnTtsSetup); @@ -652,6 +654,7 @@ public class FragmentRule extends FragmentBase { cbAnswerSubject.setEnabled(!checked); cbOriginalText.setEnabled(!checked); cbWithAttachments.setEnabled(!checked); + cbAttached.setEnabled(false); } }); @@ -1177,6 +1180,7 @@ public class FragmentRule extends FragmentBase { etTo.setText(jaction.optString("to")); cbResend.setChecked(jaction.optBoolean("resend")); + cbAttached.setChecked(jaction.optBoolean("attached")); cbCc.setChecked(jaction.optBoolean("cc")); break; @@ -1520,6 +1524,7 @@ public class FragmentRule extends FragmentBase { jaction.put("attachments", cbWithAttachments.isChecked()); jaction.put("to", etTo.getText().toString().trim()); jaction.put("resend", cbResend.isChecked()); + jaction.put("attached", cbAttached.isChecked()); jaction.put("cc", cbCc.isChecked()); break; diff --git a/app/src/main/res/layout/fragment_rule.xml b/app/src/main/res/layout/fragment_rule.xml index a34722b143..ac7748bb0e 100644 --- a/app/src/main/res/layout/fragment_rule.xml +++ b/app/src/main/res/layout/fragment_rule.xml @@ -911,6 +911,15 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/etTo" /> + + + app:layout_constraintTop_toBottomOf="@id/cbAttached" /> + app:constraint_referenced_ids="tvAnswerIdentity,spIdent,tvAnswerTemplate,spAnswer,cbAnswerSubject,cbOriginalText,cbWithAttachments,tvTo,etTo,ibTo,cbResend,cbAttached,cbCc,tvAnswerRemark" /> Include original message text Forward to Resend + Attach raw message file Reply to CC addresses With attachments Only one reply will be sent for any conversation, to avoid reply loops