From ba24ebd0f3f135c9b5614c1af80e52b59e6c4468 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 15 Aug 2024 16:47:12 +0200 Subject: [PATCH] Added reply header template --- .../java/eu/faircode/email/EntityMessage.java | 12 +++++- .../faircode/email/FragmentOptionsSend.java | 36 +++++++++++++++- .../main/res/layout/fragment_options_send.xml | 42 ++++++++++++++++++- app/src/main/res/values/strings.xml | 2 + 4 files changed, 89 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/EntityMessage.java b/app/src/main/java/eu/faircode/email/EntityMessage.java index 41d18b30ee..7ef9b676f7 100644 --- a/app/src/main/java/eu/faircode/email/EntityMessage.java +++ b/app/src/main/java/eu/faircode/email/EntityMessage.java @@ -557,6 +557,7 @@ public class EntityMessage implements Serializable { Element getReplyHeader(Context context, Document document, boolean separate, boolean extended) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean hide_timezone = prefs.getBoolean("hide_timezone", false); + String template_reply = prefs.getString("template_reply", null); boolean language_detection = prefs.getBoolean("language_detection", false); String compose_font = prefs.getString("compose_font", ""); String l = (language_detection ? language : null); @@ -604,8 +605,17 @@ public class EntityMessage implements Serializable { p.appendText(subject); p.appendElement("br"); } - } else + } else if (TextUtils.isEmpty(template_reply)) p.text(date + " " + MessageHelper.formatAddresses(from) + ":"); + else { + template_reply = template_reply.replace("$from$", MessageHelper.formatAddresses(from)); + template_reply = template_reply.replace("$to$", MessageHelper.formatAddresses(to)); + template_reply = template_reply.replace("$cc$", MessageHelper.formatAddresses(cc)); + template_reply = template_reply.replace("$time$", date); + template_reply = template_reply.replace("$subject$", subject); + p.html(template_reply); + } + Element div = document.createElement("div") .attr("fairemail", "reply"); diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java b/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java index 1cc2be8f65..9dd86cbf4f 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java @@ -32,6 +32,7 @@ import android.os.Bundle; import android.text.Editable; import android.text.SpannableStringBuilder; import android.text.Spanned; +import android.text.TextUtils; import android.text.TextWatcher; import android.view.LayoutInflater; import android.view.Menu; @@ -48,6 +49,7 @@ import android.widget.ImageButton; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.Spinner; +import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -102,6 +104,8 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc private RadioGroup rgFwd; private SwitchCompat swSeparateReply; private SwitchCompat swExtendedReply; + private EditText etTemplateReply; + private TextView tvTemplateReplyHint; private SwitchCompat swWriteBelow; private SwitchCompat swQuoteReply; private SwitchCompat swQuoteLimit; @@ -143,7 +147,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc "sound_sent", "compose_color", "compose_font", "compose_monospaced", "prefix_once", "prefix_count", "alt_re", "alt_fwd", - "separate_reply", "extended_reply", "write_below", "quote_reply", "quote_limit", + "separate_reply", "extended_reply", "template_reply", "write_below", "quote_reply", "quote_limit", "resize_reply", "resize_paste", "signature_location", "signature_new", "signature_reply", "signature_reply_once", "signature_forward", "send_at_top", "attach_new", "auto_link", "plain_only", "plain_only_reply", @@ -198,6 +202,8 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc rgFwd = view.findViewById(R.id.rgFwd); swSeparateReply = view.findViewById(R.id.swSeparateReply); swExtendedReply = view.findViewById(R.id.swExtendedReply); + etTemplateReply = view.findViewById(R.id.etTemplateReply); + tvTemplateReplyHint = view.findViewById(R.id.tvTemplateReplyHint); swWriteBelow = view.findViewById(R.id.swWriteBelow); swQuoteReply = view.findViewById(R.id.swQuoteReply); swQuoteLimit = view.findViewById(R.id.swQuoteLimit); @@ -603,9 +609,33 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { prefs.edit().putBoolean("extended_reply", checked).apply(); + etTemplateReply.setEnabled(!checked); } }); + etTemplateReply.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + // Do nothing + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + // Do nothing + } + + @Override + public void afterTextChanged(Editable s) { + String template = s.toString(); + if (TextUtils.isEmpty(template.trim())) + prefs.edit().remove("template_reply").apply(); + else + prefs.edit().putString("template_reply", template).apply(); + } + }); + + tvTemplateReplyHint.setText(getString(R.string.title_advanced_template_reply_hint, "$from$ $to$ $cc$ $time$ $subject$")); + swWriteBelow.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -863,6 +893,8 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { if (!RESET_OPTIONS.contains(key)) return; + if ("template_reply".equals(key)) + return; if ("purge_contact_age".equals(key) || "purge_contact_freq".equals(key)) return; if ("send_retry_max".equals(key)) @@ -973,6 +1005,8 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc swSeparateReply.setChecked(prefs.getBoolean("separate_reply", false)); swExtendedReply.setChecked(prefs.getBoolean("extended_reply", false)); + etTemplateReply.setText(prefs.getString("template_reply", null)); + etTemplateReply.setEnabled(!swExtendedReply.isChecked()); swWriteBelow.setChecked(prefs.getBoolean("write_below", false)); swQuoteReply.setChecked(prefs.getBoolean("quote_reply", true)); swQuoteLimit.setChecked(prefs.getBoolean("quote_limit", true)); diff --git a/app/src/main/res/layout/fragment_options_send.xml b/app/src/main/res/layout/fragment_options_send.xml index f6899414a5..63b8f8a8e0 100644 --- a/app/src/main/res/layout/fragment_options_send.xml +++ b/app/src/main/res/layout/fragment_options_send.xml @@ -694,6 +694,46 @@ app:layout_constraintTop_toBottomOf="@id/swSeparateReply" app:switchPadding="12dp" /> + + + + + + Add count to reply prefix Insert a horizontal line before a reply/forward header Use extended reply/forward header + Reply/forward header template Write above the sender\'s text Write below the sender\'s text Quote replied text @@ -1063,6 +1064,7 @@ 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 Very light or very dark colors will result in illegible messages on the recipients\' side + HTML is allowed. Available placeholders: %1$s A recipient might miss your reply, for example when a longer message is being truncated Otherwise, add shared addresses or files to the current draft message Insert \'-- \' between the text and the signature