Console: Improve parsing of email address (part 2)

This commit is contained in:
zzz
2021-01-10 08:03:15 -05:00
parent 163967311e
commit 66c4c10a78

View File

@@ -9,6 +9,8 @@ import java.util.Locale;
import java.util.Properties;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.i2p.app.ClientApp;
import net.i2p.app.ClientAppState;
@@ -37,6 +39,15 @@ public class ConfigClientsHelper extends HelperBase {
public static final String PROP_ENABLE_CLIENT_CHANGE = "routerconsole.enableClientChange";
public static final String PROP_ENABLE_PLUGIN_INSTALL = "routerconsole.enablePluginInstall";
/**
* simple regex from
* https://stackoverflow.com/questions/8204680/java-regex-email
* not the massive RFC 822 compliant one
* modified so .i2p will work
*/
private static final Pattern VALID_EMAIL_ADDRESS_REGEX =
Pattern.compile("[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z2]{2,6}", Pattern.CASE_INSENSITIVE);
public ConfigClientsHelper() {}
/** @since 0.9.14.1 */
@@ -303,14 +314,8 @@ public class ConfigClientsHelper extends HelperBase {
s = stripHTML(appProps, "author");
if (s != null) {
String[] authors = DataHelper.split(s, "[,; \r\n\t]");
String author = null;
for (int i = 0; i < authors.length; i++) {
String a = authors[i];
if (a.indexOf('@') > 0 && a.indexOf('.') > 0) {
author = a;
break;
}
}
Matcher m = VALID_EMAIL_ADDRESS_REGEX.matcher(s);
String author = m.find() ? m.group() : null;
desc.append("<tr><td><b>")
.append(_t("Author")).append("</b></td><td>");
if (author != null)