1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 19:52:17 -05: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:orientation="vertical"
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
android:text="@string/account_setup_outgoing_username_label"
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_username_label">Username</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>
<!-- 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_username_label">Username</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+"
};
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<SpinnerOption> securityTypesAdapter = new ArrayAdapter<SpinnerOption>(this,
android.R.layout.simple_spinner_item, securityTypes);
securityTypesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
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
* 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);

View File

@ -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;
}