Revert "Better search bug workaround"

This reverts commit ca97512a3a.

There is no use in sending UTF-8 searches if the server doesn't support UTF-8
This commit is contained in:
M66B 2019-02-20 15:44:24 +00:00
parent ca97512a3a
commit 622b40209d
1 changed files with 20 additions and 34 deletions

View File

@ -174,7 +174,6 @@ 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
@ -194,7 +193,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 (keywords) { if (folder.keywords.length > 0) {
arg.writeAtom("KEYWORD"); arg.writeAtom("KEYWORD");
arg.writeBytes(state.search.getBytes()); arg.writeBytes(state.search.getBytes());
} }
@ -225,45 +224,32 @@ public class ViewModelBrowse extends ViewModel {
return imessages; return imessages;
} else { } else {
// No UTF-8 support // No UTF-8 support
try { String search = Normalizer
Log.i("Boundary default search=" + state.search); .normalize(state.search, Normalizer.Form.NFD)
return state.ifolder.search(getSearchTerm(state.search, keywords)); .replaceAll("[^\\p{ASCII}]", "");
} catch (MessagingException ex) { Log.i("Boundary ASCII search=" + search);
Log.w(ex); SearchTerm term = new OrTerm(
new OrTerm(
new FromStringTerm(search),
new RecipientStringTerm(Message.RecipientType.TO, search)
),
new OrTerm(
new SubjectTerm(search),
new BodyTerm(search)
)
);
// Workaround: if (folder.keywords.length > 0)
// javax.mail.MessagingException: AE5 BAD Error in IMAP command SEARCH: 8bit data in atom; term = new OrTerm(term, new FlagTerm(
// nested exception is: new Flags(Helper.sanitizeKeyword(search)), true));
// com.sun.mail.iap.BadCommandException: AE5 BAD Error in IMAP command SEARCH: 8bit data in atom
String search = Normalizer return state.ifolder.search(term);
.normalize(state.search, Normalizer.Form.NFD)
.replaceAll("[^\\p{ASCII}]", "");
Log.i("Boundary ASCII search=" + search);
return state.ifolder.search(getSearchTerm(search, keywords));
}
} }
} catch (MessagingException ex) { } catch (MessagingException ex) {
Log.e(ex); Log.e(ex);
return ex; return ex;
} }
} }
private SearchTerm getSearchTerm(String search, boolean keywords) {
SearchTerm term = new OrTerm(
new OrTerm(
new FromStringTerm(search),
new RecipientStringTerm(Message.RecipientType.TO, search)
),
new OrTerm(
new SubjectTerm(search),
new BodyTerm(search)
)
);
if (keywords)
term = new OrTerm(term,
new FlagTerm(new Flags(Helper.sanitizeKeyword(search)), true));
return term;
}
}); });
if (result instanceof MessagingException) if (result instanceof MessagingException)