mirror of https://github.com/M66B/FairEmail.git
Simplified search exceptions
This commit is contained in:
parent
019806b3c5
commit
2f256310cc
|
@ -353,7 +353,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int load_server(final State state) throws MessagingException, IOException {
|
private int load_server(final State state) throws MessagingException, ProtocolException, IOException {
|
||||||
DB db = DB.getInstance(context);
|
DB db = DB.getInstance(context);
|
||||||
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
@ -418,73 +418,79 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
||||||
else
|
else
|
||||||
state.imessages = state.ifolder.search(new AndTerm(and.toArray(new SearchTerm[0])));
|
state.imessages = state.ifolder.search(new AndTerm(and.toArray(new SearchTerm[0])));
|
||||||
EntityLog.log(context, "Boundary filter messages=" + state.imessages.length);
|
EntityLog.log(context, "Boundary filter messages=" + state.imessages.length);
|
||||||
} else {
|
} else
|
||||||
Object result = state.ifolder.doCommand(new IMAPFolder.ProtocolCommand() {
|
try {
|
||||||
@Override
|
Object result = state.ifolder.doCommand(new IMAPFolder.ProtocolCommand() {
|
||||||
public Object doCommand(IMAPProtocol protocol) throws ProtocolException {
|
@Override
|
||||||
try {
|
public Object doCommand(IMAPProtocol protocol) throws ProtocolException {
|
||||||
// https://tools.ietf.org/html/rfc3501#section-6.4.4
|
try {
|
||||||
if (criteria.query != null &&
|
// https://tools.ietf.org/html/rfc3501#section-6.4.4
|
||||||
criteria.query.startsWith("raw:") &&
|
if (criteria.query != null &&
|
||||||
protocol.hasCapability("X-GM-EXT-1") &&
|
criteria.query.startsWith("raw:") &&
|
||||||
EntityFolder.ARCHIVE.equals(browsable.type)) {
|
protocol.hasCapability("X-GM-EXT-1") &&
|
||||||
// https://support.google.com/mail/answer/7190
|
EntityFolder.ARCHIVE.equals(browsable.type)) {
|
||||||
// https://developers.google.com/gmail/imap/imap-extensions#extension_of_the_search_command_x-gm-raw
|
// https://support.google.com/mail/answer/7190
|
||||||
Log.i("Boundary raw search=" + criteria.query);
|
// https://developers.google.com/gmail/imap/imap-extensions#extension_of_the_search_command_x-gm-raw
|
||||||
|
Log.i("Boundary raw search=" + criteria.query);
|
||||||
|
|
||||||
Argument arg = new Argument();
|
Argument arg = new Argument();
|
||||||
arg.writeAtom("X-GM-RAW");
|
arg.writeAtom("X-GM-RAW");
|
||||||
arg.writeString(criteria.query.substring(4));
|
arg.writeString(criteria.query.substring(4));
|
||||||
|
|
||||||
Response[] responses = protocol.command("SEARCH", arg);
|
Response[] responses = protocol.command("SEARCH", arg);
|
||||||
if (responses.length == 0)
|
if (responses.length == 0)
|
||||||
throw new ProtocolException("No response");
|
throw new ProtocolException("No response");
|
||||||
if (!responses[responses.length - 1].isOK())
|
if (!responses[responses.length - 1].isOK())
|
||||||
throw new ProtocolException(
|
throw new ProtocolException(
|
||||||
context.getString(R.string.title_service_auth, responses[responses.length - 1]));
|
context.getString(R.string.title_service_auth, responses[responses.length - 1]));
|
||||||
|
|
||||||
List<Integer> msgnums = new ArrayList<>();
|
List<Integer> msgnums = new ArrayList<>();
|
||||||
for (Response response : responses)
|
for (Response response : responses)
|
||||||
if (((IMAPResponse) response).keyEquals("SEARCH")) {
|
if (((IMAPResponse) response).keyEquals("SEARCH")) {
|
||||||
int msgnum;
|
int msgnum;
|
||||||
while ((msgnum = response.readNumber()) != -1)
|
while ((msgnum = response.readNumber()) != -1)
|
||||||
msgnums.add(msgnum);
|
msgnums.add(msgnum);
|
||||||
|
}
|
||||||
|
|
||||||
|
Message[] imessages = new Message[msgnums.size()];
|
||||||
|
for (int i = 0; i < msgnums.size(); i++)
|
||||||
|
imessages[i] = state.ifolder.getMessage(msgnums.get(i));
|
||||||
|
|
||||||
|
return imessages;
|
||||||
|
} else {
|
||||||
|
EntityLog.log(context, "Boundary server" +
|
||||||
|
" account=" + account +
|
||||||
|
" folder=" + folder +
|
||||||
|
" search=" + criteria);
|
||||||
|
|
||||||
|
try {
|
||||||
|
return search(true, browsable.keywords, protocol, state);
|
||||||
|
} catch (Throwable ex) {
|
||||||
|
EntityLog.log(context, ex.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
Message[] imessages = new Message[msgnums.size()];
|
return search(false, browsable.keywords, protocol, state);
|
||||||
for (int i = 0; i < msgnums.size(); i++)
|
|
||||||
imessages[i] = state.ifolder.getMessage(msgnums.get(i));
|
|
||||||
|
|
||||||
return imessages;
|
|
||||||
} else {
|
|
||||||
EntityLog.log(context, "Boundary server" +
|
|
||||||
" account=" + account +
|
|
||||||
" folder=" + folder +
|
|
||||||
" search=" + criteria);
|
|
||||||
|
|
||||||
try {
|
|
||||||
return search(true, browsable.keywords, protocol, state);
|
|
||||||
} catch (Throwable ex) {
|
|
||||||
EntityLog.log(context, ex.toString());
|
|
||||||
}
|
}
|
||||||
|
} catch (Throwable ex) {
|
||||||
return search(false, browsable.keywords, protocol, state);
|
String msg;
|
||||||
|
if (ex instanceof ProtocolException)
|
||||||
|
msg = context.getString(R.string.title_service_auth, account.host + ": " + ex.getMessage());
|
||||||
|
else
|
||||||
|
msg = "Search " + account.host;
|
||||||
|
ProtocolException pex = new ProtocolException(msg, ex);
|
||||||
|
Log.e(pex);
|
||||||
|
throw pex;
|
||||||
}
|
}
|
||||||
} catch (Throwable ex) {
|
|
||||||
String msg;
|
|
||||||
if (ex instanceof ProtocolException)
|
|
||||||
msg = context.getString(R.string.title_service_auth, account.host + ": " + ex.getMessage());
|
|
||||||
else
|
|
||||||
msg = "Search " + account.host;
|
|
||||||
ProtocolException pex = new ProtocolException(msg, ex);
|
|
||||||
Log.e(pex);
|
|
||||||
throw pex;
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
|
|
||||||
state.imessages = (Message[]) result;
|
state.imessages = (Message[]) result;
|
||||||
}
|
} catch (MessagingException ex) {
|
||||||
|
if (ex.getCause() instanceof ProtocolException)
|
||||||
|
throw (ProtocolException) ex.getCause();
|
||||||
|
else
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
EntityLog.log(context, "Boundary found messages=" + state.imessages.length);
|
EntityLog.log(context, "Boundary found messages=" + state.imessages.length);
|
||||||
|
|
||||||
state.index = state.imessages.length - 1;
|
state.index = state.imessages.length - 1;
|
||||||
|
|
Loading…
Reference in New Issue