Sanitize folder errors

pull/149/head
M66B 6 years ago
parent ff5982cfa3
commit 77e38e0a94

@ -56,6 +56,7 @@ import android.widget.Toast;
import com.android.billingclient.api.BillingClient;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.sun.mail.util.FolderClosedIOException;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
@ -84,9 +85,12 @@ import java.util.concurrent.ThreadFactory;
import javax.mail.Address;
import javax.mail.AuthenticationFailedException;
import javax.mail.FolderClosedException;
import javax.mail.MessageRemovedException;
import javax.mail.MessagingException;
import javax.mail.Store;
import javax.mail.internet.InternetAddress;
import javax.net.ssl.SSLException;
import androidx.annotation.NonNull;
import androidx.browser.customtabs.CustomTabsIntent;
@ -283,10 +287,28 @@ public class Helper {
}
static String formatThrowable(Throwable ex) {
return formatThrowable(ex, " ");
return formatThrowable(ex, false, " ");
}
static String formatThrowable(Throwable ex, boolean sanitize) {
return formatThrowable(ex, sanitize, " ");
}
static String formatThrowable(Throwable ex, boolean sanitize, String separator) {
if (sanitize) {
if (ex instanceof MessageRemovedException)
return null;
if (ex instanceof FolderClosedException)
return null;
if (ex instanceof FolderClosedIOException)
return null;
if (ex instanceof IllegalStateException)
// sync when store disconnected
return null;
if (ex instanceof SSLException || ex.getCause() instanceof SSLException)
return null;
}
static String formatThrowable(Throwable ex, String separator) {
StringBuilder sb = new StringBuilder();
if (BuildConfig.DEBUG)
sb.append(ex.toString());

@ -765,7 +765,7 @@ public class ServiceSynchronize extends LifecycleService {
.setVisibility(Notification.VISIBILITY_SECRET);
builder.setStyle(new Notification.BigTextStyle()
.bigText(Helper.formatThrowable(ex, "\n")));
.bigText(Helper.formatThrowable(ex, false, "\n")));
return builder;
}
@ -984,10 +984,10 @@ public class ServiceSynchronize extends LifecycleService {
} catch (MessagingException ex) {
// Including ReadOnlyFolderException
db.folder().setFolderState(folder.id, null);
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex));
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex, true));
continue;
} catch (Throwable ex) {
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex));
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex, true));
throw ex;
}
folders.put(folder, ifolder);
@ -1048,13 +1048,12 @@ public class ServiceSynchronize extends LifecycleService {
} catch (IOException ex) {
if (ex.getCause() instanceof MessagingException) {
Log.w(folder.name, ex);
if (!(ex.getCause() instanceof MessageRemovedException))
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex));
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex, true));
} else
throw ex;
} catch (Throwable ex) {
Log.e(folder.name, ex);
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex));
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex, true));
}
} catch (Throwable ex) {
Log.e(folder.name, ex);
@ -1084,7 +1083,7 @@ public class ServiceSynchronize extends LifecycleService {
} catch (Throwable ex) {
Log.e(folder.name, ex);
reportError(account, folder, ex);
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex));
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex, true));
state.error();
} finally {
wlAccount.release();
@ -1138,13 +1137,12 @@ public class ServiceSynchronize extends LifecycleService {
} catch (IOException ex) {
if (ex.getCause() instanceof MessagingException) {
Log.w(folder.name, ex);
if (!(ex.getCause() instanceof MessageRemovedException))
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex));
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex, true));
} else
throw ex;
} catch (Throwable ex) {
Log.e(folder.name, ex);
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex));
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex, true));
}
} catch (Throwable ex) {
Log.e(folder.name, ex);
@ -1169,7 +1167,7 @@ public class ServiceSynchronize extends LifecycleService {
} catch (Throwable ex) {
Log.e(folder.name, ex);
reportError(account, folder, ex);
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex));
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex, true));
state.error();
} finally {
Log.i(folder.name + " end idle");
@ -1257,9 +1255,7 @@ public class ServiceSynchronize extends LifecycleService {
} catch (Throwable ex) {
Log.e(folder.name, ex);
reportError(account, folder, ex);
// IllegalStateException: sync when store disconnected
if (!(ex instanceof IllegalStateException))
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex));
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex, true));
state.error();
} finally {
if (shouldClose) {
@ -2277,7 +2273,7 @@ public class ServiceSynchronize extends LifecycleService {
Log.w(ex);
reportError(account, folder, ex);
db.account().setAccountError(account.id, Helper.formatThrowable(ex));
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex));
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex, false));
} finally {
if (istore != null) {
Log.i(account.name + " closing");
@ -2477,7 +2473,7 @@ public class ServiceSynchronize extends LifecycleService {
} catch (Throwable ex) {
Log.e(folder.name, ex);
reportError(account, folder, ex);
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex));
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex, true));
}
if (uids.size() > 0) {
@ -2568,13 +2564,12 @@ public class ServiceSynchronize extends LifecycleService {
} catch (IOException ex) {
if (ex.getCause() instanceof MessagingException) {
Log.w(folder.name, ex);
if (!(ex.getCause() instanceof MessageRemovedException))
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex));
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex, true));
} else
throw ex;
} catch (Throwable ex) {
Log.e(folder.name, ex);
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex));
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex, true));
} finally {
db.endTransaction();
// Reduce memory usage
@ -3195,7 +3190,7 @@ public class ServiceSynchronize extends LifecycleService {
} catch (Throwable ex) {
Log.e(outbox.name, ex);
reportError(null, outbox, ex);
db.folder().setFolderError(outbox.id, Helper.formatThrowable(ex));
db.folder().setFolderError(outbox.id, Helper.formatThrowable(ex, true));
} finally {
db.folder().setFolderSyncState(outbox.id, null);
wl.release();

@ -312,13 +312,12 @@ public class ViewModelBrowse extends ViewModel {
} catch (IOException ex) {
if (ex.getCause() instanceof MessagingException) {
Log.w(folder.name + " boundary", ex);
if (!(ex.getCause() instanceof MessageRemovedException))
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex));
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex, true));
} else
throw ex;
} catch (Throwable ex) {
Log.e(folder.name + " boundary", ex);
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex));
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex, true));
} finally {
((IMAPMessage) isub[j]).invalidateHeaders();
}

Loading…
Cancel
Save