From a040f386211f23dd4524b3ca16815502e9ca2caf Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 22 Oct 2022 14:50:39 +0200 Subject: [PATCH] Experiment: fast fetch --- app/src/main/java/eu/faircode/email/Core.java | 31 +++++++++++++++++-- .../faircode/email/FragmentOptionsMisc.java | 12 ++++++- .../main/res/layout/fragment_options_misc.xml | 13 +++++++- app/src/main/res/values/strings.xml | 1 + 4 files changed, 52 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index e620e2cd55..87904f79cc 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -1762,8 +1762,32 @@ class Core { Log.e(ex1); } - if (download) - downloadMessage(context, account, folder, istore, ifolder, imessage, message.id, state, stats); + if (download) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + boolean fast_fetch = prefs.getBoolean("fast_fetch", false); + if (fast_fetch) { + long maxSize = prefs.getInt("download", MessageHelper.DEFAULT_DOWNLOAD_SIZE); + if (maxSize == 0) + maxSize = Long.MAX_VALUE; + boolean download_eml = prefs.getBoolean("download_eml", false); + + if (!message.content) + if (state.getNetworkState().isUnmetered() || (message.size != null && message.size < maxSize)) + EntityOperation.queue(context, message, EntityOperation.BODY); + + List attachments = db.attachment().getAttachments(message.id); + for (EntityAttachment attachment : attachments) + if (!attachment.available) + if (state.getNetworkState().isUnmetered() || (attachment.size != null && attachment.size < maxSize)) + EntityOperation.queue(context, message, EntityOperation.ATTACHMENT, attachment.id); + + if (download_eml && + (message.raw == null || !message.raw) && + (state.getNetworkState().isUnmetered() || (message.total != null && message.total < maxSize))) + EntityOperation.queue(context, message, EntityOperation.RAW); + } else + downloadMessage(context, account, folder, istore, ifolder, imessage, message.id, state, stats); + } } if (!stats.isEmpty()) @@ -4479,10 +4503,11 @@ class Core { File file = message.getFile(context); Helper.writeText(file, body); String text = HtmlHelper.getFullText(body); + message.content = true; message.preview = HtmlHelper.getPreview(text); message.language = HtmlHelper.getLanguage(context, message.subject, text); db.message().setMessageContent(message.id, - true, + message.content, message.language, parts.isPlainOnly(download_plain), message.preview, diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java index 34caa376fb..5431783a03 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java @@ -203,6 +203,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc private SwitchCompat swKeepAlivePoll; private SwitchCompat swEmptyPool; private SwitchCompat swIdleDone; + private SwitchCompat swFastFetch; private SwitchCompat swLogarithmicBackoff; private SwitchCompat swExactAlarms; private SwitchCompat swInfra; @@ -260,7 +261,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc "show_recent", "use_modseq", "uid_command", "perform_expunge", "uid_expunge", "auth_plain", "auth_login", "auth_ntlm", "auth_sasl", "auth_apop", "use_top", - "keep_alive_poll", "empty_pool", "idle_done", "logarithmic_backoff", + "keep_alive_poll", "empty_pool", "idle_done", "fast_fetch", "logarithmic_backoff", "exact_alarms", "infra", "dkim_verify", "dup_msgids", "global_keywords", "test_iab" }; @@ -414,6 +415,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc swKeepAlivePoll = view.findViewById(R.id.swKeepAlivePoll); swEmptyPool = view.findViewById(R.id.swEmptyPool); swIdleDone = view.findViewById(R.id.swIdleDone); + swFastFetch = view.findViewById(R.id.swFastFetch); swLogarithmicBackoff = view.findViewById(R.id.swLogarithmicBackoff); swExactAlarms = view.findViewById(R.id.swExactAlarms); swInfra = view.findViewById(R.id.swInfra); @@ -1412,6 +1414,13 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc } }); + swFastFetch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("fast_fetch", checked).apply(); + } + }); + swLogarithmicBackoff.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -2124,6 +2133,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc swKeepAlivePoll.setChecked(prefs.getBoolean("keep_alive_poll", false)); swEmptyPool.setChecked(prefs.getBoolean("empty_pool", true)); swIdleDone.setChecked(prefs.getBoolean("idle_done", true)); + swFastFetch.setChecked(prefs.getBoolean("fast_fetch", false)); swLogarithmicBackoff.setChecked(prefs.getBoolean("logarithmic_backoff", true)); swExactAlarms.setChecked(prefs.getBoolean("exact_alarms", true)); swInfra.setChecked(prefs.getBoolean("infra", false)); diff --git a/app/src/main/res/layout/fragment_options_misc.xml b/app/src/main/res/layout/fragment_options_misc.xml index 9b60d89742..97ac8eaaa1 100644 --- a/app/src/main/res/layout/fragment_options_misc.xml +++ b/app/src/main/res/layout/fragment_options_misc.xml @@ -1460,6 +1460,17 @@ app:layout_constraintTop_toBottomOf="@id/swEmptyPool" app:switchPadding="12dp" /> + + APOP Use TOP IDLE/DONE + Fast FETCH Logarithmic back-off Turning this off can result in a significant increase in battery usage! Poll on keep-alive