1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-22 20:32:05 +01:00

Add RegexInterpreterFactory.createDefaultMailDomainRegex()

This commit is contained in:
Paul Schaub 2022-12-01 15:19:57 +01:00
parent 77c669d289
commit fffb4b17a4

View file

@ -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 <pre>pgpainless.org</pre> will return a regex
* that matches any of the following user ids:
* <pre>
* Alice <alice@pgpainless.org>
* <bob@pgpainless.org>
* Issuer (code signing) <issuer@pgpainless.org>
* </pre>
* It will however not match the following mail addresses:
* <pre>
* Alice <alice@example.org>
* alice@pgpainless.org
* alice@pgpainless.org <alice@example.org>
* Bob <bob@PGPainless.org>
* </pre>
* 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 {