Allow unicode email addresses

pull/194/merge
M66B 4 years ago
parent 65b896dfb5
commit 2c68acc2f4

@ -70,7 +70,6 @@ import java.security.cert.X509Certificate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.regex.Pattern;
import javax.mail.internet.AddressException; import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress; import javax.mail.internet.InternetAddress;
@ -758,11 +757,8 @@ public class FragmentIdentity extends FragmentBase {
// throw new IllegalArgumentException(context.getString(R.string.title_no_name)); // throw new IllegalArgumentException(context.getString(R.string.title_no_name));
if (TextUtils.isEmpty(email) && !should) if (TextUtils.isEmpty(email) && !should)
throw new IllegalArgumentException(context.getString(R.string.title_no_email)); throw new IllegalArgumentException(context.getString(R.string.title_no_email));
if (!Helper.EMAIL_ADDRESS.matcher(email).matches() && !should)
Pattern pattern = (unicode ? Helper.EMAIL_ADDRESS_UNICODE : Helper.EMAIL_ADDRESS);
if (!pattern.matcher(email).matches() && !should)
throw new IllegalArgumentException(context.getString(R.string.title_email_invalid, email)); throw new IllegalArgumentException(context.getString(R.string.title_email_invalid, email));
if (TextUtils.isEmpty(host) && !should) if (TextUtils.isEmpty(host) && !should)
throw new IllegalArgumentException(context.getString(R.string.title_no_host)); throw new IllegalArgumentException(context.getString(R.string.title_no_host));
if (TextUtils.isEmpty(port)) if (TextUtils.isEmpty(port))

@ -195,21 +195,13 @@ public class Helper {
static final Pattern EMAIL_ADDRESS = Pattern.compile( static final Pattern EMAIL_ADDRESS = Pattern.compile(
"[\\S]{1,256}" + "[\\S]{1,256}" +
"\\@" + "\\@" +
"[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" + "[\\p{L}][\\p{L}0-9\\-\\_]{0,64}" +
"(" + "(" +
"\\." + "\\." +
"[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" + "[\\p{L}0-9][\\p{L}0-9\\-\\_]{0,25}" +
")+" ")+"
); );
static final Pattern EMAIL_ADDRESS_UNICODE = Pattern.compile(
"([\\p{L}\\_\\.\\-\\d]+)" +
"@" +
"([\\p{L}\\-\\.\\d]+)" +
"((\\.(\\p{L}){2,63})+)"
// ^([\p{L}\_\.\-\d]+)@([\p{L}\-\.\d]+)((\.(\p{L}){2,63})+)$
);
private static final ExecutorService executor = getBackgroundExecutor(1, "helper"); private static final ExecutorService executor = getBackgroundExecutor(1, "helper");
static ExecutorService getBackgroundExecutor(int threads, final String name) { static ExecutorService getBackgroundExecutor(int threads, final String name) {

Loading…
Cancel
Save