From 0fac4cf7f0bfe6ed3bd6d2472b4cde092e512406 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 11 May 2022 18:26:13 +0200 Subject: [PATCH] Added option for forward threading --- .../java/eu/faircode/email/FragmentCompose.java | 8 +++++++- .../eu/faircode/email/FragmentOptionsSend.java | 14 +++++++++++++- .../java/eu/faircode/email/MessageHelper.java | 16 ++++++++++++++++ .../main/res/layout/fragment_options_send.xml | 14 +++++++++++++- app/src/main/res/values/strings.xml | 1 + 5 files changed, 50 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index cf43726e94..46344ab83a 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -4520,6 +4520,7 @@ public class FragmentCompose extends FragmentBase { boolean auto_identity = prefs.getBoolean("auto_identity", true); boolean suggest_sent = prefs.getBoolean("suggest_sent", true); boolean suggest_received = prefs.getBoolean("suggest_received", false); + boolean forward_new = prefs.getBoolean("forward_new", true); Log.i("Load draft action=" + action + " id=" + id + " reference=" + reference); @@ -4851,7 +4852,12 @@ public class FragmentCompose extends FragmentBase { } } else if ("forward".equals(action)) { - data.draft.thread = data.draft.msgid; // new thread + if (forward_new) + data.draft.thread = data.draft.msgid; // new thread + else { + data.draft.thread = ref.thread; + data.draft.references = (ref.references == null ? "" : ref.references + " ") + ref.msgid; + } data.draft.wasforwardedfrom = ref.msgid; } else if ("resend".equals(action)) { data.draft.resend = true; diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java b/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java index 5204aeee9d..15c31c824a 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java @@ -102,6 +102,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc private SwitchCompat swReceipt; private Spinner spReceiptType; private SwitchCompat swReceiptLegacy; + private SwitchCompat swForwardNew; private SwitchCompat swLookupMx; private SwitchCompat swReplyMove; @@ -118,7 +119,9 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc "separate_reply", "extended_reply", "write_below", "quote_reply", "quote_limit", "resize_reply", "signature_location", "signature_new", "signature_reply", "signature_reply_once", "signature_forward", "attach_new", "auto_link", "plain_only", "format_flowed", "usenet_signature", "remove_signatures", - "receipt_default", "receipt_type", "receipt_legacy", "lookup_mx", "reply_move" + "receipt_default", "receipt_type", "receipt_legacy", + "forward_new", + "lookup_mx", "reply_move" }; @Override @@ -178,6 +181,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc swReceipt = view.findViewById(R.id.swReceipt); spReceiptType = view.findViewById(R.id.spReceiptType); swReceiptLegacy = view.findViewById(R.id.swReceiptLegacy); + swForwardNew = view.findViewById(R.id.swForwardNew); swLookupMx = view.findViewById(R.id.swLookupMx); swReplyMove = view.findViewById(R.id.swReplyMove); @@ -566,6 +570,13 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc } }); + swForwardNew.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("forward_new", checked).apply(); + } + }); + swLookupMx.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -711,6 +722,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc swReceiptLegacy.setChecked(prefs.getBoolean("receipt_legacy", false)); + swForwardNew.setChecked(prefs.getBoolean("forward_new", true)); swLookupMx.setChecked(prefs.getBoolean("lookup_mx", false)); swReplyMove.setChecked(prefs.getBoolean("reply_move", false)); } diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index 8bf8cfa8a2..700448eaad 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -281,6 +281,7 @@ public class MessageHelper { boolean autocrypt = prefs.getBoolean("autocrypt", true); boolean mutual = prefs.getBoolean("autocrypt_mutual", true); boolean encrypt_subject = prefs.getBoolean("encrypt_subject", false); + boolean forward_new = prefs.getBoolean("forward_new", true); Map c = new HashMap<>(); c.put("id", message.id == null ? null : Long.toString(message.id)); @@ -338,8 +339,13 @@ public class MessageHelper { } imessage.addHeader("References", references); } + if (message.inreplyto != null) imessage.addHeader("In-Reply-To", message.inreplyto); + + if (message.wasforwardedfrom != null && !forward_new) + imessage.addHeader("X-Forwarded-Message-Id", message.wasforwardedfrom); + imessage.addHeader(HEADER_CORRELATION_ID, message.msgid); MailDateFormat mdf = new MailDateFormat(); @@ -1493,6 +1499,16 @@ public class MessageHelper { if (!TextUtils.isEmpty(inreplyto) && !refs.contains(inreplyto)) refs.add(inreplyto); + boolean forward_new = prefs.getBoolean("forward_new", true); + if (!forward_new) + try { + String fwd = imessage.getHeader("X-Forwarded-Message-Id", null); + if (!TextUtils.isEmpty(fwd) && !refs.contains(fwd)) + refs.add(fwd); + } catch (Throwable ex) { + Log.w(ex); + } + DB db = DB.getInstance(context); List all = new ArrayList<>(refs); diff --git a/app/src/main/res/layout/fragment_options_send.xml b/app/src/main/res/layout/fragment_options_send.xml index 421e27a7e6..4671dfeb01 100644 --- a/app/src/main/res/layout/fragment_options_send.xml +++ b/app/src/main/res/layout/fragment_options_send.xml @@ -840,6 +840,18 @@ app:layout_constraintTop_toBottomOf="@id/spReceiptType" app:switchPadding="12dp" /> + + Follow Usenet signature convention Remove recognized signatures When requesting a receipt + Start a new conversation when forwarding Check recipient email addresses before sending Use metered connections