From bcd668a622376709422d0912131d39c45e6d8f7b Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 23 Aug 2020 09:28:10 +0200 Subject: [PATCH] Added encryption none --- .../java/eu/faircode/email/ActivityEML.java | 2 +- .../email/BoundaryCallbackMessages.java | 2 +- .../java/eu/faircode/email/EmailService.java | 59 +++++--------- .../java/eu/faircode/email/EntityAccount.java | 17 +++-- .../eu/faircode/email/EntityIdentity.java | 16 ++-- .../eu/faircode/email/FragmentAccount.java | 76 +++++++++++-------- .../java/eu/faircode/email/FragmentGmail.java | 16 ++-- .../eu/faircode/email/FragmentIdentity.java | 50 ++++++------ .../java/eu/faircode/email/FragmentOAuth.java | 16 ++-- .../java/eu/faircode/email/FragmentPop.java | 39 ++++++++-- .../eu/faircode/email/FragmentQuickSetup.java | 15 ++-- .../java/eu/faircode/email/ServiceSend.java | 2 +- .../eu/faircode/email/ServiceSynchronize.java | 2 +- .../eu/faircode/email/TupleAccountState.java | 2 +- app/src/main/res/layout/fragment_account.xml | 30 ++++++-- app/src/main/res/layout/fragment_identity.xml | 30 ++++++-- app/src/main/res/layout/fragment_pop.xml | 28 +++++-- app/src/main/res/values/strings.xml | 6 +- 18 files changed, 247 insertions(+), 161 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivityEML.java b/app/src/main/java/eu/faircode/email/ActivityEML.java index a08a3262af..55a3b0c4f6 100644 --- a/app/src/main/java/eu/faircode/email/ActivityEML.java +++ b/app/src/main/java/eu/faircode/email/ActivityEML.java @@ -425,7 +425,7 @@ public class ActivityEML extends ActivityBase { MimeMessage imessage = new MimeMessage(isession, is); try (EmailService iservice = new EmailService( - context, account.getProtocol(), account.realm, account.insecure, true)) { + context, account.getProtocol(), account.realm, account.encryption, account.insecure, true)) { iservice.setPartialFetch(account.partial_fetch); iservice.setIgnoreBodyStructureSize(account.ignore_size); iservice.connect(account); diff --git a/app/src/main/java/eu/faircode/email/BoundaryCallbackMessages.java b/app/src/main/java/eu/faircode/email/BoundaryCallbackMessages.java index bc196005e4..c486801b63 100644 --- a/app/src/main/java/eu/faircode/email/BoundaryCallbackMessages.java +++ b/app/src/main/java/eu/faircode/email/BoundaryCallbackMessages.java @@ -330,7 +330,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback 0 ? View.VISIBLE : View.GONE); grpAuthorize.setVisibility(position > 0 ? View.VISIBLE : View.GONE); @@ -319,18 +317,7 @@ public class FragmentAccount extends FragmentBase { rgEncryption.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int id) { - etPort.setHint(id == R.id.radio_starttls ? "143" : "993"); - } - }); - - cbInsecure.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - Object tag = cbInsecure.getTag(); - if (tag != null && tag.equals(isChecked)) - return; - if (isChecked) - rgEncryption.check(R.id.radio_starttls); + etPort.setHint(id == R.id.radio_ssl ? "993" : "143"); } }); @@ -522,7 +509,7 @@ public class FragmentAccount extends FragmentBase { // Initialize Helper.setViewsEnabled(view, false); - tvGmailHint.setVisibility(GONE); + tvGmailHint.setVisibility(View.GONE); btnAutoConfig.setEnabled(false); pbAutoConfig.setVisibility(View.GONE); @@ -556,7 +543,7 @@ public class FragmentAccount extends FragmentBase { grpFolders.setVisibility(View.GONE); grpError.setVisibility(View.GONE); - pbWait.setVisibility(VISIBLE); + pbWait.setVisibility(View.VISIBLE); return view; } @@ -605,10 +592,18 @@ public class FragmentAccount extends FragmentBase { } private void onCheck() { + int encryption; + if (rgEncryption.getCheckedRadioButtonId() == R.id.radio_starttls) + encryption = EmailService.ENCRYPTION_STARTTLS; + else if (rgEncryption.getCheckedRadioButtonId() == R.id.radio_none) + encryption = EmailService.ENCRYPTION_NONE; + else + encryption = EmailService.ENCRYPTION_SSL; + Bundle args = new Bundle(); args.putLong("id", id); args.putString("host", etHost.getText().toString().trim()); - args.putBoolean("starttls", rgEncryption.getCheckedRadioButtonId() == R.id.radio_starttls); + args.putInt("encryption", encryption); args.putBoolean("insecure", cbInsecure.isChecked()); args.putString("port", etPort.getText().toString()); args.putInt("auth", auth); @@ -647,7 +642,7 @@ public class FragmentAccount extends FragmentBase { protected CheckResult onExecute(Context context, Bundle args) throws Throwable { long id = args.getLong("id"); String host = args.getString("host"); - boolean starttls = args.getBoolean("starttls"); + int encryption = args.getInt("encryption"); boolean insecure = args.getBoolean("insecure"); String port = args.getString("port"); int auth = args.getInt("auth"); @@ -666,7 +661,7 @@ public class FragmentAccount extends FragmentBase { if (TextUtils.isEmpty(host)) throw new IllegalArgumentException(context.getString(R.string.title_no_host)); if (TextUtils.isEmpty(port)) - port = (starttls ? "143" : "993"); + port = (encryption == EmailService.ENCRYPTION_SSL ? "993" : "143"); if (TextUtils.isEmpty(user)) throw new IllegalArgumentException(context.getString(R.string.title_no_user)); if (TextUtils.isEmpty(password) && !insecure && certificate == null) @@ -682,9 +677,10 @@ public class FragmentAccount extends FragmentBase { result.folders = new ArrayList<>(); // Check IMAP server / get folders - String protocol = "imap" + (starttls ? "" : "s"); + String protocol = "imap" + (encryption == EmailService.ENCRYPTION_SSL ? "s" : ""); try (EmailService iservice = new EmailService( - context, protocol, realm, insecure, EmailService.PURPOSE_CHECK, true)) { + context, protocol, realm, encryption, insecure, + EmailService.PURPOSE_CHECK, true)) { iservice.connect( host, Integer.parseInt(port), auth, provider, @@ -809,8 +805,16 @@ public class FragmentAccount extends FragmentBase { Bundle args = new Bundle(); args.putLong("id", id); + int encryption; + if (rgEncryption.getCheckedRadioButtonId() == R.id.radio_starttls) + encryption = EmailService.ENCRYPTION_STARTTLS; + else if (rgEncryption.getCheckedRadioButtonId() == R.id.radio_none) + encryption = EmailService.ENCRYPTION_NONE; + else + encryption = EmailService.ENCRYPTION_SSL; + args.putString("host", etHost.getText().toString().trim()); - args.putBoolean("starttls", rgEncryption.getCheckedRadioButtonId() == R.id.radio_starttls); + args.putInt("encryption", encryption); args.putBoolean("insecure", cbInsecure.isChecked()); args.putString("port", etPort.getText().toString()); args.putInt("auth", auth); @@ -873,7 +877,7 @@ public class FragmentAccount extends FragmentBase { long id = args.getLong("id"); String host = args.getString("host"); - boolean starttls = args.getBoolean("starttls"); + int encryption = args.getInt("encryption"); boolean insecure = args.getBoolean("insecure"); String port = args.getString("port"); int auth = args.getInt("auth"); @@ -919,7 +923,7 @@ public class FragmentAccount extends FragmentBase { if (TextUtils.isEmpty(host) && !should) throw new IllegalArgumentException(context.getString(R.string.title_no_host)); if (TextUtils.isEmpty(port)) - port = (starttls ? "143" : "993"); + port = (encryption == EmailService.ENCRYPTION_SSL ? "993" : "143"); if (TextUtils.isEmpty(user) && !should) throw new IllegalArgumentException(context.getString(R.string.title_no_user)); if (synchronize && TextUtils.isEmpty(password) && !insecure && certificate == null && !should) @@ -947,7 +951,7 @@ public class FragmentAccount extends FragmentBase { if (!Objects.equals(account.host, host)) return true; - if (!Objects.equals(account.starttls, starttls)) + if (!Objects.equals(account.encryption, encryption)) return true; if (!Objects.equals(account.insecure, insecure)) return true; @@ -1029,7 +1033,7 @@ public class FragmentAccount extends FragmentBase { !account.synchronize || account.error != null || !account.host.equals(host) || - !account.starttls.equals(starttls) || + !account.encryption.equals(encryption) || !account.insecure.equals(insecure) || !account.port.equals(Integer.parseInt(port)) || !account.user.equals(user) || @@ -1047,9 +1051,10 @@ public class FragmentAccount extends FragmentBase { // Check IMAP server EntityFolder inbox = null; if (check) { - String protocol = "imap" + (starttls ? "" : "s"); + String protocol = "imap" + (encryption == EmailService.ENCRYPTION_SSL ? "s" : ""); try (EmailService iservice = new EmailService( - context, protocol, realm, insecure, EmailService.PURPOSE_CHECK, true)) { + context, protocol, realm, encryption, insecure, + EmailService.PURPOSE_CHECK, true)) { iservice.connect( host, Integer.parseInt(port), auth, provider, @@ -1092,7 +1097,7 @@ public class FragmentAccount extends FragmentBase { account = new EntityAccount(); account.host = host; - account.starttls = starttls; + account.encryption = encryption; account.insecure = insecure; account.port = Integer.parseInt(port); account.auth_type = auth; @@ -1446,7 +1451,7 @@ public class FragmentAccount extends FragmentBase { EmailProvider provider = providers.get(pos); if (provider.imap.host.equals(account.host) && provider.imap.port == account.port && - provider.imap.starttls == account.starttls) { + provider.imap.starttls == (account.encryption == EmailService.ENCRYPTION_STARTTLS)) { found = true; spProvider.setTag(pos); spProvider.setSelection(pos); @@ -1461,8 +1466,13 @@ public class FragmentAccount extends FragmentBase { etPort.setText(Long.toString(account.port)); } - rgEncryption.check(account != null && account.starttls ? R.id.radio_starttls : R.id.radio_ssl); - cbInsecure.setTag(account == null ? false : account.insecure); + if (account != null && account.encryption == EmailService.ENCRYPTION_STARTTLS) + rgEncryption.check(R.id.radio_starttls); + else if (account != null && account.encryption == EmailService.ENCRYPTION_NONE) + rgEncryption.check(R.id.radio_none); + else + rgEncryption.check(R.id.radio_ssl); + cbInsecure.setChecked(account == null ? false : account.insecure); etUser.setText(account == null ? null : account.user); diff --git a/app/src/main/java/eu/faircode/email/FragmentGmail.java b/app/src/main/java/eu/faircode/email/FragmentGmail.java index c807a8420c..c7ea72198d 100644 --- a/app/src/main/java/eu/faircode/email/FragmentGmail.java +++ b/app/src/main/java/eu/faircode/email/FragmentGmail.java @@ -363,9 +363,11 @@ public class FragmentGmail extends FragmentBase { List folders; - String aprotocol = provider.imap.starttls ? "imap" : "imaps"; + String aprotocol = (provider.imap.starttls ? "imap" : "imaps"); + int aencryption = (provider.imap.starttls ? EmailService.ENCRYPTION_STARTTLS : EmailService.ENCRYPTION_SSL); try (EmailService iservice = new EmailService( - context, aprotocol, null, false, EmailService.PURPOSE_CHECK, true)) { + context, aprotocol, null, aencryption, false, + EmailService.PURPOSE_CHECK, true)) { iservice.connect( provider.imap.host, provider.imap.port, EmailService.AUTH_TYPE_GMAIL, null, @@ -376,9 +378,11 @@ public class FragmentGmail extends FragmentBase { } Long max_size; - String iprotocol = provider.smtp.starttls ? "smtp" : "smtps"; + String iprotocol = (provider.smtp.starttls ? "smtp" : "smtps"); + int iencryption = (provider.smtp.starttls ? EmailService.ENCRYPTION_STARTTLS : EmailService.ENCRYPTION_SSL); try (EmailService iservice = new EmailService( - context, iprotocol, null, false, EmailService.PURPOSE_CHECK, true)) { + context, iprotocol, null, iencryption, false, + EmailService.PURPOSE_CHECK, true)) { iservice.connect( provider.smtp.host, provider.smtp.port, EmailService.AUTH_TYPE_GMAIL, null, @@ -397,7 +401,7 @@ public class FragmentGmail extends FragmentBase { EntityAccount account = new EntityAccount(); account.host = provider.imap.host; - account.starttls = provider.imap.starttls; + account.encryption = aencryption; account.port = provider.imap.port; account.auth_type = EmailService.AUTH_TYPE_GMAIL; account.user = user; @@ -446,7 +450,7 @@ public class FragmentGmail extends FragmentBase { identity.account = account.id; identity.host = provider.smtp.host; - identity.starttls = provider.smtp.starttls; + identity.encryption = iencryption; identity.port = provider.smtp.port; identity.auth_type = EmailService.AUTH_TYPE_GMAIL; identity.user = user; diff --git a/app/src/main/java/eu/faircode/email/FragmentIdentity.java b/app/src/main/java/eu/faircode/email/FragmentIdentity.java index 5dd00a5c23..fec9c31fc5 100644 --- a/app/src/main/java/eu/faircode/email/FragmentIdentity.java +++ b/app/src/main/java/eu/faircode/email/FragmentIdentity.java @@ -253,7 +253,7 @@ public class FragmentIdentity extends FragmentBase { EmailProvider provider = (EmailProvider) spProvider.getItemAtPosition(pos); if (provider.imap.host.equals(account.host) && provider.imap.port == account.port && - provider.imap.starttls == account.starttls) { + provider.imap.starttls == (account.encryption == EmailService.ENCRYPTION_STARTTLS)) { found = true; spProvider.setSelection(pos); @@ -418,17 +418,6 @@ public class FragmentIdentity extends FragmentBase { } }); - cbInsecure.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - Object tag = cbInsecure.getTag(); - if (tag != null && tag.equals(isChecked)) - return; - if (isChecked) - rgEncryption.check(R.id.radio_starttls); - } - }); - btnCertificate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -590,6 +579,14 @@ public class FragmentIdentity extends FragmentBase { name = hint.toString(); } + int encryption; + if (rgEncryption.getCheckedRadioButtonId() == R.id.radio_starttls) + encryption = EmailService.ENCRYPTION_STARTTLS; + else if (rgEncryption.getCheckedRadioButtonId() == R.id.radio_none) + encryption = EmailService.ENCRYPTION_NONE; + else + encryption = EmailService.ENCRYPTION_SSL; + Bundle args = new Bundle(); args.putLong("id", id); args.putString("name", name); @@ -605,7 +602,7 @@ public class FragmentIdentity extends FragmentBase { args.putString("max_size", etMaxSize.getText().toString()); args.putLong("account", account == null ? -1 : account.id); args.putString("host", etHost.getText().toString().trim()); - args.putBoolean("starttls", rgEncryption.getCheckedRadioButtonId() == R.id.radio_starttls); + args.putInt("encryption", encryption); args.putBoolean("insecure", cbInsecure.isChecked()); args.putString("port", etPort.getText().toString()); args.putInt("auth", auth); @@ -657,7 +654,7 @@ public class FragmentIdentity extends FragmentBase { String signature = args.getString("signature"); String host = args.getString("host"); - boolean starttls = args.getBoolean("starttls"); + int encryption = args.getInt("encryption"); boolean insecure = args.getBoolean("insecure"); String port = args.getString("port"); int auth = args.getInt("auth"); @@ -697,7 +694,7 @@ public class FragmentIdentity extends FragmentBase { if (TextUtils.isEmpty(host) && !should) throw new IllegalArgumentException(context.getString(R.string.title_no_host)); if (TextUtils.isEmpty(port)) - port = (starttls ? "587" : "465"); + port = (encryption == EmailService.ENCRYPTION_SSL ? "465" : "587"); if (TextUtils.isEmpty(user) && !should) throw new IllegalArgumentException(context.getString(R.string.title_no_user)); if (synchronize && TextUtils.isEmpty(password) && !insecure && certificate == null && !should) @@ -779,7 +776,7 @@ public class FragmentIdentity extends FragmentBase { return true; if (!Objects.equals(identity.host, host)) return true; - if (!Objects.equals(identity.starttls, starttls)) + if (!Objects.equals(identity.encryption, encryption)) return true; if (!Objects.equals(identity.insecure, insecure)) return true; @@ -830,7 +827,7 @@ public class FragmentIdentity extends FragmentBase { boolean check = (synchronize && (identity == null || !identity.synchronize || identity.error != null || !host.equals(identity.host) || - starttls != identity.starttls || + encryption != identity.encryption || insecure != identity.insecure || Integer.parseInt(port) != identity.port || !user.equals(identity.user) || @@ -852,9 +849,10 @@ public class FragmentIdentity extends FragmentBase { Long server_max_size = null; if (check) { // Create transport - String protocol = (starttls ? "smtp" : "smtps"); + String protocol = (encryption == EmailService.ENCRYPTION_SSL ? "smtps" : "smtp"); try (EmailService iservice = new EmailService( - context, protocol, realm, insecure, EmailService.PURPOSE_CHECK, true)) { + context, protocol, realm, encryption, insecure, + EmailService.PURPOSE_CHECK, true)) { iservice.setUseIp(use_ip, ehlo); iservice.connect( host, Integer.parseInt(port), @@ -887,7 +885,7 @@ public class FragmentIdentity extends FragmentBase { identity.signature = signature; identity.host = host; - identity.starttls = starttls; + identity.encryption = encryption; identity.insecure = insecure; identity.port = Integer.parseInt(port); identity.auth_type = auth; @@ -1094,8 +1092,14 @@ public class FragmentIdentity extends FragmentBase { signature = (identity == null ? null : identity.signature); etHost.setText(identity == null ? null : identity.host); - rgEncryption.check(identity != null && identity.starttls ? R.id.radio_starttls : R.id.radio_ssl); - cbInsecure.setTag(identity == null ? false : identity.insecure); + + if (identity != null && identity.encryption == EmailService.ENCRYPTION_STARTTLS) + rgEncryption.check(R.id.radio_starttls); + else if (identity != null && identity.encryption == EmailService.ENCRYPTION_NONE) + rgEncryption.check(R.id.radio_none); + else + rgEncryption.check(R.id.radio_ssl); + cbInsecure.setChecked(identity == null ? false : identity.insecure); etPort.setText(identity == null ? null : Long.toString(identity.port)); etUser.setText(identity == null ? null : identity.user); @@ -1210,7 +1214,7 @@ public class FragmentIdentity extends FragmentBase { EmailProvider provider = providers.get(pos); if (provider.smtp.host.equals(identity.host) && provider.smtp.port == identity.port && - provider.smtp.starttls == identity.starttls) { + provider.smtp.starttls == (identity.encryption == EmailService.ENCRYPTION_STARTTLS)) { spProvider.setTag(pos); spProvider.setSelection(pos); break; diff --git a/app/src/main/java/eu/faircode/email/FragmentOAuth.java b/app/src/main/java/eu/faircode/email/FragmentOAuth.java index b3b701725b..7e8082db2c 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOAuth.java +++ b/app/src/main/java/eu/faircode/email/FragmentOAuth.java @@ -403,6 +403,7 @@ public class FragmentOAuth extends FragmentBase { EmailProvider provider = EmailProvider.getProvider(context, id); String aprotocol = (provider.imap.starttls ? "imap" : "imaps"); + int aencryption = (provider.imap.starttls ? EmailService.ENCRYPTION_STARTTLS : EmailService.ENCRYPTION_SSL); if (accessToken != null) { String[] segments = accessToken.split("\\."); @@ -428,7 +429,8 @@ public class FragmentOAuth extends FragmentBase { String email = jpayload.getString("email"); if (!TextUtils.isEmpty(email) && !email.equals(address)) { try (EmailService iservice = new EmailService( - context, aprotocol, null, false, EmailService.PURPOSE_CHECK, true)) { + context, aprotocol, null, aencryption, false, + EmailService.PURPOSE_CHECK, true)) { iservice.connect( provider.imap.host, provider.imap.port, EmailService.AUTH_TYPE_OAUTH, provider.id, @@ -477,7 +479,8 @@ public class FragmentOAuth extends FragmentBase { Log.i("OAuth checking IMAP provider=" + provider.id); try (EmailService iservice = new EmailService( - context, aprotocol, null, false, EmailService.PURPOSE_CHECK, true)) { + context, aprotocol, null, aencryption, false, + EmailService.PURPOSE_CHECK, true)) { iservice.connect( provider.imap.host, provider.imap.port, EmailService.AUTH_TYPE_OAUTH, provider.id, @@ -490,8 +493,11 @@ public class FragmentOAuth extends FragmentBase { Log.i("OAuth checking SMTP provider=" + provider.id); Long max_size; String iprotocol = (provider.smtp.starttls ? "smtp" : "smtps"); + int iencryption = (provider.smtp.starttls ? EmailService.ENCRYPTION_STARTTLS : EmailService.ENCRYPTION_SSL); + try (EmailService iservice = new EmailService( - context, iprotocol, null, false, EmailService.PURPOSE_CHECK, true)) { + context, iprotocol, null, iencryption, false, + EmailService.PURPOSE_CHECK, true)) { iservice.connect( provider.smtp.host, provider.smtp.port, EmailService.AUTH_TYPE_OAUTH, provider.id, @@ -512,7 +518,7 @@ public class FragmentOAuth extends FragmentBase { EntityAccount account = new EntityAccount(); account.host = provider.imap.host; - account.starttls = provider.imap.starttls; + account.encryption = aencryption; account.port = provider.imap.port; account.auth_type = EmailService.AUTH_TYPE_OAUTH; account.provider = provider.id; @@ -565,7 +571,7 @@ public class FragmentOAuth extends FragmentBase { ident.account = account.id; ident.host = provider.smtp.host; - ident.starttls = provider.smtp.starttls; + ident.encryption = iencryption; ident.port = provider.smtp.port; ident.auth_type = EmailService.AUTH_TYPE_OAUTH; ident.provider = provider.id; diff --git a/app/src/main/java/eu/faircode/email/FragmentPop.java b/app/src/main/java/eu/faircode/email/FragmentPop.java index dc6fb3d271..7155e2dc32 100644 --- a/app/src/main/java/eu/faircode/email/FragmentPop.java +++ b/app/src/main/java/eu/faircode/email/FragmentPop.java @@ -162,6 +162,13 @@ public class FragmentPop extends FragmentBase { pbWait = view.findViewById(R.id.pbWait); + rgEncryption.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(RadioGroup group, int id) { + etPort.setHint(id == R.id.radio_ssl ? "995" : "110"); + } + }); + tilPassword.getEditText().addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { @@ -247,8 +254,16 @@ public class FragmentPop extends FragmentBase { Bundle args = new Bundle(); args.putLong("id", id); + int encryption; + if (rgEncryption.getCheckedRadioButtonId() == R.id.radio_starttls) + encryption = EmailService.ENCRYPTION_STARTTLS; + else if (rgEncryption.getCheckedRadioButtonId() == R.id.radio_none) + encryption = EmailService.ENCRYPTION_NONE; + else + encryption = EmailService.ENCRYPTION_SSL; + args.putString("host", etHost.getText().toString().trim()); - args.putBoolean("starttls", rgEncryption.getCheckedRadioButtonId() == R.id.radio_starttls); + args.putInt("encryption", encryption); args.putBoolean("insecure", cbInsecure.isChecked()); args.putString("port", etPort.getText().toString()); args.putString("user", etUser.getText().toString()); @@ -278,6 +293,7 @@ public class FragmentPop extends FragmentBase { saving = true; getActivity().invalidateOptionsMenu(); Helper.setViewsEnabled(view, false); + pbSave.setVisibility(View.VISIBLE); grpError.setVisibility(View.GONE); } @@ -294,7 +310,7 @@ public class FragmentPop extends FragmentBase { long id = args.getLong("id"); String host = args.getString("host"); - boolean starttls = args.getBoolean("starttls"); + int encryption = args.getInt("encryption"); boolean insecure = args.getBoolean("insecure"); String port = args.getString("port"); String user = args.getString("user").trim(); @@ -327,7 +343,7 @@ public class FragmentPop extends FragmentBase { if (TextUtils.isEmpty(host)) throw new IllegalArgumentException(context.getString(R.string.title_no_host)); if (TextUtils.isEmpty(port)) - port = "995"; + port = (encryption == EmailService.ENCRYPTION_SSL ? "995" : "110"); if (TextUtils.isEmpty(user)) throw new IllegalArgumentException(context.getString(R.string.title_no_user)); if (synchronize && TextUtils.isEmpty(password) && !insecure) @@ -349,7 +365,7 @@ public class FragmentPop extends FragmentBase { !account.synchronize || account.error != null || !account.host.equals(host) || - !account.starttls.equals(starttls) || + !account.encryption.equals(encryption) || !account.insecure.equals(insecure) || !account.port.equals(Integer.parseInt(port)) || !account.user.equals(user) || @@ -362,9 +378,10 @@ public class FragmentPop extends FragmentBase { // Check POP3 server if (check) { - String protocol = "pop3" + (starttls ? "" : "s"); + String protocol = "pop3" + (encryption == EmailService.ENCRYPTION_SSL ? "s" : ""); try (EmailService iservice = new EmailService( - context, protocol, null, insecure, EmailService.PURPOSE_CHECK, true)) { + context, protocol, null, encryption, insecure, + EmailService.PURPOSE_CHECK, true)) { iservice.connect( host, Integer.parseInt(port), EmailService.AUTH_TYPE_PASSWORD, null, @@ -389,7 +406,7 @@ public class FragmentPop extends FragmentBase { account.protocol = EntityAccount.TYPE_POP; account.host = host; - account.starttls = starttls; + account.encryption = encryption; account.insecure = insecure; account.port = Integer.parseInt(port); account.auth_type = EmailService.AUTH_TYPE_PASSWORD; @@ -571,7 +588,13 @@ public class FragmentPop extends FragmentBase { etHost.setText(account == null ? null : account.host); etPort.setText(account == null ? null : Long.toString(account.port)); - rgEncryption.check(account != null && account.starttls ? R.id.radio_starttls : R.id.radio_ssl); + if (account != null && account.encryption == EmailService.ENCRYPTION_STARTTLS) + rgEncryption.check(R.id.radio_starttls); + else if (account != null && account.encryption == EmailService.ENCRYPTION_NONE) + rgEncryption.check(R.id.radio_none); + else + rgEncryption.check(R.id.radio_ssl); + cbInsecure.setChecked(account == null ? false : account.insecure); etUser.setText(account == null ? null : account.user); diff --git a/app/src/main/java/eu/faircode/email/FragmentQuickSetup.java b/app/src/main/java/eu/faircode/email/FragmentQuickSetup.java index 38269926d5..31498a40a0 100644 --- a/app/src/main/java/eu/faircode/email/FragmentQuickSetup.java +++ b/app/src/main/java/eu/faircode/email/FragmentQuickSetup.java @@ -297,9 +297,10 @@ public class FragmentQuickSetup extends FragmentBase { List folders; - String aprotocol = provider.imap.starttls ? "imap" : "imaps"; + String aprotocol = (provider.imap.starttls ? "imap" : "imaps"); + int aencryption = (provider.imap.starttls ? EmailService.ENCRYPTION_STARTTLS : EmailService.ENCRYPTION_SSL); try (EmailService iservice = new EmailService( - context, aprotocol, null, false, EmailService.PURPOSE_CHECK, true)) { + context, aprotocol, null, aencryption, false, EmailService.PURPOSE_CHECK, true)) { try { iservice.connect( provider.imap.host, provider.imap.port, @@ -340,9 +341,11 @@ public class FragmentQuickSetup extends FragmentBase { } Long max_size = null; - String iprotocol = provider.smtp.starttls ? "smtp" : "smtps"; + String iprotocol = (provider.smtp.starttls ? "smtp" : "smtps"); + int iencryption = (provider.smtp.starttls ? EmailService.ENCRYPTION_STARTTLS : EmailService.ENCRYPTION_SSL); try (EmailService iservice = new EmailService( - context, iprotocol, null, false, EmailService.PURPOSE_CHECK, true)) { + context, iprotocol, null, iencryption, false, + EmailService.PURPOSE_CHECK, true)) { iservice.setUseIp(provider.useip, null); iservice.connect( provider.smtp.host, provider.smtp.port, @@ -373,7 +376,7 @@ public class FragmentQuickSetup extends FragmentBase { EntityAccount account = new EntityAccount(); account.host = provider.imap.host; - account.starttls = provider.imap.starttls; + account.encryption = aencryption; account.port = provider.imap.port; account.auth_type = EmailService.AUTH_TYPE_PASSWORD; account.user = user; @@ -423,7 +426,7 @@ public class FragmentQuickSetup extends FragmentBase { identity.account = account.id; identity.host = provider.smtp.host; - identity.starttls = provider.smtp.starttls; + identity.encryption = iencryption; identity.port = provider.smtp.port; identity.auth_type = EmailService.AUTH_TYPE_PASSWORD; identity.user = user; diff --git a/app/src/main/java/eu/faircode/email/ServiceSend.java b/app/src/main/java/eu/faircode/email/ServiceSend.java index 5286f5e16a..8df52718fb 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSend.java +++ b/app/src/main/java/eu/faircode/email/ServiceSend.java @@ -582,7 +582,7 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar // Create transport try (EmailService iservice = new EmailService( - this, ident.getProtocol(), ident.realm, ident.insecure, debug)) { + this, ident.getProtocol(), ident.realm, ident.encryption, ident.insecure, debug)) { iservice.setUseIp(ident.use_ip, ident.ehlo); iservice.setUnicode(ident.unicode); diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index ba23fc27fb..b3a27dcd43 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -909,7 +909,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences boolean debug = (prefs.getBoolean("debug", false) || BuildConfig.DEBUG); final EmailService iservice = new EmailService( - this, account.getProtocol(), account.realm, account.insecure, debug); + this, account.getProtocol(), account.realm, account.encryption, account.insecure, debug); iservice.setPartialFetch(account.partial_fetch); iservice.setIgnoreBodyStructureSize(account.ignore_size); if (account.protocol != EntityAccount.TYPE_IMAP) diff --git a/app/src/main/java/eu/faircode/email/TupleAccountState.java b/app/src/main/java/eu/faircode/email/TupleAccountState.java index d829d72f9c..4119dcaa9c 100644 --- a/app/src/main/java/eu/faircode/email/TupleAccountState.java +++ b/app/src/main/java/eu/faircode/email/TupleAccountState.java @@ -31,7 +31,7 @@ public class TupleAccountState extends EntityAccount { if (obj instanceof TupleAccountState) { TupleAccountState other = (TupleAccountState) obj; return (this.host.equals(other.host) && - this.starttls.equals(other.starttls) && + this.encryption.equals(other.encryption) && this.insecure.equals(other.insecure) && this.port.equals(other.port) && this.user.equals(other.user) && diff --git a/app/src/main/res/layout/fragment_account.xml b/app/src/main/res/layout/fragment_account.xml index df1ae770ad..aac9ebc147 100644 --- a/app/src/main/res/layout/fragment_account.xml +++ b/app/src/main/res/layout/fragment_account.xml @@ -137,28 +137,43 @@ + + + app:layout_constraintTop_toBottomOf="@id/tvEncryption"> + android:text="@string/title_encryption_ssl" /> + android:text="@string/title_encryption_starttls" /> + + @@ -966,7 +982,7 @@ android:layout_height="0dp" app:constraint_referenced_ids=" tvDomain,tvDomainHint,etDomain,btnAutoConfig, - tvImap,tvHost,etHost,rgEncryption,cbInsecure,tvInsecureRemark,tvPort,etPort" /> + tvImap,tvHost,etHost,tvEncryption,rgEncryption,cbInsecure,tvInsecureRemark,tvPort,etPort" /> + + + app:layout_constraintTop_toBottomOf="@id/tvEncryption"> + android:text="@string/title_encryption_ssl" /> + android:text="@string/title_encryption_starttls" /> + + @@ -832,7 +848,7 @@ app:constraint_referenced_ids=" tvProvider,spProvider, tvDomain,tvDomainHint,etDomain,btnAutoConfig, - tvSmtp,tvHost,etHost,rgEncryption,cbInsecure,tvInsecureRemark,tvPort,etPort, + tvSmtp,tvHost,etHost,tvEncryption,rgEncryption,cbInsecure,tvInsecureRemark,tvPort,etPort, tvUser,etUser,tvPassword,tilPassword,tvCaseSensitiveHint,btnCertificate,tvCertificate,btnOAuth, tvRealm,etRealm, cbUseIp,tvUseIpHint,tvEhlo,etEhlo, diff --git a/app/src/main/res/layout/fragment_pop.xml b/app/src/main/res/layout/fragment_pop.xml index ab1a7fc82d..0a25a99537 100644 --- a/app/src/main/res/layout/fragment_pop.xml +++ b/app/src/main/res/layout/fragment_pop.xml @@ -48,28 +48,43 @@ + + + app:layout_constraintTop_toBottomOf="@id/tvEncryption"> + android:text="@string/title_encryption_ssl" /> + android:text="@string/title_encryption_starttls" /> + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ea903c94ee..084ffb3adc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -619,8 +619,10 @@ Provider Custom Host name - SSL/TLS - STARTTLS + Encryption + SSL/TLS + STARTTLS + None Allow insecure connections Insecure connections should only be allowed on trusted networks and never on public networks Port number