From fffb4b17a402f0a5222b76af9633a4ea3eef0877 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Thu, 1 Dec 2022 15:19:57 +0100 Subject: [PATCH] Add RegexInterpreterFactory.createDefaultMailDomainRegex() --- .../algorithm/RegexInterpreterFactory.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) 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 {