diff --git a/app/src/main/java/eu/faircode/email/FragmentGmail.java b/app/src/main/java/eu/faircode/email/FragmentGmail.java index c8f55e0921..ce23e4cbb9 100644 --- a/app/src/main/java/eu/faircode/email/FragmentGmail.java +++ b/app/src/main/java/eu/faircode/email/FragmentGmail.java @@ -300,7 +300,7 @@ public class FragmentGmail extends FragmentBase { String password = args.getString("password"); // Safety checks - if (!Patterns.EMAIL_ADDRESS.matcher(user).matches()) + if (!Helper.EMAIL_ADDRESS.matcher(user).matches()) throw new IllegalArgumentException(context.getString(R.string.title_email_invalid, user)); if (TextUtils.isEmpty(password)) throw new IllegalArgumentException(context.getString(R.string.title_no_password)); diff --git a/app/src/main/java/eu/faircode/email/FragmentIdentity.java b/app/src/main/java/eu/faircode/email/FragmentIdentity.java index 10000813b0..890737b257 100644 --- a/app/src/main/java/eu/faircode/email/FragmentIdentity.java +++ b/app/src/main/java/eu/faircode/email/FragmentIdentity.java @@ -657,7 +657,7 @@ public class FragmentIdentity extends FragmentBase { throw new IllegalArgumentException(context.getString(R.string.title_no_name)); if (TextUtils.isEmpty(email) && !should) throw new IllegalArgumentException(context.getString(R.string.title_no_email)); - if (!Patterns.EMAIL_ADDRESS.matcher(email).matches() && !should) + if (!Helper.EMAIL_ADDRESS.matcher(email).matches() && !should) throw new IllegalArgumentException(context.getString(R.string.title_email_invalid, email)); if (TextUtils.isEmpty(host) && !should) throw new IllegalArgumentException(context.getString(R.string.title_no_host)); diff --git a/app/src/main/java/eu/faircode/email/FragmentOAuth.java b/app/src/main/java/eu/faircode/email/FragmentOAuth.java index 9b37889b6a..50ff412102 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOAuth.java +++ b/app/src/main/java/eu/faircode/email/FragmentOAuth.java @@ -217,7 +217,7 @@ public class FragmentOAuth extends FragmentBase { if (TextUtils.isEmpty(email)) throw new IllegalArgumentException(getString(R.string.title_no_email)); - if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) + if (!Helper.EMAIL_ADDRESS.matcher(email).matches()) throw new IllegalArgumentException(getString(R.string.title_email_invalid, email)); } diff --git a/app/src/main/java/eu/faircode/email/FragmentQuickSetup.java b/app/src/main/java/eu/faircode/email/FragmentQuickSetup.java index ed067a1c5a..508057ab3f 100644 --- a/app/src/main/java/eu/faircode/email/FragmentQuickSetup.java +++ b/app/src/main/java/eu/faircode/email/FragmentQuickSetup.java @@ -256,7 +256,7 @@ public class FragmentQuickSetup extends FragmentBase { throw new IllegalArgumentException(context.getString(R.string.title_no_name)); if (TextUtils.isEmpty(email)) throw new IllegalArgumentException(context.getString(R.string.title_no_email)); - if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) + if (!Helper.EMAIL_ADDRESS.matcher(email).matches()) throw new IllegalArgumentException(context.getString(R.string.title_email_invalid, email)); if (TextUtils.isEmpty(password)) throw new IllegalArgumentException(context.getString(R.string.title_no_password)); diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index c3583c44f0..4d874a1411 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -127,6 +127,7 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicInteger; +import java.util.regex.Pattern; import static android.os.Process.THREAD_PRIORITY_BACKGROUND; import static androidx.browser.customtabs.CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION; @@ -151,6 +152,17 @@ public class Helper { static final String CROWDIN_URI = "https://crowdin.com/project/open-source-email"; static final String GRAVATAR_PRIVACY_URI = "https://meta.stackexchange.com/questions/44717/is-gravatar-a-privacy-risk"; + static final Pattern EMAIL_ADDRESS + = Pattern.compile( + "[\\S]{1,256}" + + "\\@" + + "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" + + "(" + + "\\." + + "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" + + ")+" + ); + static ExecutorService getBackgroundExecutor(int threads, final String name) { ThreadFactory factory = new ThreadFactory() { private final AtomicInteger threadId = new AtomicInteger();