Added debug option to disable expunge

pull/194/head
M66B 4 years ago
parent 5c8f4c0cbc
commit 89ee7d79ee

@ -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. 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). 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.
<br /> <br />
<a name="faq161"></a> <a name="faq161"></a>

@ -614,7 +614,7 @@ class Core {
if (TextUtils.isEmpty(message.msgid)) if (TextUtils.isEmpty(message.msgid))
throw new IllegalArgumentException("Message without msgid for " + op.name); 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) if (uid == null)
throw new IllegalArgumentException("Message not found for " + op.name + " folder=" + folder.name); throw new IllegalArgumentException("Message not found for " + op.name + " folder=" + folder.name);
@ -623,7 +623,7 @@ class Core {
message.uid = uid; 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(); String name = ifolder.getFullName();
Log.i(name + " searching for msgid=" + msgid); 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 { try {
ifolder.expunge(); ifolder.expunge();
} catch (MessagingException ex) { } catch (MessagingException ex) {
@ -833,6 +835,10 @@ class Core {
if (imessage == null) if (imessage == null)
throw new MessageRemovedException(); throw new MessageRemovedException();
imessage.setFlag(Flags.Flag.DELETED, true); imessage.setFlag(Flags.Flag.DELETED, true);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean perform_expunge = prefs.getBoolean("perform_expunge", true);
if (perform_expunge)
ifolder.expunge(); ifolder.expunge();
} catch (MessagingException ex) { } catch (MessagingException ex) {
Log.w(ex); Log.w(ex);
@ -971,7 +977,7 @@ class Core {
// Some providers do not list the new message yet // Some providers do not list the new message yet
try { try {
Long found = findUid(ifolder, message.msgid, true); Long found = findUid(context, ifolder, message.msgid, true);
if (found != null) if (found != null)
if (newuid == null) if (newuid == null)
newuid = found; newuid = found;
@ -1102,6 +1108,10 @@ class Core {
try { try {
for (Message imessage : map.keySet()) for (Message imessage : map.keySet())
imessage.setFlag(Flags.Flag.DELETED, true); imessage.setFlag(Flags.Flag.DELETED, true);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean perform_expunge = prefs.getBoolean("perform_expunge", true);
if (perform_expunge)
ifolder.expunge(); ifolder.expunge();
} catch (MessageRemovedException ex) { } catch (MessageRemovedException ex) {
Log.w(ex); Log.w(ex);
@ -1126,7 +1136,7 @@ class Core {
if (TextUtils.isEmpty(message.msgid)) if (TextUtils.isEmpty(message.msgid))
throw new IllegalArgumentException("move: msgid missing"); throw new IllegalArgumentException("move: msgid missing");
Long uid = findUid(itarget, message.msgid, false); Long uid = findUid(context, itarget, message.msgid, false);
if (uid == null) if (uid == null)
throw new IllegalArgumentException("move: uid not found"); throw new IllegalArgumentException("move: uid not found");
@ -1354,8 +1364,12 @@ class Core {
Log.w(ex); Log.w(ex);
} }
if (deleted) if (deleted) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean perform_expunge = prefs.getBoolean("perform_expunge", true);
if (perform_expunge)
ifolder.expunge(); // NO EXPUNGE failed. ifolder.expunge(); // NO EXPUNGE failed.
}
db.message().deleteMessage(message.id); db.message().deleteMessage(message.id);
} finally { } finally {
@ -1958,6 +1972,9 @@ class Core {
}); });
Log.i(folder.name + " purge deleted"); Log.i(folder.name + " purge deleted");
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean perform_expunge = prefs.getBoolean("perform_expunge", true);
if (perform_expunge)
ifolder.expunge(); ifolder.expunge();
Log.i(folder.name + " purge expunged"); Log.i(folder.name + " purge expunged");
} catch (Throwable ex) { } catch (Throwable ex) {
@ -2301,6 +2318,7 @@ class Core {
boolean sync_flagged = prefs.getBoolean("sync_flagged", false); boolean sync_flagged = prefs.getBoolean("sync_flagged", false);
boolean sync_kept = prefs.getBoolean("sync_kept", true); boolean sync_kept = prefs.getBoolean("sync_kept", true);
boolean delete_unseen = prefs.getBoolean("delete_unseen", false); 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 + Log.i(folder.name + " start sync after=" + sync_days + "/" + keep_days +
" force=" + force + " force=" + force +
@ -2437,7 +2455,7 @@ class Core {
db.folder().setFolderError(folder.id, Log.formatThrowable(ex)); db.folder().setFolderError(folder.id, Log.formatThrowable(ex));
} }
if (expunge > 0) if (expunge > 0 && perform_expunge)
try { try {
Log.i(folder.name + " expunging=" + expunge); Log.i(folder.name + " expunging=" + expunge);
ifolder.expunge(); ifolder.expunge();

@ -109,6 +109,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private SwitchCompat swProtocol; private SwitchCompat swProtocol;
private SwitchCompat swDebug; private SwitchCompat swDebug;
private SwitchCompat swExpunge;
private SwitchCompat swAuthPlain; private SwitchCompat swAuthPlain;
private SwitchCompat swAuthLogin; private SwitchCompat swAuthLogin;
private SwitchCompat swAuthNtlm; private SwitchCompat swAuthNtlm;
@ -133,7 +134,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
"classification", "class_min_probability", "class_min_difference", "classification", "class_min_probability", "class_min_difference",
"language", "watchdog", "updates", "language", "watchdog", "updates",
"experiments", "query_threads", "crash_reports", "cleanup_attachments", "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[]{ 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); swProtocol = view.findViewById(R.id.swProtocol);
swDebug = view.findViewById(R.id.swDebug); swDebug = view.findViewById(R.id.swDebug);
swExpunge = view.findViewById(R.id.swExpunge);
swAuthPlain = view.findViewById(R.id.swAuthPlain); swAuthPlain = view.findViewById(R.id.swAuthPlain);
swAuthLogin = view.findViewById(R.id.swAuthLogin); swAuthLogin = view.findViewById(R.id.swAuthLogin);
swAuthNtlm = view.findViewById(R.id.swAuthNtlm); 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() { swAuthPlain.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -845,6 +854,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swProtocol.setChecked(prefs.getBoolean("protocol", false)); swProtocol.setChecked(prefs.getBoolean("protocol", false));
swDebug.setChecked(prefs.getBoolean("debug", false)); swDebug.setChecked(prefs.getBoolean("debug", false));
swExpunge.setChecked(prefs.getBoolean("perform_expunge", true));
swAuthPlain.setChecked(prefs.getBoolean("auth_plain", true)); swAuthPlain.setChecked(prefs.getBoolean("auth_plain", true));
swAuthLogin.setChecked(prefs.getBoolean("auth_login", true)); swAuthLogin.setChecked(prefs.getBoolean("auth_login", true));
swAuthNtlm.setChecked(prefs.getBoolean("auth_ntlm", true)); swAuthNtlm.setChecked(prefs.getBoolean("auth_ntlm", true));

@ -492,6 +492,18 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swDebug" /> app:layout_constraintTop_toBottomOf="@id/swDebug" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swExpunge"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:checked="true"
android:text="@string/title_advanced_expunge"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvDebugHint"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat
android:id="@+id/swAuthPlain" android:id="@+id/swAuthPlain"
android:layout_width="0dp" android:layout_width="0dp"
@ -501,7 +513,7 @@
android:text="@string/title_advanced_auth_plain" android:text="@string/title_advanced_auth_plain"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvDebugHint" app:layout_constraintTop_toBottomOf="@id/swExpunge"
app:switchPadding="12dp" /> app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat
@ -627,6 +639,6 @@
android:id="@+id/grpDebug" android:id="@+id/grpDebug"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
app:constraint_referenced_ids="swAuthPlain,swAuthLogin,swAuthNtlm,swAuthSasl,tvProcessors,tvMemoryClass,tvMemoryUsage,tvStorageUsage,tvFingerprint,btnCharsets,btnCiphers,btnFiles" /> app:constraint_referenced_ids="swExpunge,swAuthPlain,swAuthLogin,swAuthNtlm,swAuthSasl,tvProcessors,tvMemoryClass,tvMemoryUsage,tvStorageUsage,tvFingerprint,btnCharsets,btnCiphers,btnFiles" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</eu.faircode.email.ScrollViewEx> </eu.faircode.email.ScrollViewEx>

@ -521,6 +521,7 @@
<string name="title_advanced_language">Language</string> <string name="title_advanced_language">Language</string>
<string name="title_advanced_language_system">System</string> <string name="title_advanced_language_system">System</string>
<string name="title_advanced_watchdog">Periodically check if FairEmail is still active</string> <string name="title_advanced_watchdog">Periodically check if FairEmail is still active</string>
<string name="title_advanced_expunge" translatable="false">EXPUNGE (debug only)</string>
<string name="title_advanced_auth_plain" translatable="false">PLAIN (debug only)</string> <string name="title_advanced_auth_plain" translatable="false">PLAIN (debug only)</string>
<string name="title_advanced_auth_login" translatable="false">LOGIN (debug only)</string> <string name="title_advanced_auth_login" translatable="false">LOGIN (debug only)</string>
<string name="title_advanced_auth_ntlm" translatable="false">NTLM (debug only)</string> <string name="title_advanced_auth_ntlm" translatable="false">NTLM (debug only)</string>

Loading…
Cancel
Save