From 9147dae4d2fe67d010164d46fcd464b5917f0b41 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 26 Apr 2021 08:15:53 +0200 Subject: [PATCH] Added options to always download headers and EML files --- app/src/main/java/eu/faircode/email/Core.java | 14 ++++++ .../email/FragmentOptionsConnection.java | 22 ++++++++ .../layout/fragment_options_connection.xml | 50 ++++++++++++++++++- app/src/main/res/values/strings.xml | 3 ++ 4 files changed, 87 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 827957727c..4daafd0cab 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -3055,6 +3055,7 @@ class Core { List rules, State state, SyncStats stats) throws MessagingException, IOException { DB db = DB.getInstance(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + boolean download_headers = prefs.getBoolean("download_headers", false); boolean notify_known = prefs.getBoolean("notify_known", false); boolean perform_expunge = prefs.getBoolean("perform_expunge", true); boolean pro = ActivityBilling.isPro(context); @@ -3207,6 +3208,8 @@ class Core { message.list_post = helper.getListPost(); message.unsubscribe = helper.getListUnsubscribe(); message.autocrypt = helper.getAutocrypt(); + if (download_headers) + message.headers = helper.getHeaders(); message.subject = helper.getSubject(); message.size = parts.getBodySize(); message.total = helper.getSize(); @@ -3706,6 +3709,7 @@ class Core { long maxSize = prefs.getInt("download", MessageHelper.DEFAULT_DOWNLOAD_SIZE); if (maxSize == 0) maxSize = Long.MAX_VALUE; + boolean download_eml = prefs.getBoolean("download_eml", false); List attachments = db.attachment().getAttachments(message.id); @@ -3786,6 +3790,16 @@ class Core { } } + if (download_eml && + (state.getNetworkState().isUnmetered() || (message.total != null && message.total < maxSize))) { + File file = message.getRawFile(context); + try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) { + imessage.writeTo(os); + } + + db.message().setMessageRaw(message.id, true); + } + return fetch; } diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsConnection.java b/app/src/main/java/eu/faircode/email/FragmentOptionsConnection.java index 9ca32395d7..209248018a 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsConnection.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsConnection.java @@ -59,6 +59,8 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre private Spinner spDownload; private SwitchCompat swRoaming; private SwitchCompat swRlah; + private SwitchCompat swDownloadHeaders; + private SwitchCompat swDownloadEml; private SwitchCompat swValidated; private EditText etTimeout; private SwitchCompat swPreferIp4; @@ -75,6 +77,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre private final static String[] RESET_OPTIONS = new String[]{ "metered", "download", "roaming", "rlah", + "download_headers", "download_eml", "require_validated", "timeout", "prefer_ip4", "standalone_vpn", "tcp_keep_alive", "ssl_harden" }; @@ -92,6 +95,8 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre spDownload = view.findViewById(R.id.spDownload); swRoaming = view.findViewById(R.id.swRoaming); swRlah = view.findViewById(R.id.swRlah); + swDownloadHeaders = view.findViewById(R.id.swDownloadHeaders); + swDownloadEml = view.findViewById(R.id.swDownloadEml); swValidated = view.findViewById(R.id.swValidated); etTimeout = view.findViewById(R.id.etTimeout); swPreferIp4 = view.findViewById(R.id.swPreferIp4); @@ -148,6 +153,20 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre } }); + swDownloadHeaders.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("download_headers", checked).apply(); + } + }); + + swDownloadEml.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("download_eml", checked).apply(); + } + }); + grpValidated.setVisibility(Build.VERSION.SDK_INT < Build.VERSION_CODES.M ? View.GONE : View.VISIBLE); swValidated.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override @@ -313,6 +332,9 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre swRoaming.setChecked(prefs.getBoolean("roaming", true)); swRlah.setChecked(prefs.getBoolean("rlah", true)); + swDownloadHeaders.setChecked(prefs.getBoolean("download_headers", false)); + swDownloadEml.setChecked(prefs.getBoolean("download_eml", false)); + swValidated.setChecked(prefs.getBoolean("require_validated", false)); int timeout = prefs.getInt("timeout", 0); diff --git a/app/src/main/res/layout/fragment_options_connection.xml b/app/src/main/res/layout/fragment_options_connection.xml index 5e16b0b8fd..a6f98e7983 100644 --- a/app/src/main/res/layout/fragment_options_connection.xml +++ b/app/src/main/res/layout/fragment_options_connection.xml @@ -161,7 +161,53 @@ android:textAppearance="@style/TextAppearance.AppCompat.Large" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@id/tvRlahHint" /> + app:layout_constraintTop_toBottomOf="@id/swRlah" /> + + + + + + + + Automatically download messages and attachments on a metered connection up to Download messages and attachments while roaming Roam like at home + Download all message headers + Download raw message files Require a validated (checked) connection Connection timeout (seconds) Prefer IPv4 over IPv6 @@ -595,6 +597,7 @@ Metered connections are generally mobile connections or paid Wi-Fi hotspots Disabling this option will disable receiving and sending messages on mobile internet connections Assuming no roaming within the EU + This will increase battery, data and storage space usage Enabling this can cause connection problems on some devices This can result in not synchronizing messages, for example when using a VPN, but also in other situations The read/write timeout will be set to the double of the connection timeout. Higher values will result in more battery use.