From 09b8f1a37fe3fed7cd22650183a789b50ab28274 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 3 Apr 2021 12:52:22 +0200 Subject: [PATCH] Added option to auto store sent messages in user folders --- .../faircode/email/FragmentOptionsSend.java | 12 +++++++++- .../java/eu/faircode/email/ServiceSend.java | 19 ++++++++++++++- .../main/res/layout/fragment_options_send.xml | 24 ++++++++++++++++++- app/src/main/res/values/strings.xml | 2 ++ 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java b/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java index 6eb3e38a83..301cada86a 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java @@ -65,6 +65,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc private SwitchCompat swSignatureForward; private Button btnEditSignature; private SwitchCompat swDiscardDelete; + private SwitchCompat swReplyMove; private SwitchCompat swAutoLink; private SwitchCompat swPlainOnly; @@ -81,7 +82,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc "send_reminders", "send_delayed", "send_pending", "compose_font", "prefix_once", "separate_reply", "extended_reply", "write_below", "quote_reply", "quote_limit", "resize_reply", "signature_location", "signature_reply", "signature_forward", - "discard_delete", + "discard_delete", "reply_move", "auto_link", "plain_only", "format_flowed", "usenet_signature", "remove_signatures", "receipt_default", "receipt_type", "lookup_mx" }; @@ -120,6 +121,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc swSignatureForward = view.findViewById(R.id.swSignatureForward); btnEditSignature = view.findViewById(R.id.btnEditSignature); swDiscardDelete = view.findViewById(R.id.swDiscardDelete); + swReplyMove = view.findViewById(R.id.swReplyMove); swAutoLink = view.findViewById(R.id.swAutoLink); swPlainOnly = view.findViewById(R.id.swPlainOnly); @@ -330,6 +332,13 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc } }); + swReplyMove.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("reply_move", checked).apply(); + } + }); + swAutoLink.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -468,6 +477,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc swSignatureReply.setChecked(prefs.getBoolean("signature_reply", true)); swSignatureForward.setChecked(prefs.getBoolean("signature_forward", true)); swDiscardDelete.setChecked(prefs.getBoolean("discard_delete", false)); + swReplyMove.setChecked(prefs.getBoolean("reply_move", false)); swAutoLink.setChecked(prefs.getBoolean("auto_link", false)); swPlainOnly.setChecked(prefs.getBoolean("plain_only", false)); diff --git a/app/src/main/java/eu/faircode/email/ServiceSend.java b/app/src/main/java/eu/faircode/email/ServiceSend.java index 2a50b74cdf..f81b708234 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSend.java +++ b/app/src/main/java/eu/faircode/email/ServiceSend.java @@ -514,6 +514,7 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar } SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + boolean reply_move = prefs.getBoolean("reply_move", false); boolean debug = prefs.getBoolean("debug", false); if (message.identity == null) @@ -550,7 +551,23 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar // Prepare sent message Long sid = null; - EntityFolder sent = db.folder().getFolderByType(message.account, EntityFolder.SENT); + EntityFolder sent = null; + + if (reply_move && !TextUtils.isEmpty(message.inreplyto)) { + List replied = db.message().getMessagesByMsgId(message.account, message.inreplyto); + if (replied != null) + for (EntityMessage m : replied) { + EntityFolder folder = db.folder().getFolder(m.folder); + if (folder != null && EntityFolder.USER.equals(folder.type)) { + sent = folder; + break; + } + } + } + + if (sent == null) + sent = db.folder().getFolderByType(message.account, EntityFolder.SENT); + if (sent != null) { Log.i(sent.name + " Preparing sent message"); diff --git a/app/src/main/res/layout/fragment_options_send.xml b/app/src/main/res/layout/fragment_options_send.xml index 49f3837395..fb32421dee 100644 --- a/app/src/main/res/layout/fragment_options_send.xml +++ b/app/src/main/res/layout/fragment_options_send.xml @@ -402,6 +402,28 @@ app:layout_constraintTop_toBottomOf="@id/btnEditSignature" app:switchPadding="12dp" /> + + + + + app:layout_constraintTop_toBottomOf="@+id/tvReplyMoveHint" /> Use signature when replying Use signature when forwarding On discard draft permanently delete draft + On replying to a message that is not in the inbox, save the reply in the same folder Automatically create links Send plain text only by default @@ -581,6 +582,7 @@ In addition to contacts provided by Android. Contact data will be stored for newly sent or received messages only when enabled. Insert \'-- \' between the text and the signature Show a warning when the message text or the subject is empty or when an attachment might be missing + The email server could still add the messages to the sent message folder Metered connections are generally mobile connections or paid Wi-Fi hotspots Disabling this option will disable receiving and sending messages on mobile internet connections