I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Verified Commit 66c4c10a authored by zzz's avatar zzz
Browse files

Console: Improve parsing of email address (part 2)

parent 16396731
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,8 @@ import java.util.Locale; ...@@ -9,6 +9,8 @@ import java.util.Locale;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.i2p.app.ClientApp; import net.i2p.app.ClientApp;
import net.i2p.app.ClientAppState; import net.i2p.app.ClientAppState;
...@@ -37,6 +39,15 @@ public class ConfigClientsHelper extends HelperBase { ...@@ -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_CLIENT_CHANGE = "routerconsole.enableClientChange";
public static final String PROP_ENABLE_PLUGIN_INSTALL = "routerconsole.enablePluginInstall"; 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() {} public ConfigClientsHelper() {}
/** @since 0.9.14.1 */ /** @since 0.9.14.1 */
...@@ -303,14 +314,8 @@ public class ConfigClientsHelper extends HelperBase { ...@@ -303,14 +314,8 @@ public class ConfigClientsHelper extends HelperBase {
s = stripHTML(appProps, "author"); s = stripHTML(appProps, "author");
if (s != null) { if (s != null) {
String[] authors = DataHelper.split(s, "[,; \r\n\t]"); String[] authors = DataHelper.split(s, "[,; \r\n\t]");
String author = null; Matcher m = VALID_EMAIL_ADDRESS_REGEX.matcher(s);
for (int i = 0; i < authors.length; i++) { String author = m.find() ? m.group() : null;
String a = authors[i];
if (a.indexOf('@') > 0 && a.indexOf('.') > 0) {
author = a;
break;
}
}
desc.append("<tr><td><b>") desc.append("<tr><td><b>")
.append(_t("Author")).append("</b></td><td>"); .append(_t("Author")).append("</b></td><td>");
if (author != null) if (author != null)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment