diff --git a/pgpainless-core/src/main/java/org/pgpainless/algorithm/RegexInterpreterFactory.java b/pgpainless-core/src/main/java/org/pgpainless/algorithm/RegexInterpreterFactory.java index 266a245c..426b6c49 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/algorithm/RegexInterpreterFactory.java +++ b/pgpainless-core/src/main/java/org/pgpainless/algorithm/RegexInterpreterFactory.java @@ -4,8 +4,8 @@ package org.pgpainless.algorithm; -import javax.annotation.Nonnull; import java.util.regex.Pattern; +import javax.annotation.Nonnull; public abstract class RegexInterpreterFactory { @@ -26,6 +26,32 @@ public abstract class RegexInterpreterFactory { return getInstance().instantiate(regex); } + /** + * Regex that matches any mail address on the given mail server. + * For example, calling this method with parameter
pgpainless.org
will return a regex + * that matches any of the following user ids: + *
+     *     Alice 
+     *     
+     *     Issuer (code signing) 
+     * 
+ * It will however not match the following mail addresses: + *
+     *     Alice 
+     *     alice@pgpainless.org
+     *     alice@pgpainless.org 
+     *     Bob 
+     * 
+ * Note: This method will not validate the given domain string, so that is your responsibility! + * + * @param mailDomain domain + * @return regex matching the domain + */ + public static Regex createDefaultMailDomainRegex(String mailDomain) { + String escaped = mailDomain.replace(".", "\\."); + return create("<[^>]+[@.]" + escaped + ">$"); + } + public abstract Regex instantiate(String regex) throws IllegalArgumentException; public static class JavaRegexInterpreterFactory extends RegexInterpreterFactory {