From 11be0780fde62dd6e139e700e0103510e9adf394 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 10 Dec 2018 13:14:15 +0100 Subject: [PATCH] Better keyword sanitize --- .../main/java/eu/faircode/email/Helper.java | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) 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(); } }