mirror of https://github.com/M66B/FairEmail.git
Better search bug workaround
This commit is contained in:
parent
9c8c937026
commit
ca97512a3a
|
@ -174,6 +174,7 @@ public class ViewModelBrowse extends ViewModel {
|
||||||
@Override
|
@Override
|
||||||
public Object doCommand(IMAPProtocol protocol) {
|
public Object doCommand(IMAPProtocol protocol) {
|
||||||
try {
|
try {
|
||||||
|
boolean keywords = (folder.keywords.length > 0);
|
||||||
if (protocol.supportsUtf8()) {
|
if (protocol.supportsUtf8()) {
|
||||||
// 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
|
||||||
|
@ -193,7 +194,7 @@ public class ViewModelBrowse extends ViewModel {
|
||||||
arg.writeBytes(state.search.getBytes());
|
arg.writeBytes(state.search.getBytes());
|
||||||
arg.writeAtom("BODY");
|
arg.writeAtom("BODY");
|
||||||
arg.writeBytes(state.search.getBytes());
|
arg.writeBytes(state.search.getBytes());
|
||||||
if (folder.keywords.length > 0) {
|
if (keywords) {
|
||||||
arg.writeAtom("KEYWORD");
|
arg.writeAtom("KEYWORD");
|
||||||
arg.writeBytes(state.search.getBytes());
|
arg.writeBytes(state.search.getBytes());
|
||||||
}
|
}
|
||||||
|
@ -224,10 +225,30 @@ public class ViewModelBrowse extends ViewModel {
|
||||||
return imessages;
|
return imessages;
|
||||||
} else {
|
} else {
|
||||||
// No UTF-8 support
|
// No UTF-8 support
|
||||||
|
try {
|
||||||
|
Log.i("Boundary default search=" + state.search);
|
||||||
|
return state.ifolder.search(getSearchTerm(state.search, keywords));
|
||||||
|
} catch (MessagingException ex) {
|
||||||
|
Log.w(ex);
|
||||||
|
|
||||||
|
// Workaround:
|
||||||
|
// javax.mail.MessagingException: AE5 BAD Error in IMAP command SEARCH: 8bit data in atom;
|
||||||
|
// nested exception is:
|
||||||
|
// com.sun.mail.iap.BadCommandException: AE5 BAD Error in IMAP command SEARCH: 8bit data in atom
|
||||||
String search = Normalizer
|
String search = Normalizer
|
||||||
.normalize(state.search, Normalizer.Form.NFD)
|
.normalize(state.search, Normalizer.Form.NFD)
|
||||||
.replaceAll("[^\\p{ASCII}]", "");
|
.replaceAll("[^\\p{ASCII}]", "");
|
||||||
Log.i("Boundary ASCII search=" + search);
|
Log.i("Boundary ASCII search=" + search);
|
||||||
|
return state.ifolder.search(getSearchTerm(search, keywords));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (MessagingException ex) {
|
||||||
|
Log.e(ex);
|
||||||
|
return ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private SearchTerm getSearchTerm(String search, boolean keywords) {
|
||||||
SearchTerm term = new OrTerm(
|
SearchTerm term = new OrTerm(
|
||||||
new OrTerm(
|
new OrTerm(
|
||||||
new FromStringTerm(search),
|
new FromStringTerm(search),
|
||||||
|
@ -238,17 +259,10 @@ public class ViewModelBrowse extends ViewModel {
|
||||||
new BodyTerm(search)
|
new BodyTerm(search)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
if (keywords)
|
||||||
if (folder.keywords.length > 0)
|
term = new OrTerm(term,
|
||||||
term = new OrTerm(term, new FlagTerm(
|
new FlagTerm(new Flags(Helper.sanitizeKeyword(search)), true));
|
||||||
new Flags(Helper.sanitizeKeyword(search)), true));
|
return term;
|
||||||
|
|
||||||
return state.ifolder.search(term);
|
|
||||||
}
|
|
||||||
} catch (MessagingException ex) {
|
|
||||||
Log.e(ex);
|
|
||||||
return ex;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue