From eaa219671674c66802fc6183845043d9f87dfd01 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 14 Dec 2019 16:54:34 +0100 Subject: [PATCH] Should or should not? --- .../eu/faircode/email/FragmentAccount.java | 21 +++++-- .../eu/faircode/email/FragmentIdentity.java | 56 +++++++++++++------ 2 files changed, 55 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentAccount.java b/app/src/main/java/eu/faircode/email/FragmentAccount.java index cf08627063..cdbaffb27b 100644 --- a/app/src/main/java/eu/faircode/email/FragmentAccount.java +++ b/app/src/main/java/eu/faircode/email/FragmentAccount.java @@ -792,14 +792,23 @@ public class FragmentAccount extends FragmentBase { host = h.getHost(); } - if (!should && TextUtils.isEmpty(host)) - throw new IllegalArgumentException(context.getString(R.string.title_no_host)); + if (TextUtils.isEmpty(host)) + if (should) + return true; + else + throw new IllegalArgumentException(context.getString(R.string.title_no_host)); if (TextUtils.isEmpty(port)) port = (starttls ? "143" : "993"); - if (!should && TextUtils.isEmpty(user)) - throw new IllegalArgumentException(context.getString(R.string.title_no_user)); - if (!should && synchronize && TextUtils.isEmpty(password) && !insecure) - throw new IllegalArgumentException(context.getString(R.string.title_no_password)); + if (TextUtils.isEmpty(user)) + if (should) + return true; + else + throw new IllegalArgumentException(context.getString(R.string.title_no_user)); + if (synchronize && TextUtils.isEmpty(password) && !insecure) + if (should) + return true; + else + throw new IllegalArgumentException(context.getString(R.string.title_no_password)); if (TextUtils.isEmpty(interval)) interval = Integer.toString(EntityAccount.DEFAULT_KEEP_ALIVE_INTERVAL); diff --git a/app/src/main/java/eu/faircode/email/FragmentIdentity.java b/app/src/main/java/eu/faircode/email/FragmentIdentity.java index ae3d981afc..115328d900 100644 --- a/app/src/main/java/eu/faircode/email/FragmentIdentity.java +++ b/app/src/main/java/eu/faircode/email/FragmentIdentity.java @@ -577,35 +577,59 @@ public class FragmentIdentity extends FragmentBase { host = h.getHost(); } - if (!should && TextUtils.isEmpty(name)) - throw new IllegalArgumentException(context.getString(R.string.title_no_name)); - if (!should && TextUtils.isEmpty(email)) - throw new IllegalArgumentException(context.getString(R.string.title_no_email)); - if (!should && !Patterns.EMAIL_ADDRESS.matcher(email).matches()) - throw new IllegalArgumentException(context.getString(R.string.title_email_invalid, email)); - if (!should && TextUtils.isEmpty(host)) - throw new IllegalArgumentException(context.getString(R.string.title_no_host)); + if (TextUtils.isEmpty(name)) + if (should) + return true; + else + throw new IllegalArgumentException(context.getString(R.string.title_no_name)); + if (TextUtils.isEmpty(email)) + if (should) + return true; + else + throw new IllegalArgumentException(context.getString(R.string.title_no_email)); + if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) + if (should) + return true; + else + throw new IllegalArgumentException(context.getString(R.string.title_email_invalid, email)); + if (TextUtils.isEmpty(host)) + if (should) + return true; + else + throw new IllegalArgumentException(context.getString(R.string.title_no_host)); if (TextUtils.isEmpty(port)) port = (starttls ? "587" : "465"); - if (!should && TextUtils.isEmpty(user)) - throw new IllegalArgumentException(context.getString(R.string.title_no_user)); - if (!should && synchronize && TextUtils.isEmpty(password) && !insecure) - throw new IllegalArgumentException(context.getString(R.string.title_no_password)); + if (TextUtils.isEmpty(user)) + if (should) + return true; + else + throw new IllegalArgumentException(context.getString(R.string.title_no_user)); + if (synchronize && TextUtils.isEmpty(password) && !insecure) + if (should) + return true; + else + throw new IllegalArgumentException(context.getString(R.string.title_no_password)); - if (!should && !TextUtils.isEmpty(replyto)) { + if (!TextUtils.isEmpty(replyto)) { try { InternetAddress[] addresses = InternetAddress.parse(replyto); if (addresses.length != 1) throw new AddressException(); } catch (AddressException ex) { - throw new IllegalArgumentException(context.getString(R.string.title_email_invalid, replyto)); + if (should) + return true; + else + throw new IllegalArgumentException(context.getString(R.string.title_email_invalid, replyto)); } } - if (!should && !TextUtils.isEmpty(bcc)) + if (!TextUtils.isEmpty(bcc)) try { InternetAddress.parse(bcc); } catch (AddressException ex) { - throw new IllegalArgumentException(context.getString(R.string.title_email_invalid, bcc)); + if (should) + return true; + else + throw new IllegalArgumentException(context.getString(R.string.title_email_invalid, bcc)); } if (TextUtils.isEmpty(display))