From 41504e8098a123b5f8f3d83deb41d49829120cef Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 6 Aug 2018 17:31:51 +0000 Subject: [PATCH] Check for host, port, user, password Fixes #19 --- .../java/eu/faircode/email/FragmentAccount.java | 15 +++++++++++---- .../eu/faircode/email/FragmentIdentity.java | 17 +++++++++++++---- app/src/main/res/values/strings.xml | 5 ++++- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentAccount.java b/app/src/main/java/eu/faircode/email/FragmentAccount.java index 98a12b4c..f53f65ee 100644 --- a/app/src/main/java/eu/faircode/email/FragmentAccount.java +++ b/app/src/main/java/eu/faircode/email/FragmentAccount.java @@ -49,7 +49,6 @@ import com.sun.mail.imap.IMAPStore; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Objects; import javax.mail.Folder; import javax.mail.MessagingException; @@ -191,11 +190,19 @@ public class FragmentAccount extends FragmentEx { String host = args.getString("host"); String port = args.getString("port"); String user = args.getString("user"); + String password = args.getString("password"); + + if (TextUtils.isEmpty(host)) + throw new Throwable(getContext().getString(R.string.title_no_host)); + if (TextUtils.isEmpty(port)) + throw new Throwable(getContext().getString(R.string.title_no_port)); + if (TextUtils.isEmpty(user)) + throw new Throwable(getContext().getString(R.string.title_no_user)); + if (TextUtils.isEmpty(password)) + throw new Throwable(getContext().getString(R.string.title_no_password)); if (TextUtils.isEmpty(name)) name = host + "/" + user; - if (TextUtils.isEmpty(port)) - port = "0"; DB db = DB.getInstance(getContext()); EntityAccount account = db.account().getAccount(args.getLong("id")); @@ -206,7 +213,7 @@ public class FragmentAccount extends FragmentEx { account.host = host; account.port = Integer.parseInt(port); account.user = user; - account.password = Objects.requireNonNull(args.getString("password")); + account.password = password; account.synchronize = args.getBoolean("synchronize"); account.primary = (account.synchronize && args.getBoolean("primary")); diff --git a/app/src/main/java/eu/faircode/email/FragmentIdentity.java b/app/src/main/java/eu/faircode/email/FragmentIdentity.java index b19227bd..07b5fff2 100644 --- a/app/src/main/java/eu/faircode/email/FragmentIdentity.java +++ b/app/src/main/java/eu/faircode/email/FragmentIdentity.java @@ -215,11 +215,20 @@ public class FragmentIdentity extends FragmentEx { String host = args.getString("host"); boolean starttls = args.getBoolean("starttls"); String port = args.getString("port"); + String user = args.getString("user"); + String password = args.getString("password"); + + if (TextUtils.isEmpty(host)) + throw new Throwable(getContext().getString(R.string.title_no_host)); + if (TextUtils.isEmpty(port)) + throw new Throwable(getContext().getString(R.string.title_no_port)); + if (TextUtils.isEmpty(user)) + throw new Throwable(getContext().getString(R.string.title_no_user)); + if (TextUtils.isEmpty(password)) + throw new Throwable(getContext().getString(R.string.title_no_password)); if (TextUtils.isEmpty(replyto)) replyto = null; - if (TextUtils.isEmpty(port)) - port = "0"; DB db = DB.getInstance(getContext()); EntityIdentity identity = db.identity().getIdentity(id); @@ -232,8 +241,8 @@ public class FragmentIdentity extends FragmentEx { identity.host = Objects.requireNonNull(host); identity.port = Integer.parseInt(port); identity.starttls = starttls; - identity.user = Objects.requireNonNull(args.getString("user")); - identity.password = Objects.requireNonNull(args.getString("password")); + identity.user = user; + identity.password = password; identity.synchronize = args.getBoolean("synchronize"); identity.primary = (identity.synchronize && args.getBoolean("primary")); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9aa6cef1..6ebb5a45 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -62,7 +62,10 @@ Primary (default identity) Name mandatory Email address mandatory - IDLE not supported + Host name missing + Port number missing + User name missing + Password missing Local drafts %1$s (%2$d/%3$d)