Catch search exceptions

pull/147/head
M66B 6 years ago
parent 0bbf4d38d2
commit 71e484c1c3

@ -25,7 +25,6 @@ import android.util.Log;
import com.sun.mail.imap.IMAPFolder; import com.sun.mail.imap.IMAPFolder;
import com.sun.mail.imap.IMAPMessage; import com.sun.mail.imap.IMAPMessage;
import com.sun.mail.imap.IMAPStore; import com.sun.mail.imap.IMAPStore;
import com.sun.mail.util.FolderClosedIOException;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
@ -133,40 +132,49 @@ public class ViewModelBrowse extends ViewModel {
EntityAccount account = db.account().getAccount(folder.account); EntityAccount account = db.account().getAccount(folder.account);
Properties props = MessageHelper.getSessionProperties(account.auth_type, account.insecure); try {
props.setProperty("mail.imap.throwsearchexception", "true"); Properties props = MessageHelper.getSessionProperties(account.auth_type, account.insecure);
Session isession = Session.getInstance(props, null); props.setProperty("mail.imap.throwsearchexception", "true");
Session isession = Session.getInstance(props, null);
Log.i(Helper.TAG, "Boundary connecting account=" + account.name);
state.istore = (IMAPStore) isession.getStore(account.starttls ? "imap" : "imaps"); Log.i(Helper.TAG, "Boundary connecting account=" + account.name);
Helper.connect(state.context, state.istore, account); state.istore = (IMAPStore) isession.getStore(account.starttls ? "imap" : "imaps");
Helper.connect(state.context, state.istore, account);
Log.i(Helper.TAG, "Boundary opening folder=" + folder.name);
state.ifolder = (IMAPFolder) state.istore.getFolder(folder.name); Log.i(Helper.TAG, "Boundary opening folder=" + folder.name);
state.ifolder.open(Folder.READ_WRITE); state.ifolder = (IMAPFolder) state.istore.getFolder(folder.name);
state.ifolder.open(Folder.READ_WRITE);
Log.i(Helper.TAG, "Boundary searching=" + state.search);
if (state.search == null) Log.i(Helper.TAG, "Boundary searching=" + state.search);
state.imessages = state.ifolder.getMessages(); if (state.search == null)
else state.imessages = state.ifolder.getMessages();
state.imessages = state.ifolder.search( else
new OrTerm( state.imessages = state.ifolder.search(
new OrTerm( new OrTerm(
new OrTerm( new OrTerm(
new FromStringTerm(state.search), new OrTerm(
new RecipientStringTerm(Message.RecipientType.TO, state.search) new FromStringTerm(state.search),
), new RecipientStringTerm(Message.RecipientType.TO, state.search)
new OrTerm( ),
new SubjectTerm(state.search), new OrTerm(
new BodyTerm(state.search) new SubjectTerm(state.search),
) new BodyTerm(state.search)
), )
new FlagTerm(new Flags(Helper.sanitizeKeyword(state.search)), true) ),
) new FlagTerm(new Flags(Helper.sanitizeKeyword(state.search)), true)
); )
Log.i(Helper.TAG, "Boundary found messages=" + state.imessages.length); );
Log.i(Helper.TAG, "Boundary found messages=" + state.imessages.length);
state.index = state.imessages.length - 1;
state.index = state.imessages.length - 1;
} catch (Throwable ex) {
if (ex instanceof FolderClosedException)
Log.w(Helper.TAG, "Search " + ex + "\n" + Log.getStackTraceString(ex));
else {
Log.e(Helper.TAG, "Search " + ex + "\n" + Log.getStackTraceString(ex));
throw ex;
}
}
} }
int count = 0; int count = 0;
@ -202,9 +210,7 @@ public class ViewModelBrowse extends ViewModel {
} }
db.message().setMessageFound(message.account, message.thread); db.message().setMessageFound(message.account, message.thread);
} catch (Throwable ex) { } catch (Throwable ex) {
if ((ex instanceof MessageRemovedException) || if ((ex instanceof MessageRemovedException) || (ex instanceof FolderClosedException))
(ex instanceof FolderClosedException) ||
(ex instanceof FolderClosedIOException))
Log.w(Helper.TAG, "Boundary " + ex + "\n" + Log.getStackTraceString(ex)); Log.w(Helper.TAG, "Boundary " + ex + "\n" + Log.getStackTraceString(ex));
else { else {
Log.e(Helper.TAG, "Boundary " + ex + "\n" + Log.getStackTraceString(ex)); Log.e(Helper.TAG, "Boundary " + ex + "\n" + Log.getStackTraceString(ex));

Loading…
Cancel
Save