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.android.billingclient.api.BillingClient;
import com.google.android.material.bottomnavigation.BottomNavigationView; import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.sun.mail.util.FolderClosedIOException;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
@ -84,9 +85,12 @@ import java.util.concurrent.ThreadFactory;
import javax.mail.Address; import javax.mail.Address;
import javax.mail.AuthenticationFailedException; import javax.mail.AuthenticationFailedException;
import javax.mail.FolderClosedException;
import javax.mail.MessageRemovedException;
import javax.mail.MessagingException; import javax.mail.MessagingException;
import javax.mail.Store; import javax.mail.Store;
import javax.mail.internet.InternetAddress; import javax.mail.internet.InternetAddress;
import javax.net.ssl.SSLException;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.browser.customtabs.CustomTabsIntent; import androidx.browser.customtabs.CustomTabsIntent;
@ -283,10 +287,28 @@ public class Helper {
} }
static String formatThrowable(Throwable ex) { 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(); StringBuilder sb = new StringBuilder();
if (BuildConfig.DEBUG) if (BuildConfig.DEBUG)
sb.append(ex.toString()); sb.append(ex.toString());

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

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

Loading…
Cancel
Save