diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index f16ea30f2a..0ed7cdb03d 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -619,7 +619,27 @@ public class Helper { } static String sanitizeKeyword(String keyword) { - // ()}%*"\] - return keyword.replaceAll("[^A-Za-z0-9$_.]", ""); + // https://tools.ietf.org/html/rfc3501 + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < keyword.length(); i++) { + // flag-keyword = atom + // atom = 1*ATOM-CHAR + // ATOM-CHAR = + Character kar = keyword.charAt(i); + // atom-specials = "(" / ")" / "{" / SP / CTL / list-wildcards / quoted-specials / resp-specials + if (kar == '(' || kar == ')' || kar == '{' || kar == ' ' || Character.isISOControl(kar)) + continue; + // list-wildcards = "%" / "*" + if (kar == '%' || kar == '*') + continue; + // quoted-specials = DQUOTE / "\" + if (kar == '"' || kar == '\\') + continue; + // resp-specials = "]" + if (kar == ']') + continue; + sb.append(kar); + } + return sb.toString(); } }