mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-28 10:47:28 +00:00
Improved search
This commit is contained in:
parent
e2eaef058d
commit
0759c66774
1 changed files with 57 additions and 71 deletions
|
@ -197,24 +197,16 @@ public class ViewModelBrowse extends ViewModel {
|
|||
}
|
||||
|
||||
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
|
||||
Log.i("Boundary UTF8 search=" + state.search);
|
||||
Argument arg = new Argument();
|
||||
if (!protocol.supportsUtf8()) {
|
||||
arg.writeAtom("CHARSET");
|
||||
arg.writeAtom("UTF-8");
|
||||
}
|
||||
if (keywords)
|
||||
arg.writeAtom("OR");
|
||||
arg.writeAtom("OR");
|
||||
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.writeAtom("TEXT");
|
||||
arg.writeBytes(state.search.getBytes());
|
||||
if (keywords) {
|
||||
arg.writeAtom("KEYWORD");
|
||||
|
@ -223,30 +215,18 @@ public class ViewModelBrowse extends ViewModel {
|
|||
arg.writeAtom("ALL");
|
||||
Response[] responses = protocol.command("SEARCH", arg);
|
||||
|
||||
int msgnum;
|
||||
List<Integer> msgnums = new ArrayList<>();
|
||||
for (int i = 0; i < responses.length; i++) {
|
||||
if (responses[i] instanceof IMAPResponse) {
|
||||
IMAPResponse ir = (IMAPResponse) responses[i];
|
||||
if (ir.keyEquals("SEARCH")) {
|
||||
while ((msgnum = ir.readNumber()) != -1)
|
||||
for (Response response : responses)
|
||||
if (response.isOK())
|
||||
Log.i(folder.name + " response=" + response);
|
||||
else if (((IMAPResponse) response).keyEquals("SEARCH")) {
|
||||
int msgnum;
|
||||
while ((msgnum = response.readNumber()) != -1)
|
||||
msgnums.add(msgnum);
|
||||
}
|
||||
} else {
|
||||
if (responses[i].isOK())
|
||||
Log.i(folder.name + " response=" + responses[i]);
|
||||
else
|
||||
throw new MessagingException(responses[i].toString());
|
||||
}
|
||||
}
|
||||
Log.w(folder.name + " response=" + response);
|
||||
|
||||
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 {
|
||||
// No UTF-8 support
|
||||
// Assume no UTF-8 support
|
||||
String search = state.search.replace("ß", "ss"); // Eszett
|
||||
search = Normalizer.normalize(search, Normalizer.Form.NFD)
|
||||
.replaceAll("[^\\p{ASCII}]", "");
|
||||
|
@ -269,6 +249,12 @@ public class ViewModelBrowse extends ViewModel {
|
|||
|
||||
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) {
|
||||
Log.e(ex);
|
||||
return ex;
|
||||
|
|
Loading…
Reference in a new issue