diff --git a/FAQ.md b/FAQ.md index 6ab419fb90..30d2653634 100644 --- a/FAQ.md +++ b/FAQ.md @@ -1204,6 +1204,8 @@ It is possible to configure a [regex](https://en.wikipedia.org/wiki/Regular_expr to match the username of an email address (the part before the @ sign). Note that the domain name (the parts after the @ sign) always needs to be equal to the domain name of the identity. +if you specify the domain part in your expression, the pattern has to match the domain part of the identity, otherwise, +the matching will always fail (except for the address of the identity itself). If you like to match the special purpose email addresses abc@example.com and xyx@example.com and like to have a fallback email address main@example.com as well, you could do something like this: diff --git a/app/src/main/java/eu/faircode/email/EntityIdentity.java b/app/src/main/java/eu/faircode/email/EntityIdentity.java index 35f5c54a3b..73e36037f9 100644 --- a/app/src/main/java/eu/faircode/email/EntityIdentity.java +++ b/app/src/main/java/eu/faircode/email/EntityIdentity.java @@ -154,7 +154,14 @@ public class EntityIdentity { if (user.equalsIgnoreCase(cemail[0])) return true; } else { - if (Pattern.matches(sender_extra_regex, cother[0])) + /* match by regex + * if the expression contains @, assume the pattern also contains the domain part. + * if no @ is contained, assume only the local part should be matched. + * Domain part must match identity domain part in any case, else + * this is never reached ( see cother[1] comparison above) + */ + String matchInput = (sender_extra_regex.contains("@") ? matchInput = other : cother[0]; + if (Pattern.matches(sender_extra_regex, matchInput)) return true; }