diff --git a/FAQ.md b/FAQ.md index 183774cba8..639a431773 100644 --- a/FAQ.md +++ b/FAQ.md @@ -1146,6 +1146,16 @@ This will result in searching like this: ("apple" AND "banana" AND NOT "cherry") OR "nuts" ``` +Since version 1.1979 it is possible to use these prefixes as a search expression: + +``` +from: +to: +keyword: +``` + +There should be no space between the prefix and the search term, which will be applied as an AND-condition. + Search expressions can be used for searching on the email server only, and not for searching on the device. Since version 1.1733 it is possible to save searches, which means that a named entry in the navigation menu will be created to repeat the same search later. diff --git a/app/src/main/java/eu/faircode/email/BoundaryCallbackMessages.java b/app/src/main/java/eu/faircode/email/BoundaryCallbackMessages.java index 00cd37434a..bbebd178fe 100644 --- a/app/src/main/java/eu/faircode/email/BoundaryCallbackMessages.java +++ b/app/src/main/java/eu/faircode/email/BoundaryCallbackMessages.java @@ -885,6 +885,8 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback FROM.length() && w.startsWith(FROM)) return true; + else if (w.length() > TO.length() && w.startsWith(TO)) + return true; + else if (w.length() > KEYWORD.length() && w.startsWith(KEYWORD)) + return true; return false; } @@ -923,7 +929,9 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback plus = new ArrayList<>(); List minus = new ArrayList<>(); List opt = new ArrayList<>(); - List from = new ArrayList<>(); + List andFrom = new ArrayList<>(); + List andTo = new ArrayList<>(); + List andKeyword = new ArrayList<>(); StringBuilder all = new StringBuilder(); for (String w : search.trim().split("\\s+")) { if (all.length() > 0) @@ -938,15 +946,20 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback 1 && w.startsWith("?")) { opt.add(w.substring(1)); all.append(w.substring(1)); - } else if (w.length() > FROM.length() && w.startsWith(FROM)) { - from.add(w.substring(FROM.length())); - } else { + } else if (w.length() > FROM.length() && w.startsWith(FROM)) + andFrom.add(w.substring(FROM.length())); + else if (w.length() > TO.length() && w.startsWith(TO)) + andTo.add(w.substring(TO.length())); + else if (w.length() > KEYWORD.length() && w.startsWith(KEYWORD)) + andKeyword.add(w.substring(KEYWORD.length())); + else { word.add(w); all.append(w); } } - if (plus.size() + minus.size() + opt.size() + from.size() > 0) + if (plus.size() + minus.size() + opt.size() + + andFrom.size() + andTo.size() + andKeyword.size() > 0) search = all.toString(); // Yahoo! does not support keyword search, but uses the flags $Forwarded $Junk $NotJunk @@ -957,21 +970,26 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback 0) { - for (String term : from) + if (andFrom.size() > 0) { + for (String term : andFrom) and.add(new FromStringTerm(term)); } else { - if (in_senders) + if (in_senders && !TextUtils.isEmpty(search)) or.add(new FromStringTerm(search)); } - if (in_recipients) { - or.add(new RecipientStringTerm(Message.RecipientType.TO, search)); - or.add(new RecipientStringTerm(Message.RecipientType.CC, search)); - or.add(new RecipientStringTerm(Message.RecipientType.BCC, search)); + if (andTo.size() > 0) { + for (String term : andTo) + and.add(new RecipientStringTerm(Message.RecipientType.TO, term)); + } else { + if (in_recipients && !TextUtils.isEmpty(search)) { + or.add(new RecipientStringTerm(Message.RecipientType.TO, search)); + or.add(new RecipientStringTerm(Message.RecipientType.CC, search)); + or.add(new RecipientStringTerm(Message.RecipientType.BCC, search)); + } } - if (in_subject) + if (in_subject && !TextUtils.isEmpty(search)) if (plus.size() + minus.size() + opt.size() == 0) or.add(new SubjectTerm(search)); else @@ -982,15 +1000,21 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback