Added reply header to answer rule

This commit is contained in:
M66B 2020-08-07 10:40:24 +02:00
parent 18ef903971
commit a8a3289f74
3 changed files with 69 additions and 55 deletions

View File

@ -23,16 +23,23 @@ import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager;
import androidx.room.Entity;
import androidx.room.ForeignKey;
import androidx.room.Index;
import androidx.room.PrimaryKey;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import java.io.File;
import java.io.Serializable;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
@ -252,6 +259,61 @@ public class EntityMessage implements Serializable {
return false;
}
Element getReplyHeader(Context context, Document document, boolean extended) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean language_detection = prefs.getBoolean("language_detection", false);
String l = (language_detection ? language : null);
DateFormat DF;
if (l == null)
DF = Helper.getDateTimeInstance(context);
else
DF = SimpleDateFormat.getDateTimeInstance(
SimpleDateFormat.MEDIUM, SimpleDateFormat.MEDIUM, new Locale(l));
Element p = document.createElement("p");
if (extended) {
if (from != null && from.length > 0) {
Element strong = document.createElement("strong");
strong.text(Helper.getString(context, l, R.string.title_from) + " ");
p.appendChild(strong);
p.appendText(MessageHelper.formatAddresses(from));
p.appendElement("br");
}
if (to != null && to.length > 0) {
Element strong = document.createElement("strong");
strong.text(Helper.getString(context, l, R.string.title_to) + " ");
p.appendChild(strong);
p.appendText(MessageHelper.formatAddresses(to));
p.appendElement("br");
}
if (cc != null && cc.length > 0) {
Element strong = document.createElement("strong");
strong.text(Helper.getString(context, l, R.string.title_cc) + " ");
p.appendChild(strong);
p.appendText(MessageHelper.formatAddresses(cc));
p.appendElement("br");
}
{
Element strong = document.createElement("strong");
strong.text(Helper.getString(context, l, R.string.title_received) + " ");
p.appendChild(strong);
p.appendText(DF.format(received));
p.appendElement("br");
}
{
Element strong = document.createElement("strong");
strong.text(Helper.getString(context, l, R.string.title_subject) + " ");
p.appendChild(strong);
p.appendText(subject == null ? "" : subject);
p.appendElement("br");
}
} else
p.text(DF.format(new Date(received)) + " " + MessageHelper.formatAddresses(from) + ":");
return p;
}
String getNotificationChannelId() {
if (from == null || from.length == 0)
return null;

View File

@ -465,18 +465,20 @@ public class EntityRule {
reply.id = db.message().insertMessage(reply);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean extended_reply = prefs.getBoolean("extended_reply", false);
boolean quote_reply = prefs.getBoolean("quote_reply", true);
String body = answer.getText(message.from);
Document msg = JsoupEx.parse(body);
Element div = msg.createElement("div");
Element p = msg.createElement("p");
DateFormat DF = Helper.getDateTimeInstance(context);
p.text(DF.format(new Date(message.received)) + " " + MessageHelper.formatAddresses(message.from) + ":");
Element p = message.getReplyHeader(context, msg, extended_reply);
div.appendChild(p);
Document answering = JsoupEx.parse(message.getFile(context));
div.appendChild(answering.body().tagName("blockquote"));
div.appendChild(answering.body().tagName(quote_reply ? "blockquote" : "p"));
msg.body().appendChild(div);

View File

@ -3455,59 +3455,9 @@ public class FragmentCompose extends FragmentBase {
Element reply = document.createElement("div");
reply.attr("fairemail", "reference");
boolean language_detection = prefs.getBoolean("language_detection", false);
String language = (language_detection ? ref.language : null);
DateFormat DF;
if (language == null)
DF = Helper.getDateTimeInstance(context);
else
DF = SimpleDateFormat.getDateTimeInstance(
SimpleDateFormat.MEDIUM, SimpleDateFormat.MEDIUM,
new Locale(language));
// Build reply header
Element p = document.createElement("p");
boolean extended_reply = prefs.getBoolean("extended_reply", false);
if (extended_reply) {
if (ref.from != null && ref.from.length > 0) {
Element strong = document.createElement("strong");
strong.text(Helper.getString(context, language, R.string.title_from) + " ");
p.appendChild(strong);
p.appendText(MessageHelper.formatAddresses(ref.from));
p.appendElement("br");
}
if (ref.to != null && ref.to.length > 0) {
Element strong = document.createElement("strong");
strong.text(Helper.getString(context, language, R.string.title_to) + " ");
p.appendChild(strong);
p.appendText(MessageHelper.formatAddresses(ref.to));
p.appendElement("br");
}
if (ref.cc != null && ref.cc.length > 0) {
Element strong = document.createElement("strong");
strong.text(Helper.getString(context, language, R.string.title_cc) + " ");
p.appendChild(strong);
p.appendText(MessageHelper.formatAddresses(ref.cc));
p.appendElement("br");
}
{
Element strong = document.createElement("strong");
strong.text(Helper.getString(context, language, R.string.title_received) + " ");
p.appendChild(strong);
p.appendText(DF.format(ref.received));
p.appendElement("br");
}
{
Element strong = document.createElement("strong");
strong.text(Helper.getString(context, language, R.string.title_subject) + " ");
p.appendChild(strong);
p.appendText(ref.subject == null ? "" : ref.subject);
p.appendElement("br");
}
} else
p.text(DF.format(new Date(ref.received)) + " " + MessageHelper.formatAddresses(ref.from) + ":");
Element p = ref.getReplyHeader(context, document, extended_reply);
reply.appendChild(p);
Document d;