From 9301aabc8c3d66376fd1a6bbf62f8f02f77c15c1 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Mon, 18 Jan 2010 00:10:49 +0000 Subject: [PATCH] CRAM-MD5 for SMTP is now configurable --- res/layout/account_setup_outgoing.xml | 10 ++++ res/values/strings.xml | 2 +- .../activity/setup/AccountSetupOutgoing.java | 50 ++++++++++++++++--- .../fsck/k9/mail/transport/SmtpTransport.java | 9 +++- 4 files changed, 62 insertions(+), 9 deletions(-) diff --git a/res/layout/account_setup_outgoing.xml b/res/layout/account_setup_outgoing.xml index 2dc4aefb9..853a16c25 100644 --- a/res/layout/account_setup_outgoing.xml +++ b/res/layout/account_setup_outgoing.xml @@ -61,6 +61,16 @@ android:layout_height="fill_parent" android:orientation="vertical" android:visibility="gone"> + + Require sign-in. Username Password - Authentication type + Username & password Username Password diff --git a/src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java b/src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java index 76fb4493d..83474091e 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java @@ -43,6 +43,10 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener, "webdav", "webdav+ssl", "webdav+ssl+", "webdav+tls", "webdav+tls+" }; + private static final String authTypes[] = + { + "PLAIN", "CRAM_MD5" + }; private EditText mUsernameView; private EditText mPasswordView; private EditText mServerView; @@ -50,6 +54,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener, private CheckBox mRequireLoginView; private ViewGroup mRequireLoginSettingsView; private Spinner mSecurityTypeView; + private Spinner mAuthTypeView; private Button mNextButton; private Account mAccount; private boolean mMakeDefault; @@ -100,6 +105,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener, mRequireLoginView = (CheckBox)findViewById(R.id.account_require_login); mRequireLoginSettingsView = (ViewGroup)findViewById(R.id.account_require_login_settings); mSecurityTypeView = (Spinner)findViewById(R.id.account_security_type); + mAuthTypeView = (Spinner)findViewById(R.id.account_auth_type); mNextButton = (Button)findViewById(R.id.next); mNextButton.setOnClickListener(this); @@ -116,11 +122,26 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener, new SpinnerOption(4, getString(R.string.account_setup_incoming_security_tls_label)), }; + // This needs to be kept in sync with the list at the top of the file. + // that makes me somewhat unhappy + SpinnerOption authTypeSpinnerOptions[] = + { + new SpinnerOption(0, "PLAIN"), + new SpinnerOption(1, "CRAM_MD5") + }; + + + ArrayAdapter securityTypesAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, securityTypes); securityTypesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mSecurityTypeView.setAdapter(securityTypesAdapter); + ArrayAdapter authTypesAdapter = new ArrayAdapter(this, + android.R.layout.simple_spinner_item, authTypeSpinnerOptions); + authTypesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + mAuthTypeView.setAdapter(authTypesAdapter); + /* * Updates the port when the user changes the security type. This allows * us to show a reasonable default which the user can change. @@ -183,14 +204,18 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener, URI uri = new URI(mAccount.getTransportUri()); String username = null; String password = null; + String authType = null; if (uri.getUserInfo() != null) { - String[] userInfoParts = uri.getUserInfo().split(":", 2); + String[] userInfoParts = uri.getUserInfo().split(":"); username = userInfoParts[0]; - if (userInfoParts.length > 1) - { - password = userInfoParts[1]; - } + if (userInfoParts.length > 1) + { + password = userInfoParts[1]; + } + if (userInfoParts.length > 2) { + authType = userInfoParts[2]; + } } if (username != null) @@ -204,6 +229,18 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener, mPasswordView.setText(password); } + if (authType != null) + { + for (int i = 0; i < authTypes.length; i++) + { + if (authTypes[i].equals(authType)) + { + SpinnerOption.setSpinnerOptionValue(mAuthTypeView, i); + } + } + } + + for (int i = 0; i < smtpSchemes.length; i++) { if (smtpSchemes[i].equals(uri.getScheme())) @@ -288,10 +325,11 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener, try { String userInfo = null; + String authType = ((SpinnerOption)mAuthTypeView.getSelectedItem()).label; if (mRequireLoginView.isChecked()) { userInfo = mUsernameView.getText().toString() + ":" - + mPasswordView.getText().toString(); + + mPasswordView.getText().toString() + ":" + authType; } uri = new URI(smtpSchemes[securityType], userInfo, mServerView.getText().toString(), Integer.parseInt(mPortView.getText().toString()), null, null, null); diff --git a/src/com/fsck/k9/mail/transport/SmtpTransport.java b/src/com/fsck/k9/mail/transport/SmtpTransport.java index 48a3812a0..35df3d2d3 100644 --- a/src/com/fsck/k9/mail/transport/SmtpTransport.java +++ b/src/com/fsck/k9/mail/transport/SmtpTransport.java @@ -45,6 +45,8 @@ public class SmtpTransport extends Transport String mPassword; + String mAuthType; + int mConnectionSecurity; boolean mSecure; @@ -116,12 +118,15 @@ public class SmtpTransport extends Transport if (uri.getUserInfo() != null) { - String[] userInfoParts = uri.getUserInfo().split(":", 2); + String[] userInfoParts = uri.getUserInfo().split(":"); mUsername = userInfoParts[0]; if (userInfoParts.length > 1) { mPassword = userInfoParts[1]; } + if (userInfoParts.length > 2) { + mAuthType = userInfoParts[2]; + } } } @@ -234,7 +239,7 @@ public class SmtpTransport extends Transport { authPlainSupported = true; } - if (result.matches(".*AUTH.*CRAM-MD5.*$") == true) + if (result.matches(".*AUTH.*CRAM-MD5.*$") == true && mAuthType != null && mAuthType.equals("CRAM_MD5")) { authCramMD5Supported = true; }