mirror of https://github.com/M66B/FairEmail.git
Use search workaround by default when UTF-8 is supported
This commit is contained in:
parent
3ee2f7c936
commit
b6c8e01fd1
|
@ -176,47 +176,33 @@ public class ViewModelBrowse extends ViewModel {
|
||||||
if (state.search == null)
|
if (state.search == null)
|
||||||
state.imessages = state.ifolder.getMessages();
|
state.imessages = state.ifolder.getMessages();
|
||||||
else {
|
else {
|
||||||
try {
|
Object result = state.ifolder.doCommand(new IMAPFolder.ProtocolCommand() {
|
||||||
SearchTerm term = new OrTerm(
|
@Override
|
||||||
new OrTerm(
|
public Object doCommand(IMAPProtocol protocol) {
|
||||||
new FromStringTerm(state.search),
|
try {
|
||||||
new RecipientStringTerm(Message.RecipientType.TO, state.search)
|
if (protocol.supportsUtf8()) {
|
||||||
),
|
|
||||||
new OrTerm(
|
|
||||||
new SubjectTerm(state.search),
|
|
||||||
new BodyTerm(state.search)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (folder.keywords.length > 0)
|
|
||||||
term = new OrTerm(term, new FlagTerm(
|
|
||||||
new Flags(Helper.sanitizeKeyword(state.search)), true));
|
|
||||||
|
|
||||||
state.imessages = state.ifolder.search(term);
|
|
||||||
} catch (final MessagingException ex) {
|
|
||||||
Object result = state.ifolder.doCommand(new IMAPFolder.ProtocolCommand() {
|
|
||||||
@Override
|
|
||||||
public Object doCommand(IMAPProtocol protocol) {
|
|
||||||
try {
|
|
||||||
if (!protocol.supportsUtf8())
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
// SEARCH OR OR FROM "x" TO "x" OR SUBJECT "x" BODY "x" ALL
|
// 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
|
// SEARCH OR OR OR FROM "x" TO "x" OR SUBJECT "x" BODY "x" (KEYWORD x) ALL
|
||||||
Argument a = new Argument();
|
Argument arg = new Argument();
|
||||||
a.writeAtom("OR");
|
if (folder.keywords.length > 0)
|
||||||
a.writeAtom("OR");
|
arg.writeAtom("OR");
|
||||||
a.writeAtom("FROM");
|
arg.writeAtom("OR");
|
||||||
a.writeBytes(state.search.getBytes());
|
arg.writeAtom("OR");
|
||||||
a.writeAtom("TO");
|
arg.writeAtom("FROM");
|
||||||
a.writeBytes(state.search.getBytes());
|
arg.writeBytes(state.search.getBytes());
|
||||||
a.writeAtom("OR");
|
arg.writeAtom("TO");
|
||||||
a.writeAtom("SUBJECT");
|
arg.writeBytes(state.search.getBytes());
|
||||||
a.writeBytes(state.search.getBytes());
|
arg.writeAtom("OR");
|
||||||
a.writeAtom("BODY");
|
arg.writeAtom("SUBJECT");
|
||||||
a.writeBytes(state.search.getBytes());
|
arg.writeBytes(state.search.getBytes());
|
||||||
a.writeAtom("ALL");
|
arg.writeAtom("BODY");
|
||||||
Response[] responses = protocol.command("SEARCH", a);
|
arg.writeBytes(state.search.getBytes());
|
||||||
|
if (folder.keywords.length > 0) {
|
||||||
|
arg.writeAtom("KEYWORD");
|
||||||
|
arg.writeBytes(state.search.getBytes());
|
||||||
|
}
|
||||||
|
arg.writeAtom("ALL");
|
||||||
|
Response[] responses = protocol.command("SEARCH", arg);
|
||||||
|
|
||||||
int msgnum;
|
int msgnum;
|
||||||
List<Integer> msgnums = new ArrayList<>();
|
List<Integer> msgnums = new ArrayList<>();
|
||||||
|
@ -240,18 +226,35 @@ public class ViewModelBrowse extends ViewModel {
|
||||||
imessages[i] = state.ifolder.getMessage(msgnums.get(i));
|
imessages[i] = state.ifolder.getMessage(msgnums.get(i));
|
||||||
|
|
||||||
return imessages;
|
return imessages;
|
||||||
} catch (MessagingException ex) {
|
} else {
|
||||||
Log.e(ex);
|
SearchTerm term = new OrTerm(
|
||||||
return ex;
|
new OrTerm(
|
||||||
|
new FromStringTerm(state.search),
|
||||||
|
new RecipientStringTerm(Message.RecipientType.TO, state.search)
|
||||||
|
),
|
||||||
|
new OrTerm(
|
||||||
|
new SubjectTerm(state.search),
|
||||||
|
new BodyTerm(state.search)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (folder.keywords.length > 0)
|
||||||
|
term = new OrTerm(term, new FlagTerm(
|
||||||
|
new Flags(Helper.sanitizeKeyword(state.search)), true));
|
||||||
|
|
||||||
|
return state.ifolder.search(term);
|
||||||
}
|
}
|
||||||
|
} catch (MessagingException ex) {
|
||||||
|
Log.e(ex);
|
||||||
|
return ex;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (result instanceof Throwable)
|
if (result instanceof MessagingException)
|
||||||
throw (MessagingException) result;
|
throw (MessagingException) result;
|
||||||
|
|
||||||
state.imessages = (Message[]) result;
|
state.imessages = (Message[]) result;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Log.i("Boundary found messages=" + state.imessages.length);
|
Log.i("Boundary found messages=" + state.imessages.length);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue