From 89ee7d79ee563c80c026a05e56a45723cc0da871 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 9 Feb 2021 16:49:51 +0100 Subject: [PATCH] Added debug option to disable expunge --- FAQ.md | 3 ++ app/src/main/java/eu/faircode/email/Core.java | 40 ++++++++++++++----- .../faircode/email/FragmentOptionsMisc.java | 12 +++++- .../main/res/layout/fragment_options_misc.xml | 16 +++++++- app/src/main/res/values/strings.xml | 1 + 5 files changed, 58 insertions(+), 14 deletions(-) diff --git a/FAQ.md b/FAQ.md index bbd40e8aac..6a12b07345 100644 --- a/FAQ.md +++ b/FAQ.md @@ -3423,6 +3423,9 @@ Advanced: the IMAP delete flag in combination with the EXPUNGE command is not su because both email servers and not all people can handle this, risking unexpected loss of messages. A complicating factor is that not all email servers support [UID EXPUNGE](https://tools.ietf.org/html/rfc4315). +From version 1.1485 it is possible to temporarily enable debug mode in the miscellaneous settings to disable expunging messages. +Note that messages with a *\Deleted* flag will not be shown in FairEmail. +
diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 1fad568b48..29ddb82a7f 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -614,7 +614,7 @@ class Core { if (TextUtils.isEmpty(message.msgid)) throw new IllegalArgumentException("Message without msgid for " + op.name); - Long uid = findUid(ifolder, message.msgid, false); + Long uid = findUid(context, ifolder, message.msgid, false); if (uid == null) throw new IllegalArgumentException("Message not found for " + op.name + " folder=" + folder.name); @@ -623,7 +623,7 @@ class Core { message.uid = uid; } - private static Long findUid(IMAPFolder ifolder, String msgid, boolean purge) throws MessagingException { + private static Long findUid(Context context, IMAPFolder ifolder, String msgid, boolean purge) throws MessagingException { String name = ifolder.getFullName(); Log.i(name + " searching for msgid=" + msgid); @@ -657,7 +657,9 @@ class Core { } } - if (purged) + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + boolean perform_expunge = prefs.getBoolean("perform_expunge", true); + if (purged && perform_expunge) try { ifolder.expunge(); } catch (MessagingException ex) { @@ -833,7 +835,11 @@ class Core { if (imessage == null) throw new MessageRemovedException(); imessage.setFlag(Flags.Flag.DELETED, true); - ifolder.expunge(); + + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + boolean perform_expunge = prefs.getBoolean("perform_expunge", true); + if (perform_expunge) + ifolder.expunge(); } catch (MessagingException ex) { Log.w(ex); } @@ -971,7 +977,7 @@ class Core { // Some providers do not list the new message yet try { - Long found = findUid(ifolder, message.msgid, true); + Long found = findUid(context, ifolder, message.msgid, true); if (found != null) if (newuid == null) newuid = found; @@ -1102,7 +1108,11 @@ class Core { try { for (Message imessage : map.keySet()) imessage.setFlag(Flags.Flag.DELETED, true); - ifolder.expunge(); + + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + boolean perform_expunge = prefs.getBoolean("perform_expunge", true); + if (perform_expunge) + ifolder.expunge(); } catch (MessageRemovedException ex) { Log.w(ex); } @@ -1126,7 +1136,7 @@ class Core { if (TextUtils.isEmpty(message.msgid)) throw new IllegalArgumentException("move: msgid missing"); - Long uid = findUid(itarget, message.msgid, false); + Long uid = findUid(context, itarget, message.msgid, false); if (uid == null) throw new IllegalArgumentException("move: uid not found"); @@ -1354,8 +1364,12 @@ class Core { Log.w(ex); } - if (deleted) - ifolder.expunge(); // NO EXPUNGE failed. + if (deleted) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + boolean perform_expunge = prefs.getBoolean("perform_expunge", true); + if (perform_expunge) + ifolder.expunge(); // NO EXPUNGE failed. + } db.message().deleteMessage(message.id); } finally { @@ -1958,7 +1972,10 @@ class Core { }); Log.i(folder.name + " purge deleted"); - ifolder.expunge(); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + boolean perform_expunge = prefs.getBoolean("perform_expunge", true); + if (perform_expunge) + ifolder.expunge(); Log.i(folder.name + " purge expunged"); } catch (Throwable ex) { Log.e(ex); @@ -2301,6 +2318,7 @@ class Core { boolean sync_flagged = prefs.getBoolean("sync_flagged", false); boolean sync_kept = prefs.getBoolean("sync_kept", true); boolean delete_unseen = prefs.getBoolean("delete_unseen", false); + boolean perform_expunge = prefs.getBoolean("perform_expunge", true); Log.i(folder.name + " start sync after=" + sync_days + "/" + keep_days + " force=" + force + @@ -2437,7 +2455,7 @@ class Core { db.folder().setFolderError(folder.id, Log.formatThrowable(ex)); } - if (expunge > 0) + if (expunge > 0 && perform_expunge) try { Log.i(folder.name + " expunging=" + expunge); ifolder.expunge(); diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java index 3dc5d87f3c..eadd423728 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java @@ -109,6 +109,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc private SwitchCompat swProtocol; private SwitchCompat swDebug; + private SwitchCompat swExpunge; private SwitchCompat swAuthPlain; private SwitchCompat swAuthLogin; private SwitchCompat swAuthNtlm; @@ -133,7 +134,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc "classification", "class_min_probability", "class_min_difference", "language", "watchdog", "updates", "experiments", "query_threads", "crash_reports", "cleanup_attachments", - "protocol", "debug", "auth_plain", "auth_login", "auth_ntlm", "auth_sasl" + "protocol", "debug", "perform_expunge", "auth_plain", "auth_login", "auth_ntlm", "auth_sasl" }; private final static String[] RESET_QUESTIONS = new String[]{ @@ -200,6 +201,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc swProtocol = view.findViewById(R.id.swProtocol); swDebug = view.findViewById(R.id.swDebug); + swExpunge = view.findViewById(R.id.swExpunge); swAuthPlain = view.findViewById(R.id.swAuthPlain); swAuthLogin = view.findViewById(R.id.swAuthLogin); swAuthNtlm = view.findViewById(R.id.swAuthNtlm); @@ -469,6 +471,13 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc } }); + swExpunge.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("perform_expunge", checked).apply(); + } + }); + swAuthPlain.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -845,6 +854,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc swProtocol.setChecked(prefs.getBoolean("protocol", false)); swDebug.setChecked(prefs.getBoolean("debug", false)); + swExpunge.setChecked(prefs.getBoolean("perform_expunge", true)); swAuthPlain.setChecked(prefs.getBoolean("auth_plain", true)); swAuthLogin.setChecked(prefs.getBoolean("auth_login", true)); swAuthNtlm.setChecked(prefs.getBoolean("auth_ntlm", true)); diff --git a/app/src/main/res/layout/fragment_options_misc.xml b/app/src/main/res/layout/fragment_options_misc.xml index de704313d0..79fed98479 100644 --- a/app/src/main/res/layout/fragment_options_misc.xml +++ b/app/src/main/res/layout/fragment_options_misc.xml @@ -492,6 +492,18 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/swDebug" /> + + + app:constraint_referenced_ids="swExpunge,swAuthPlain,swAuthLogin,swAuthNtlm,swAuthSasl,tvProcessors,tvMemoryClass,tvMemoryUsage,tvStorageUsage,tvFingerprint,btnCharsets,btnCiphers,btnFiles" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 12c0b2bb66..04106ce070 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -521,6 +521,7 @@ Language System Periodically check if FairEmail is still active + EXPUNGE (debug only) PLAIN (debug only) LOGIN (debug only) NTLM (debug only)