1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 11:42:16 -05:00

Change the PLAIN auth. option text based on encryption

If the user chooses a connection security option which assures the use of
encryption, then the PLAIN auth. option is labeled "Normal password",
otherwise it is labeled "Password, transmitted insecurely".

This is similar to Thunderbird's behavior.
This commit is contained in:
Joe Steele 2014-02-14 10:37:44 -05:00
parent f7d397ea09
commit 540de158a0
4 changed files with 71 additions and 11 deletions

View File

@ -386,6 +386,7 @@ Please submit bug reports, contribute new features and ask questions at
<string name="account_setup_account_type_webdav_action">Exchange (WebDAV)</string>
<string name="account_setup_auth_type_normal_password">Normal password</string>
<string name="account_setup_auth_type_insecure_password">Password, transmitted insecurely</string>
<string name="account_setup_auth_type_encrypted_password">Encrypted password</string>
<string name="account_setup_incoming_title">Incoming server settings</string>

View File

@ -129,10 +129,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
securityTypesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mSecurityTypeView.setAdapter(securityTypesAdapter);
AuthType[] acceptableAuthTypes = {AuthType.PLAIN, AuthType.CRAM_MD5};
mAuthTypeAdapter = new ArrayAdapter<AuthType>(this,
android.R.layout.simple_spinner_item, acceptableAuthTypes);
mAuthTypeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mAuthTypeAdapter = AuthType.getArrayAdapter(this);
mAuthTypeView.setAdapter(mAuthTypeAdapter);
/*
@ -186,6 +183,8 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
mPasswordView.setText(settings.password);
}
updateAuthPlainTextFromSecurityType(settings.connectionSecurity);
// The first item is selected if settings.authenticationType is null or is not in mAuthTypeAdapter
int position = mAuthTypeAdapter.getPosition(settings.authenticationType);
mAuthTypeView.setSelection(position, false);
@ -319,6 +318,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
private void updatePortFromSecurityType() {
ConnectionSecurity securityType = (ConnectionSecurity) mSecurityTypeView.getSelectedItem();
mPortView.setText(getDefaultPort(securityType));
updateAuthPlainTextFromSecurityType(securityType);
}
private String getDefaultPort(ConnectionSecurity securityType) {
@ -351,6 +351,17 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
return port;
}
private void updateAuthPlainTextFromSecurityType(ConnectionSecurity securityType) {
switch (securityType) {
case NONE:
case STARTTLS_OPTIONAL:
AuthType.PLAIN.useInsecureText(true, mAuthTypeAdapter);
break;
default:
AuthType.PLAIN.useInsecureText(false, mAuthTypeAdapter);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {

View File

@ -103,10 +103,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
securityTypesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mSecurityTypeView.setAdapter(securityTypesAdapter);
AuthType[] acceptableAuthTypes = {AuthType.AUTOMATIC, AuthType.PLAIN, AuthType.CRAM_MD5};
mAuthTypeAdapter = new ArrayAdapter<AuthType>(this,
android.R.layout.simple_spinner_item, acceptableAuthTypes);
mAuthTypeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mAuthTypeAdapter = AuthType.getArrayAdapter(this);
mAuthTypeView.setAdapter(mAuthTypeAdapter);
/*
@ -162,6 +159,8 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
mPasswordView.setText(password);
}
updateAuthPlainTextFromSecurityType(settings.connectionSecurity);
// The first item is selected if settings.authenticationType is null or is not in mAuthTypeAdapter
int position = mAuthTypeAdapter.getPosition(settings.authenticationType);
mAuthTypeView.setSelection(position, false);
@ -229,6 +228,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
private void updatePortFromSecurityType() {
ConnectionSecurity securityType = (ConnectionSecurity) mSecurityTypeView.getSelectedItem();
mPortView.setText(getDefaultSmtpPort(securityType));
updateAuthPlainTextFromSecurityType(securityType);
}
private String getDefaultSmtpPort(ConnectionSecurity securityType) {
@ -250,6 +250,17 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
return port;
}
private void updateAuthPlainTextFromSecurityType(ConnectionSecurity securityType) {
switch (securityType) {
case NONE:
case STARTTLS_OPTIONAL:
AuthType.PLAIN.useInsecureText(true, mAuthTypeAdapter);
break;
default:
AuthType.PLAIN.useInsecureText(false, mAuthTypeAdapter);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {

View File

@ -1,10 +1,11 @@
package com.fsck.k9.mail;
import android.content.Context;
import android.widget.ArrayAdapter;
import com.fsck.k9.K9;
import com.fsck.k9.R;
public enum AuthType {
/*
* The names of these authentication types are saved as strings when
* settings are exported and are also saved as part of the Server URI stored
@ -16,7 +17,20 @@ public enum AuthType {
* their original names have been retained for backward compatibility with
* user settings.
*/
PLAIN(R.string.account_setup_auth_type_normal_password),
PLAIN(R.string.account_setup_auth_type_normal_password){
@Override
public void useInsecureText(boolean insecure, ArrayAdapter<AuthType> authTypesAdapter) {
if (insecure) {
mResourceId = R.string.account_setup_auth_type_insecure_password;
} else {
mResourceId = R.string.account_setup_auth_type_normal_password;
}
authTypesAdapter.notifyDataSetChanged();
}
},
CRAM_MD5(R.string.account_setup_auth_type_encrypted_password),
/*
@ -29,12 +43,35 @@ public enum AuthType {
LOGIN(0);
private final int mResourceId;
static public ArrayAdapter<AuthType> getArrayAdapter(Context context) {
AuthType[] authTypes = {PLAIN, CRAM_MD5};
ArrayAdapter<AuthType> authTypesAdapter = new ArrayAdapter<AuthType>(context,
android.R.layout.simple_spinner_item, authTypes);
authTypesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
return authTypesAdapter;
}
int mResourceId;
private AuthType(int id) {
mResourceId = id;
}
/**
* Used to select an appropriate localized text label for the
* {@code AuthType.PLAIN} option presented to users.
*
* @param insecure
* <p>
* A value of {@code true} will use "Normal password".
* <p>
* A value of {@code false} will use
* "Password, transmitted insecurely"
*/
public void useInsecureText(boolean insecure, ArrayAdapter<AuthType> authTypesAdapter) {
// Do nothing. Overridden in AuthType.PLAIN
}
@Override
public String toString() {
if (mResourceId == 0) {