mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-06 17:13:23 +02:00
Added option for Usenet signatures
This commit is contained in:
@@ -110,6 +110,7 @@ import com.google.android.material.bottomnavigation.LabelVisibilityMode;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.openintents.openpgp.OpenPgpError;
|
||||
import org.openintents.openpgp.util.OpenPgpApi;
|
||||
@@ -2226,10 +2227,39 @@ public class FragmentCompose extends FragmentBase {
|
||||
!"editasnew".equals(action) &&
|
||||
!"list".equals(action) &&
|
||||
!"receipt".equals(action)) {
|
||||
String refText = Helper.readText(ref.getFile(context));
|
||||
|
||||
boolean usenet = prefs.getBoolean("usenet_signature", false);
|
||||
if (usenet) {
|
||||
Document rdoc = Jsoup.parse(refText);
|
||||
|
||||
Element signature = null;
|
||||
for (Element e : rdoc.select("*"))
|
||||
if ("-- ".equals(e.wholeText()))
|
||||
signature = e;
|
||||
|
||||
if (signature != null) {
|
||||
List<Element> tbd = new ArrayList<>();
|
||||
tbd.add(signature);
|
||||
|
||||
Element next = signature.nextElementSibling();
|
||||
while (next != null) {
|
||||
tbd.add(0, next);
|
||||
next = next.nextElementSibling();
|
||||
}
|
||||
|
||||
for (Element e : tbd)
|
||||
e.remove();
|
||||
|
||||
if (rdoc.body() != null)
|
||||
refText = rdoc.body().html();
|
||||
}
|
||||
}
|
||||
|
||||
String refBody = String.format("<p>%s %s:</p>\n<blockquote>%s</blockquote>",
|
||||
Html.escapeHtml(new Date(ref.received).toString()),
|
||||
Html.escapeHtml(MessageHelper.formatAddresses(ref.from)),
|
||||
Helper.readText(ref.getFile(context)));
|
||||
refText);
|
||||
Helper.writeText(draft.getRefFile(context), refBody);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
|
||||
private SwitchCompat swKeyboard;
|
||||
private SwitchCompat swPrefixOnce;
|
||||
private SwitchCompat swPlainOnly;
|
||||
private SwitchCompat swUsenetSignature;
|
||||
private SwitchCompat swAutoResize;
|
||||
private Spinner spAutoResize;
|
||||
private TextView tvAutoResize;
|
||||
@@ -50,7 +51,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
|
||||
private Spinner spSendDelayed;
|
||||
|
||||
private final static String[] RESET_OPTIONS = new String[]{
|
||||
"keyboard", "prefix_once", "plain_only", "autoresize", "resize", "lookup_mx", "autosend", "send_delayed"
|
||||
"keyboard", "prefix_once", "plain_only", "usenet_signature", "autoresize", "resize", "lookup_mx", "autosend", "send_delayed"
|
||||
};
|
||||
|
||||
@Override
|
||||
@@ -66,6 +67,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
|
||||
swKeyboard = view.findViewById(R.id.swKeyboard);
|
||||
swPrefixOnce = view.findViewById(R.id.swPrefixOnce);
|
||||
swPlainOnly = view.findViewById(R.id.swPlainOnly);
|
||||
swUsenetSignature = view.findViewById(R.id.swUsenetSignature);
|
||||
swAutoResize = view.findViewById(R.id.swAutoResize);
|
||||
spAutoResize = view.findViewById(R.id.spAutoResize);
|
||||
tvAutoResize = view.findViewById(R.id.tvAutoResize);
|
||||
@@ -100,6 +102,13 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
|
||||
}
|
||||
});
|
||||
|
||||
swUsenetSignature.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
prefs.edit().putBoolean("usenet_signature", checked).apply();
|
||||
}
|
||||
});
|
||||
|
||||
swAutoResize.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
@@ -197,6 +206,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
|
||||
swKeyboard.setChecked(prefs.getBoolean("keyboard", true));
|
||||
swPrefixOnce.setChecked(prefs.getBoolean("prefix_once", true));
|
||||
swPlainOnly.setChecked(prefs.getBoolean("plain_only", false));
|
||||
swUsenetSignature.setChecked(prefs.getBoolean("usenet_signature", false));
|
||||
|
||||
swAutoResize.setChecked(prefs.getBoolean("autoresize", true));
|
||||
|
||||
|
||||
@@ -20,10 +20,13 @@ package eu.faircode.email;
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.MailTo;
|
||||
import android.text.TextUtils;
|
||||
import android.webkit.MimeTypeMap;
|
||||
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.sun.mail.util.FolderClosedIOException;
|
||||
import com.sun.mail.util.MessageRemovedIOException;
|
||||
|
||||
@@ -213,6 +216,9 @@ public class MessageHelper {
|
||||
}
|
||||
|
||||
static void build(Context context, EntityMessage message, List<EntityAttachment> attachments, EntityIdentity identity, MimeMessage imessage) throws IOException, MessagingException {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean usenet = prefs.getBoolean("usenet_signature", false);
|
||||
|
||||
if (message.receipt_request != null && message.receipt_request) {
|
||||
// https://www.ietf.org/rfc/rfc3798.txt
|
||||
Multipart report = new MimeMultipart("report; report-type=disposition-notification");
|
||||
@@ -249,8 +255,11 @@ public class MessageHelper {
|
||||
if (identity != null) {
|
||||
if (!TextUtils.isEmpty(identity.signature)) {
|
||||
Document sdoc = Jsoup.parse(identity.signature);
|
||||
if (sdoc.body() != null)
|
||||
if (sdoc.body() != null) {
|
||||
if (usenet) // https://www.ietf.org/rfc/rfc3676.txt
|
||||
body.append("<span>-- <br></span>");
|
||||
body.append(sdoc.body().html());
|
||||
}
|
||||
}
|
||||
|
||||
File refFile = message.getRefFile(context);
|
||||
|
||||
Reference in New Issue
Block a user