Limit quote levels

This commit is contained in:
M66B 2020-11-14 09:36:11 +01:00
parent 39b53c0883
commit 78ee7cd42d
5 changed files with 44 additions and 13 deletions

View File

@ -277,6 +277,8 @@ public class FragmentCompose extends FragmentBase {
private static final int RECIPIENTS_WARNING = 10;
private static final int MAX_QUOTE_LEVEL = 5;
private static final int REQUEST_CONTACT_TO = 1;
private static final int REQUEST_CONTACT_CC = 2;
private static final int REQUEST_CONTACT_BCC = 3;
@ -3825,6 +3827,21 @@ public class FragmentCompose extends FragmentBase {
Element e = d.body();
// Limit number of nested block quotes
boolean quote_limit = prefs.getBoolean("quote_limit", true);
if (quote_limit)
for (Element bq : e.select("blockquote")) {
int level = 1;
Element parent = bq.parent();
while (parent != null) {
if ("blockquote".equals(parent.tagName()))
level++;
parent = parent.parent();
}
if (level >= MAX_QUOTE_LEVEL)
bq.html("…");
}
// Apply styles
List<CSSStyleSheet> sheets = HtmlHelper.parseStyles(d.head().select("style"));
for (Element element : e.select("*")) {

View File

@ -55,6 +55,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
private SwitchCompat swSeparateReply;
private SwitchCompat swExtendedReply;
private SwitchCompat swQuoteReply;
private SwitchCompat swQuoteLimit;
private SwitchCompat swResizeReply;
private Spinner spSignatureLocation;
private SwitchCompat swSignatureReply;
@ -72,7 +73,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
private final static String[] RESET_OPTIONS = new String[]{
"keyboard", "suggest_sent", "suggested_received", "suggest_frequently",
"send_reminders", "send_delayed",
"compose_font", "prefix_once", "separate_reply", "extended_reply", "quote_reply", "resize_reply",
"compose_font", "prefix_once", "separate_reply", "extended_reply", "quote_reply", "quote_limit", "resize_reply",
"signature_location", "signature_reply", "signature_forward",
"discard_delete",
"plain_only", "format_flowed", "usenet_signature", "remove_signatures",
@ -102,6 +103,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
swSeparateReply = view.findViewById(R.id.swSeparateReply);
swExtendedReply = view.findViewById(R.id.swExtendedReply);
swQuoteReply = view.findViewById(R.id.swQuoteReply);
swQuoteLimit = view.findViewById(R.id.swQuoteLimit);
swResizeReply = view.findViewById(R.id.swResizeReply);
spSignatureLocation = view.findViewById(R.id.spSignatureLocation);
swSignatureReply = view.findViewById(R.id.swSignatureReply);
@ -230,6 +232,14 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("quote_reply", checked).apply();
swQuoteLimit.setEnabled(checked);
}
});
swQuoteLimit.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("quote_limit", checked).apply();
}
});
@ -401,6 +411,8 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
swSeparateReply.setChecked(prefs.getBoolean("separate_reply", false));
swExtendedReply.setChecked(prefs.getBoolean("extended_reply", false));
swQuoteReply.setChecked(prefs.getBoolean("quote_reply", true));
swQuoteLimit.setChecked(prefs.getBoolean("quote_limit", true));
swQuoteLimit.setEnabled(swQuoteReply.isChecked());
swResizeReply.setChecked(prefs.getBoolean("resize_reply", true));
int signature_location = prefs.getInt("signature_location", 1);

View File

@ -570,9 +570,6 @@ public class MessageHelper {
// Build html body
Document document = JsoupEx.parse(message.getFile(context));
Element ref = null;
if (BuildConfig.DEBUG)
ref = document.select("div[fairemail=reference]").first();
// When sending message
if (identity != null && send) {
@ -656,14 +653,6 @@ public class MessageHelper {
String htmlContent = document.html();
String htmlContentType = "text/html; charset=" + Charset.defaultCharset().name();
// Limit alternative plain content
if (ref != null &&
(message.plain_only == null || !message.plain_only)) {
Element first = ref.select("blockquote").first();
if (first != null)
first.children().select("blockquote").remove();
}
String plainContent = HtmlHelper.getText(context, document.html());
String plainContentType = "text/plain; charset=" + Charset.defaultCharset().name();

View File

@ -237,6 +237,18 @@
app:layout_constraintTop_toBottomOf="@id/swExtendedReply"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swQuoteLimit"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:checked="true"
android:text="@string/title_advanced_limit_reply"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swQuoteReply"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swResizeReply"
android:layout_width="0dp"
@ -246,7 +258,7 @@
android:text="@string/title_advanced_resize_reply"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swQuoteReply"
app:layout_constraintTop_toBottomOf="@id/swQuoteLimit"
app:switchPadding="12dp" />
<eu.faircode.email.FixedTextView

View File

@ -311,6 +311,7 @@
<string name="title_advanced_separate_reply">Insert a horizontal line before a reply/forward header</string>
<string name="title_advanced_extended_reply">Use extended reply/forward header</string>
<string name="title_advanced_quote_reply">Quote replied text</string>
<string name="title_advanced_limit_reply">Limit the number of nested quotes</string>
<string name="title_advanced_resize_reply">Resize images in replied text</string>
<string name="title_advanced_signature_location">Signature position</string>
<string name="title_advanced_signature_reply">Use signature when replying</string>