diff --git a/res/values/strings.xml b/res/values/strings.xml index 9de519bd3..5a1c8103c 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -386,6 +386,7 @@ Please submit bug reports, contribute new features and ask questions at Exchange (WebDAV) Normal password + Password, transmitted insecurely Encrypted password Incoming server settings diff --git a/src/com/fsck/k9/activity/setup/AccountSetupIncoming.java b/src/com/fsck/k9/activity/setup/AccountSetupIncoming.java index 73ab9327b..f05376499 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupIncoming.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupIncoming.java @@ -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(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) { diff --git a/src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java b/src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java index d74e80088..bb77aef11 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java @@ -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(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) { diff --git a/src/com/fsck/k9/mail/AuthType.java b/src/com/fsck/k9/mail/AuthType.java index c77371661..52ffe5866 100644 --- a/src/com/fsck/k9/mail/AuthType.java +++ b/src/com/fsck/k9/mail/AuthType.java @@ -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 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 getArrayAdapter(Context context) { + AuthType[] authTypes = {PLAIN, CRAM_MD5}; + ArrayAdapter authTypesAdapter = new ArrayAdapter(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 + *

+ * A value of {@code true} will use "Normal password". + *

+ * A value of {@code false} will use + * "Password, transmitted insecurely" + */ + public void useInsecureText(boolean insecure, ArrayAdapter authTypesAdapter) { + // Do nothing. Overridden in AuthType.PLAIN + } + @Override public String toString() { if (mResourceId == 0) {