Improved search

pull/152/head
M66B 6 years ago
parent e2eaef058d
commit 0759c66774

@ -197,24 +197,16 @@ public class ViewModelBrowse extends ViewModel {
} }
try { try {
if (protocol.supportsUtf8()) {
// SEARCH OR OR FROM "x" TO "x" OR SUBJECT "x" BODY "x" ALL
// SEARCH OR OR OR FROM "x" TO "x" OR SUBJECT "x" BODY "x" (KEYWORD x) ALL
// https://tools.ietf.org/html/rfc3501#section-6.4.4 // https://tools.ietf.org/html/rfc3501#section-6.4.4
Log.i("Boundary UTF8 search=" + state.search); Log.i("Boundary UTF8 search=" + state.search);
Argument arg = new Argument(); Argument arg = new Argument();
if (!protocol.supportsUtf8()) {
arg.writeAtom("CHARSET");
arg.writeAtom("UTF-8");
}
if (keywords) if (keywords)
arg.writeAtom("OR"); arg.writeAtom("OR");
arg.writeAtom("OR"); arg.writeAtom("TEXT");
arg.writeAtom("OR");
arg.writeAtom("FROM");
arg.writeBytes(state.search.getBytes());
arg.writeAtom("TO");
arg.writeBytes(state.search.getBytes());
arg.writeAtom("OR");
arg.writeAtom("SUBJECT");
arg.writeBytes(state.search.getBytes());
arg.writeAtom("BODY");
arg.writeBytes(state.search.getBytes()); arg.writeBytes(state.search.getBytes());
if (keywords) { if (keywords) {
arg.writeAtom("KEYWORD"); arg.writeAtom("KEYWORD");
@ -223,30 +215,18 @@ public class ViewModelBrowse extends ViewModel {
arg.writeAtom("ALL"); arg.writeAtom("ALL");
Response[] responses = protocol.command("SEARCH", arg); Response[] responses = protocol.command("SEARCH", arg);
int msgnum;
List<Integer> msgnums = new ArrayList<>(); List<Integer> msgnums = new ArrayList<>();
for (int i = 0; i < responses.length; i++) { for (Response response : responses)
if (responses[i] instanceof IMAPResponse) { if (response.isOK())
IMAPResponse ir = (IMAPResponse) responses[i]; Log.i(folder.name + " response=" + response);
if (ir.keyEquals("SEARCH")) { else if (((IMAPResponse) response).keyEquals("SEARCH")) {
while ((msgnum = ir.readNumber()) != -1) int msgnum;
while ((msgnum = response.readNumber()) != -1)
msgnums.add(msgnum); msgnums.add(msgnum);
}
} else { } else {
if (responses[i].isOK()) Log.w(folder.name + " response=" + response);
Log.i(folder.name + " response=" + responses[i]);
else
throw new MessagingException(responses[i].toString());
}
}
Message[] imessages = new Message[msgnums.size()]; // Assume no UTF-8 support
for (int i = 0; i < msgnums.size(); i++)
imessages[i] = state.ifolder.getMessage(msgnums.get(i));
return imessages;
} else {
// No UTF-8 support
String search = state.search.replace("ß", "ss"); // Eszett String search = state.search.replace("ß", "ss"); // Eszett
search = Normalizer.normalize(search, Normalizer.Form.NFD) search = Normalizer.normalize(search, Normalizer.Form.NFD)
.replaceAll("[^\\p{ASCII}]", ""); .replaceAll("[^\\p{ASCII}]", "");
@ -269,6 +249,12 @@ public class ViewModelBrowse extends ViewModel {
return state.ifolder.search(term); return state.ifolder.search(term);
} }
Message[] imessages = new Message[msgnums.size()];
for (int i = 0; i < msgnums.size(); i++)
imessages[i] = state.ifolder.getMessage(msgnums.get(i));
return imessages;
} catch (MessagingException ex) { } catch (MessagingException ex) {
Log.e(ex); Log.e(ex);
return ex; return ex;

Loading…
Cancel
Save