Server search fixes

pull/209/head
M66B 2 years ago
parent 3a26847818
commit fe3f2df183

@ -100,7 +100,6 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
private final ExecutorService executor = Helper.getBackgroundExecutor(1, "boundary"); private final ExecutorService executor = Helper.getBackgroundExecutor(1, "boundary");
private static final int SEARCH_LIMIT_DEVICE = 1000; private static final int SEARCH_LIMIT_DEVICE = 1000;
private static final int SEARCH_LIMIT_SERVER = 250;
interface IBoundaryCallbackMessages { interface IBoundaryCallbackMessages {
void onLoading(); void onLoading();
@ -621,31 +620,6 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
}); });
state.imessages = (Message[]) result; state.imessages = (Message[]) result;
FetchProfile fp = new FetchProfile();
fp.add(UIDFolder.FetchProfileItem.UID);
fp.add(IMAPFolder.FetchProfileItem.INTERNALDATE);
state.ifolder.fetch(state.imessages, fp);
Arrays.sort(state.imessages, new Comparator<Message>() {
@Override
public int compare(Message m1, Message m2) {
Date d1 = null;
try {
d1 = m1.getReceivedDate();
} catch (Throwable ex) {
Log.w(ex);
}
Date d2 = null;
try {
d2 = m2.getReceivedDate();
} catch (Throwable ex) {
Log.w(ex);
}
return Long.compare(d1 == null ? 0 : d1.getTime(), d2 == null ? 0 : d2.getTime());
}
});
} catch (MessagingException ex) { } catch (MessagingException ex) {
if (ex.getCause() instanceof ProtocolException) if (ex.getCause() instanceof ProtocolException)
throw (ProtocolException) ex.getCause(); throw (ProtocolException) ex.getCause();
@ -654,6 +628,33 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
} }
EntityLog.log(context, "Boundary found messages=" + state.imessages.length); EntityLog.log(context, "Boundary found messages=" + state.imessages.length);
FetchProfile fp = new FetchProfile();
fp.add(UIDFolder.FetchProfileItem.UID);
fp.add(IMAPFolder.FetchProfileItem.INTERNALDATE);
state.ifolder.fetch(state.imessages, fp);
Arrays.sort(state.imessages, new Comparator<Message>() {
@Override
public int compare(Message m1, Message m2) {
Date d1 = null;
try {
d1 = m1.getReceivedDate();
} catch (Throwable ex) {
Log.w(ex);
}
Date d2 = null;
try {
d2 = m2.getReceivedDate();
} catch (Throwable ex) {
Log.w(ex);
}
return Long.compare(d1 == null ? 0 : d1.getTime(), d2 == null ? 0 : d2.getTime());
}
});
EntityLog.log(context, "Boundary sorted messages=" + state.imessages.length);
state.index = state.imessages.length - 1; state.index = state.imessages.length - 1;
} catch (Throwable ex) { } catch (Throwable ex) {
state.error = true; state.error = true;
@ -782,7 +783,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
throw new ProtocolException(responses[responses.length - 1]); throw new ProtocolException(responses[responses.length - 1]);
List<Integer> msgnums = new ArrayList<>(); List<Integer> msgnums = new ArrayList<>();
for (int r = 0; r < Math.min(responses.length, SEARCH_LIMIT_SERVER); r++) { for (int r = 0; r < responses.length; r++) {
IMAPResponse response = (IMAPResponse) responses[r]; IMAPResponse response = (IMAPResponse) responses[r];
if (response.keyEquals("SEARCH")) { if (response.keyEquals("SEARCH")) {
int msgnum; int msgnum;

Loading…
Cancel
Save