mirror of
https://github.com/M66B/FairEmail.git
synced 2025-12-31 18:11:03 +01:00
Added certificate selection
This commit is contained in:
@@ -100,7 +100,8 @@ public class FragmentIdentity extends FragmentBase {
|
||||
private EditText etUser;
|
||||
private TextInputLayout tilPassword;
|
||||
private TextView tvCharacters;
|
||||
private CheckBox cbCertificate;
|
||||
private Button btnCertificate;
|
||||
private TextView tvCertificate;
|
||||
private Button btnOAuth;
|
||||
private EditText etRealm;
|
||||
private CheckBox cbUseIp;
|
||||
@@ -132,6 +133,7 @@ public class FragmentIdentity extends FragmentBase {
|
||||
private long account = -1;
|
||||
private int auth = EmailService.AUTH_TYPE_PASSWORD;
|
||||
private String provider = null;
|
||||
private String certificate = null;
|
||||
private boolean saving = false;
|
||||
|
||||
private static final int REQUEST_COLOR = 1;
|
||||
@@ -186,7 +188,8 @@ public class FragmentIdentity extends FragmentBase {
|
||||
etUser = view.findViewById(R.id.etUser);
|
||||
tilPassword = view.findViewById(R.id.tilPassword);
|
||||
tvCharacters = view.findViewById(R.id.tvCharacters);
|
||||
cbCertificate = view.findViewById(R.id.cbCertificate);
|
||||
btnCertificate = view.findViewById(R.id.btnCertificate);
|
||||
tvCertificate = view.findViewById(R.id.tvCertificate);
|
||||
btnOAuth = view.findViewById(R.id.btnOAuth);
|
||||
etRealm = view.findViewById(R.id.etRealm);
|
||||
cbUseIp = view.findViewById(R.id.cbUseIp);
|
||||
@@ -268,12 +271,13 @@ public class FragmentIdentity extends FragmentBase {
|
||||
etEmail.setText(account.user);
|
||||
etUser.setText(account.user);
|
||||
tilPassword.getEditText().setText(account.password);
|
||||
cbCertificate.setChecked(account.certificate);
|
||||
certificate = account.certificate_alias;
|
||||
tvCertificate.setText(certificate == null ? getString(R.string.title_optional) : certificate);
|
||||
etRealm.setText(account.realm);
|
||||
|
||||
etUser.setEnabled(auth == EmailService.AUTH_TYPE_PASSWORD);
|
||||
tilPassword.setEnabled(auth == EmailService.AUTH_TYPE_PASSWORD);
|
||||
cbCertificate.setEnabled(auth == EmailService.AUTH_TYPE_PASSWORD);
|
||||
btnCertificate.setEnabled(auth == EmailService.AUTH_TYPE_PASSWORD);
|
||||
cbTrust.setChecked(false);
|
||||
}
|
||||
|
||||
@@ -406,7 +410,7 @@ public class FragmentIdentity extends FragmentBase {
|
||||
|
||||
etUser.setEnabled(auth == EmailService.AUTH_TYPE_PASSWORD);
|
||||
tilPassword.setEnabled(auth == EmailService.AUTH_TYPE_PASSWORD);
|
||||
cbCertificate.setEnabled(auth == EmailService.AUTH_TYPE_PASSWORD);
|
||||
btnCertificate.setEnabled(auth == EmailService.AUTH_TYPE_PASSWORD);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -428,6 +432,25 @@ public class FragmentIdentity extends FragmentBase {
|
||||
}
|
||||
});
|
||||
|
||||
btnCertificate.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Helper.selectKeyAlias(getActivity(), getViewLifecycleOwner(), null, new Helper.IKeyAlias() {
|
||||
@Override
|
||||
public void onSelected(String alias) {
|
||||
certificate = alias;
|
||||
tvCertificate.setText(alias);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected() {
|
||||
certificate = null;
|
||||
tvCertificate.setText(R.string.title_optional);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
btnOAuth.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@@ -586,7 +609,7 @@ public class FragmentIdentity extends FragmentBase {
|
||||
args.putString("provider", provider);
|
||||
args.putString("user", etUser.getText().toString().trim());
|
||||
args.putString("password", tilPassword.getEditText().getText().toString());
|
||||
args.putBoolean("certificate", cbCertificate.isChecked());
|
||||
args.putString("certificate", certificate);
|
||||
args.putString("realm", etRealm.getText().toString());
|
||||
args.putString("fingerprint", cbTrust.isChecked() ? (String) cbTrust.getTag() : null);
|
||||
args.putBoolean("use_ip", cbUseIp.isChecked());
|
||||
@@ -636,7 +659,7 @@ public class FragmentIdentity extends FragmentBase {
|
||||
String provider = args.getString("provider");
|
||||
String user = args.getString("user").trim();
|
||||
String password = args.getString("password");
|
||||
boolean certificate = args.getBoolean("certificate");
|
||||
String certificate = args.getString("certificate");
|
||||
String realm = args.getString("realm");
|
||||
String fingerprint = args.getString("fingerprint");
|
||||
boolean use_ip = args.getBoolean("use_ip");
|
||||
@@ -667,7 +690,7 @@ public class FragmentIdentity extends FragmentBase {
|
||||
port = (starttls ? "587" : "465");
|
||||
if (TextUtils.isEmpty(user) && !should)
|
||||
throw new IllegalArgumentException(context.getString(R.string.title_no_user));
|
||||
if (synchronize && TextUtils.isEmpty(password) && !insecure && !certificate && !should)
|
||||
if (synchronize && TextUtils.isEmpty(password) && !insecure && certificate == null && !should)
|
||||
throw new IllegalArgumentException(context.getString(R.string.title_no_password));
|
||||
|
||||
if (!TextUtils.isEmpty(replyto) && !should) {
|
||||
@@ -739,7 +762,7 @@ public class FragmentIdentity extends FragmentBase {
|
||||
return true;
|
||||
if (!Objects.equals(identity.password, password))
|
||||
return true;
|
||||
if (!Objects.equals(identity.certificate, certificate))
|
||||
if (!Objects.equals(identity.certificate_alias, certificate))
|
||||
return true;
|
||||
if (!Objects.equals(identity.realm, realm))
|
||||
return true;
|
||||
@@ -770,7 +793,7 @@ public class FragmentIdentity extends FragmentBase {
|
||||
!identity.insecure.equals(insecure) ||
|
||||
!host.equals(identity.host) || Integer.parseInt(port) != identity.port ||
|
||||
!user.equals(identity.user) || !password.equals(identity.password) ||
|
||||
!Objects.equals(identity.certificate, certificate) ||
|
||||
!Objects.equals(identity.certificate_alias, certificate) ||
|
||||
!Objects.equals(realm, identityRealm) ||
|
||||
!Objects.equals(identity.fingerprint, fingerprint) ||
|
||||
use_ip != identity.use_ip));
|
||||
@@ -823,7 +846,7 @@ public class FragmentIdentity extends FragmentBase {
|
||||
identity.auth_type = auth;
|
||||
identity.user = user;
|
||||
identity.password = password;
|
||||
identity.certificate = certificate;
|
||||
identity.certificate_alias = certificate;
|
||||
identity.provider = provider;
|
||||
identity.realm = realm;
|
||||
identity.fingerprint = fingerprint;
|
||||
@@ -1019,7 +1042,8 @@ public class FragmentIdentity extends FragmentBase {
|
||||
etPort.setText(identity == null ? null : Long.toString(identity.port));
|
||||
etUser.setText(identity == null ? null : identity.user);
|
||||
tilPassword.getEditText().setText(identity == null ? null : identity.password);
|
||||
cbCertificate.setChecked(identity != null && identity.certificate);
|
||||
certificate = (identity == null ? null : identity.certificate_alias);
|
||||
tvCertificate.setText(certificate == null ? getString(R.string.title_optional) : certificate);
|
||||
etRealm.setText(identity == null ? null : identity.realm);
|
||||
|
||||
if (identity == null || identity.fingerprint == null) {
|
||||
@@ -1075,7 +1099,7 @@ public class FragmentIdentity extends FragmentBase {
|
||||
if (auth != EmailService.AUTH_TYPE_PASSWORD) {
|
||||
etUser.setEnabled(false);
|
||||
tilPassword.setEnabled(false);
|
||||
cbCertificate.setEnabled(false);
|
||||
btnCertificate.setEnabled(false);
|
||||
}
|
||||
|
||||
if (identity == null || identity.auth_type != EmailService.AUTH_TYPE_GMAIL)
|
||||
|
||||
Reference in New Issue
Block a user