1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-08-13 17:03:48 -04:00

CRAM-MD5 for SMTP is now configurable

This commit is contained in:
Jesse Vincent 2010-01-18 00:10:49 +00:00
parent 22e771ef2a
commit 9301aabc8c
4 changed files with 62 additions and 9 deletions

View File

@ -61,6 +61,16 @@
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" android:orientation="vertical"
android:visibility="gone"> android:visibility="gone">
<TextView
android:text="@string/account_setup_outgoing_authentication_label"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorPrimary" />
<Spinner
android:id="@+id/account_auth_type"
android:layout_height="wrap_content"
android:layout_width="fill_parent" />
<TextView <TextView
android:text="@string/account_setup_outgoing_username_label" android:text="@string/account_setup_outgoing_username_label"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@ -353,8 +353,8 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin
<string name="account_setup_outgoing_require_login_label">Require sign-in.</string> <string name="account_setup_outgoing_require_login_label">Require sign-in.</string>
<string name="account_setup_outgoing_username_label">Username</string> <string name="account_setup_outgoing_username_label">Username</string>
<string name="account_setup_outgoing_password_label">Password</string> <string name="account_setup_outgoing_password_label">Password</string>
<!-- The authentication strings below are for a planned (hopefully) change to the above username and password options -->
<string name="account_setup_outgoing_authentication_label">Authentication type</string> <string name="account_setup_outgoing_authentication_label">Authentication type</string>
<!-- The authentication strings below are for a planned (hopefully) change to the above username and password options -->
<string name="account_setup_outgoing_authentication_basic_label">Username &amp; password</string> <string name="account_setup_outgoing_authentication_basic_label">Username &amp; password</string>
<string name="account_setup_outgoing_authentication_basic_username_label">Username</string> <string name="account_setup_outgoing_authentication_basic_username_label">Username</string>
<string name="account_setup_outgoing_authentication_basic_password_label">Password</string> <string name="account_setup_outgoing_authentication_basic_password_label">Password</string>

View File

@ -43,6 +43,10 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
"webdav", "webdav+ssl", "webdav+ssl+", "webdav+tls", "webdav+tls+" "webdav", "webdav+ssl", "webdav+ssl+", "webdav+tls", "webdav+tls+"
}; };
private static final String authTypes[] =
{
"PLAIN", "CRAM_MD5"
};
private EditText mUsernameView; private EditText mUsernameView;
private EditText mPasswordView; private EditText mPasswordView;
private EditText mServerView; private EditText mServerView;
@ -50,6 +54,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
private CheckBox mRequireLoginView; private CheckBox mRequireLoginView;
private ViewGroup mRequireLoginSettingsView; private ViewGroup mRequireLoginSettingsView;
private Spinner mSecurityTypeView; private Spinner mSecurityTypeView;
private Spinner mAuthTypeView;
private Button mNextButton; private Button mNextButton;
private Account mAccount; private Account mAccount;
private boolean mMakeDefault; private boolean mMakeDefault;
@ -100,6 +105,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
mRequireLoginView = (CheckBox)findViewById(R.id.account_require_login); mRequireLoginView = (CheckBox)findViewById(R.id.account_require_login);
mRequireLoginSettingsView = (ViewGroup)findViewById(R.id.account_require_login_settings); mRequireLoginSettingsView = (ViewGroup)findViewById(R.id.account_require_login_settings);
mSecurityTypeView = (Spinner)findViewById(R.id.account_security_type); mSecurityTypeView = (Spinner)findViewById(R.id.account_security_type);
mAuthTypeView = (Spinner)findViewById(R.id.account_auth_type);
mNextButton = (Button)findViewById(R.id.next); mNextButton = (Button)findViewById(R.id.next);
mNextButton.setOnClickListener(this); 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)), 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<SpinnerOption> securityTypesAdapter = new ArrayAdapter<SpinnerOption>(this, ArrayAdapter<SpinnerOption> securityTypesAdapter = new ArrayAdapter<SpinnerOption>(this,
android.R.layout.simple_spinner_item, securityTypes); android.R.layout.simple_spinner_item, securityTypes);
securityTypesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); securityTypesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mSecurityTypeView.setAdapter(securityTypesAdapter); mSecurityTypeView.setAdapter(securityTypesAdapter);
ArrayAdapter<SpinnerOption> authTypesAdapter = new ArrayAdapter<SpinnerOption>(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 * Updates the port when the user changes the security type. This allows
* us to show a reasonable default which the user can change. * 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()); URI uri = new URI(mAccount.getTransportUri());
String username = null; String username = null;
String password = null; String password = null;
String authType = null;
if (uri.getUserInfo() != null) if (uri.getUserInfo() != null)
{ {
String[] userInfoParts = uri.getUserInfo().split(":", 2); String[] userInfoParts = uri.getUserInfo().split(":");
username = userInfoParts[0]; username = userInfoParts[0];
if (userInfoParts.length > 1) if (userInfoParts.length > 1)
{ {
password = userInfoParts[1]; password = userInfoParts[1];
} }
if (userInfoParts.length > 2) {
authType = userInfoParts[2];
}
} }
if (username != null) if (username != null)
@ -204,6 +229,18 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
mPasswordView.setText(password); 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++) for (int i = 0; i < smtpSchemes.length; i++)
{ {
if (smtpSchemes[i].equals(uri.getScheme())) if (smtpSchemes[i].equals(uri.getScheme()))
@ -288,10 +325,11 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
try try
{ {
String userInfo = null; String userInfo = null;
String authType = ((SpinnerOption)mAuthTypeView.getSelectedItem()).label;
if (mRequireLoginView.isChecked()) if (mRequireLoginView.isChecked())
{ {
userInfo = mUsernameView.getText().toString() + ":" userInfo = mUsernameView.getText().toString() + ":"
+ mPasswordView.getText().toString(); + mPasswordView.getText().toString() + ":" + authType;
} }
uri = new URI(smtpSchemes[securityType], userInfo, mServerView.getText().toString(), uri = new URI(smtpSchemes[securityType], userInfo, mServerView.getText().toString(),
Integer.parseInt(mPortView.getText().toString()), null, null, null); Integer.parseInt(mPortView.getText().toString()), null, null, null);

View File

@ -45,6 +45,8 @@ public class SmtpTransport extends Transport
String mPassword; String mPassword;
String mAuthType;
int mConnectionSecurity; int mConnectionSecurity;
boolean mSecure; boolean mSecure;
@ -116,12 +118,15 @@ public class SmtpTransport extends Transport
if (uri.getUserInfo() != null) if (uri.getUserInfo() != null)
{ {
String[] userInfoParts = uri.getUserInfo().split(":", 2); String[] userInfoParts = uri.getUserInfo().split(":");
mUsername = userInfoParts[0]; mUsername = userInfoParts[0];
if (userInfoParts.length > 1) if (userInfoParts.length > 1)
{ {
mPassword = userInfoParts[1]; mPassword = userInfoParts[1];
} }
if (userInfoParts.length > 2) {
mAuthType = userInfoParts[2];
}
} }
} }
@ -234,7 +239,7 @@ public class SmtpTransport extends Transport
{ {
authPlainSupported = true; authPlainSupported = true;
} }
if (result.matches(".*AUTH.*CRAM-MD5.*$") == true) if (result.matches(".*AUTH.*CRAM-MD5.*$") == true && mAuthType != null && mAuthType.equals("CRAM_MD5"))
{ {
authCramMD5Supported = true; authCramMD5Supported = true;
} }