Added option to download plain text only part by default

This commit is contained in:
M66B 2022-02-14 20:18:03 +01:00
parent 632a3912bf
commit 82ac131e39
8 changed files with 57 additions and 15 deletions

View File

@ -24,6 +24,7 @@ import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.text.Spannable;
@ -49,6 +50,7 @@ import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.cardview.widget.CardView;
import androidx.constraintlayout.widget.Group;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
@ -256,6 +258,9 @@ public class ActivityEML extends ActivityBase {
Result result = new Result();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean download_plain = prefs.getBoolean("download_plain", false);
ContentResolver resolver = context.getContentResolver();
try (InputStream is = resolver.openInputStream(uri)) {
@ -275,7 +280,7 @@ public class ActivityEML extends ActivityBase {
result.subject = helper.getSubject();
result.parts = helper.getMessageParts(false);
String html = result.parts.getHtml(context);
String html = result.parts.getHtml(context, download_plain);
if (html != null) {
Document parsed = JsoupEx.parse(html);
HtmlHelper.autoLink(parsed);

View File

@ -2568,6 +2568,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
final boolean show_quotes = args.getBoolean("show_quotes");
final int zoom = args.getInt("zoom");
final float scale = args.getFloat("scale");
final boolean download_plain = prefs.getBoolean("download_plain", false);
if (message == null || !message.content)
return null;
@ -2613,7 +2614,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
embedded.received = helper.getSent();
embedded.subject = helper.getSubject();
String html = parts.getHtml(context);
String html = parts.getHtml(context, download_plain);
Document d = (html == null ? Document.createShell("") : JsoupEx.parse(html));
Element div = document.createElement("div");

View File

@ -2674,6 +2674,7 @@ class Core {
boolean sync_quick_pop = prefs.getBoolean("sync_quick_pop", true);
boolean notify_known = prefs.getBoolean("notify_known", false);
boolean download_eml = prefs.getBoolean("download_eml", false);
boolean download_plain = prefs.getBoolean("download_plain", false);
boolean pro = ActivityBilling.isPro(context);
boolean force = jargs.optBoolean(5, false);
@ -2963,7 +2964,7 @@ class Core {
boolean needsHeaders = EntityRule.needsHeaders(message, rules);
List<Header> headers = (needsHeaders ? helper.getAllHeaders() : null);
String body = parts.getHtml(context);
String body = parts.getHtml(context, download_plain);
try {
db.beginTransaction();
@ -2999,7 +3000,7 @@ class Core {
db.message().setMessageContent(message.id,
true,
message.language,
parts.isPlainOnly(),
parts.isPlainOnly(download_plain),
message.preview,
parts.getWarnings(message.warning));
@ -3720,6 +3721,7 @@ class Core {
DB db = DB.getInstance(context);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean download_headers = prefs.getBoolean("download_headers", false);
boolean download_plain = prefs.getBoolean("download_plain", false);
boolean notify_known = prefs.getBoolean("notify_known", false);
boolean experiments = prefs.getBoolean("experiments", false);
boolean pro = ActivityBilling.isPro(context);
@ -4030,7 +4032,7 @@ class Core {
if (needsHeaders || needsBody)
Log.i(folder.name + " needs headers=" + needsHeaders + " body=" + needsBody);
List<Header> headers = (needsHeaders ? helper.getAllHeaders() : null);
String body = (needsBody ? parts.getHtml(context) : null);
String body = (needsBody ? parts.getHtml(context, download_plain) : null);
if (experiments && helper.isReport())
try {
@ -4124,7 +4126,7 @@ class Core {
EntityContact.received(context, account, folder, message);
if (body == null && helper.isReport())
body = parts.getHtml(context);
body = parts.getHtml(context, download_plain);
// Download small messages inline
if (body != null || (download && !message.ui_hide)) {
@ -4142,7 +4144,7 @@ class Core {
(MessageClassifier.isEnabled(context)) && folder.auto_classify_source)
try {
if (body == null)
body = parts.getHtml(context);
body = parts.getHtml(context, download_plain);
File file = message.getFile(context);
Helper.writeText(file, body);
String text = HtmlHelper.getFullText(body);
@ -4151,7 +4153,7 @@ class Core {
db.message().setMessageContent(message.id,
true,
message.language,
parts.isPlainOnly(),
parts.isPlainOnly(download_plain),
message.preview,
parts.getWarnings(message.warning));
MessageClassifier.classify(message, folder, null, context);
@ -4297,7 +4299,7 @@ class Core {
if (needsHeaders || needsBody)
Log.i(folder.name + " needs headers=" + needsHeaders + " body=" + needsBody);
List<Header> headers = (needsHeaders ? helper.getAllHeaders() : null);
String body = (needsBody ? helper.getMessageParts().getHtml(context) : null);
String body = (needsBody ? helper.getMessageParts().getHtml(context, download_plain) : null);
try {
db.beginTransaction();

View File

@ -7368,7 +7368,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
String protect_subject = parts.getProtectedSubject();
// Write decrypted body
String html = parts.getHtml(context);
boolean download_plain = prefs.getBoolean("download_plain", false);
String html = parts.getHtml(context, download_plain);
Helper.writeText(message.getFile(context), html);
Log.i("pgp html=" + (html == null ? null : html.length()));
@ -7385,7 +7386,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.message().setMessageContent(message.id,
true,
message.language,
parts.isPlainOnly(),
parts.isPlainOnly(download_plain),
message.preview,
message.warning);
@ -8076,7 +8077,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
MessageHelper.MessageParts parts = helper.getMessageParts();
// Write decrypted body
String html = parts.getHtml(context);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean download_plain = prefs.getBoolean("download_plain", false);
String html = parts.getHtml(context, download_plain);
Helper.writeText(message.getFile(context), html);
Log.i("s/mime html=" + (html == null ? null : html.length()));
@ -8091,7 +8094,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.message().setMessageContent(message.id,
true,
message.language,
parts.isPlainOnly(),
parts.isPlainOnly(download_plain),
message.preview,
message.warning);

View File

@ -62,6 +62,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
private SwitchCompat swRlah;
private SwitchCompat swDownloadHeaders;
private SwitchCompat swDownloadEml;
private SwitchCompat swDownloadPlain;
private SwitchCompat swValidated;
private SwitchCompat swVpnOnly;
private EditText etTimeout;
@ -82,7 +83,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
private final static String[] RESET_OPTIONS = new String[]{
"metered", "download", "roaming", "rlah",
"download_headers", "download_eml",
"download_headers", "download_eml", "download_plain",
"require_validated", "vpn_only",
"timeout", "prefer_ip4", "bind_socket", "standalone_vpn", "tcp_keep_alive",
"ssl_harden", "cert_strict"
@ -104,6 +105,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
swRlah = view.findViewById(R.id.swRlah);
swDownloadHeaders = view.findViewById(R.id.swDownloadHeaders);
swDownloadEml = view.findViewById(R.id.swDownloadEml);
swDownloadPlain = view.findViewById(R.id.swDownloadPlain);
swValidated = view.findViewById(R.id.swValidated);
swVpnOnly = view.findViewById(R.id.swVpnOnly);
etTimeout = view.findViewById(R.id.etTimeout);
@ -179,6 +181,13 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
}
});
swDownloadPlain.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
prefs.edit().putBoolean("download_plain", checked).apply();
}
});
grpValidated.setVisibility(Build.VERSION.SDK_INT < Build.VERSION_CODES.M ? View.GONE : View.VISIBLE);
swValidated.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
@ -371,6 +380,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
swDownloadHeaders.setChecked(prefs.getBoolean("download_headers", false));
swDownloadEml.setChecked(prefs.getBoolean("download_eml", false));
swDownloadPlain.setChecked(prefs.getBoolean("download_plain", false));
swValidated.setChecked(prefs.getBoolean("require_validated", false));
swVpnOnly.setChecked(prefs.getBoolean("vpn_only", false));

View File

@ -2782,6 +2782,15 @@ public class MessageHelper {
return protected_subject;
}
Integer isPlainOnly(boolean download_plain) {
Integer plain = isPlainOnly();
if (plain == null)
return null;
if (download_plain && plain == 0x80)
plain |= 1;
return plain;
}
Integer isPlainOnly() {
int html = 0;
int plain = 0;

View File

@ -248,6 +248,17 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swDownloadEml" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swDownloadPlain"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_download_plain"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvDownloadEmlHint"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swValidated"
android:layout_width="0dp"
@ -256,7 +267,7 @@
android:text="@string/title_advanced_validated"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvDownloadEmlHint"
app:layout_constraintTop_toBottomOf="@id/swDownloadPlain"
app:switchPadding="12dp" />
<eu.faircode.email.FixedTextView

View File

@ -412,6 +412,7 @@
<string name="title_advanced_rlah">Roam like at home</string>
<string name="title_advanced_download_headers">Download all message headers</string>
<string name="title_advanced_download_eml">Download raw message files</string>
<string name="title_advanced_download_plain">Download plain text only parts by default (if available)</string>
<string name="title_advanced_validated">Require a validated (checked) connection</string>
<string name="title_advanced_vpn_only">Connect only via a VPN</string>
<string name="title_advanced_timeout">Connection timeout (seconds)</string>