mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-23 18:02:15 -05:00
Use localized strings for authentication type
AUTOMATIC = "Automatic" PLAIN = "Normal password" CRAM_MD5 = "Encrypted password" SMTP also uses LOGIN. No localized text was associated with that because a future commit will remove that option. (The text is similar to that of Thunderbird's)
This commit is contained in:
parent
f24ac67e4d
commit
dc9720ca13
@ -385,6 +385,10 @@ Please submit bug reports, contribute new features and ask questions at
|
|||||||
<string name="account_setup_account_type_imap_action">IMAP</string>
|
<string name="account_setup_account_type_imap_action">IMAP</string>
|
||||||
<string name="account_setup_account_type_webdav_action">Exchange (WebDAV)</string>
|
<string name="account_setup_account_type_webdav_action">Exchange (WebDAV)</string>
|
||||||
|
|
||||||
|
<string name="account_setup_auth_type_automatic">Automatic</string>
|
||||||
|
<string name="account_setup_auth_type_normal_password">Normal password</string>
|
||||||
|
<string name="account_setup_auth_type_encrypted_password">Encrypted password</string>
|
||||||
|
|
||||||
<string name="account_setup_incoming_title">Incoming server settings</string>
|
<string name="account_setup_incoming_title">Incoming server settings</string>
|
||||||
<string name="account_setup_incoming_username_label">Username</string>
|
<string name="account_setup_incoming_username_label">Username</string>
|
||||||
<string name="account_setup_incoming_password_label">Password</string>
|
<string name="account_setup_incoming_password_label">Password</string>
|
||||||
|
@ -18,6 +18,7 @@ import com.fsck.k9.*;
|
|||||||
import com.fsck.k9.activity.K9Activity;
|
import com.fsck.k9.activity.K9Activity;
|
||||||
import com.fsck.k9.activity.setup.AccountSetupCheckSettings.CheckDirection;
|
import com.fsck.k9.activity.setup.AccountSetupCheckSettings.CheckDirection;
|
||||||
import com.fsck.k9.helper.Utility;
|
import com.fsck.k9.helper.Utility;
|
||||||
|
import com.fsck.k9.mail.AuthType;
|
||||||
import com.fsck.k9.mail.ConnectionSecurity;
|
import com.fsck.k9.mail.ConnectionSecurity;
|
||||||
import com.fsck.k9.mail.ServerSettings;
|
import com.fsck.k9.mail.ServerSettings;
|
||||||
import com.fsck.k9.mail.Store;
|
import com.fsck.k9.mail.Store;
|
||||||
@ -58,11 +59,6 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||||||
ConnectionSecurity.STARTTLS_REQUIRED
|
ConnectionSecurity.STARTTLS_REQUIRED
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final String[] AUTH_TYPES = {
|
|
||||||
"PLAIN", "CRAM_MD5"
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
private int[] mAccountPorts;
|
private int[] mAccountPorts;
|
||||||
private String mStoreType;
|
private String mStoreType;
|
||||||
private EditText mUsernameView;
|
private EditText mUsernameView;
|
||||||
@ -83,6 +79,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||||||
private CheckBox mCompressionWifi;
|
private CheckBox mCompressionWifi;
|
||||||
private CheckBox mCompressionOther;
|
private CheckBox mCompressionOther;
|
||||||
private CheckBox mSubscribedFoldersOnly;
|
private CheckBox mSubscribedFoldersOnly;
|
||||||
|
private ArrayAdapter<AuthType> mAuthTypeAdapter;
|
||||||
|
|
||||||
public static void actionIncomingSettings(Activity context, Account account, boolean makeDefault) {
|
public static void actionIncomingSettings(Activity context, Account account, boolean makeDefault) {
|
||||||
Intent i = new Intent(context, AccountSetupIncoming.class);
|
Intent i = new Intent(context, AccountSetupIncoming.class);
|
||||||
@ -149,22 +146,16 @@ public class AccountSetupIncoming 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, AUTH_TYPES[0]),
|
|
||||||
new SpinnerOption(1, AUTH_TYPES[1])
|
|
||||||
};
|
|
||||||
|
|
||||||
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,
|
AuthType[] acceptableAuthTypes = {AuthType.PLAIN, AuthType.CRAM_MD5};
|
||||||
android.R.layout.simple_spinner_item, authTypeSpinnerOptions);
|
mAuthTypeAdapter = new ArrayAdapter<AuthType>(this,
|
||||||
authTypesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
android.R.layout.simple_spinner_item, acceptableAuthTypes);
|
||||||
mAuthTypeView.setAdapter(authTypesAdapter);
|
mAuthTypeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||||
|
mAuthTypeView.setAdapter(mAuthTypeAdapter);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Calls validateFields() which enables or disables the Next button
|
* Calls validateFields() which enables or disables the Next button
|
||||||
@ -217,13 +208,9 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||||||
mPasswordView.setText(settings.password);
|
mPasswordView.setText(settings.password);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings.authenticationType != null) {
|
// The first item is selected if settings.authenticationType is null or is not in mAuthTypeAdapter
|
||||||
for (int i = 0; i < AUTH_TYPES.length; i++) {
|
int position = mAuthTypeAdapter.getPosition(settings.authenticationType);
|
||||||
if (AUTH_TYPES[i].equals(settings.authenticationType)) {
|
mAuthTypeView.setSelection(position, false);
|
||||||
SpinnerOption.setSpinnerOptionValue(mAuthTypeView, i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mStoreType = settings.type;
|
mStoreType = settings.type;
|
||||||
if (Pop3Store.STORE_TYPE.equals(settings.type)) {
|
if (Pop3Store.STORE_TYPE.equals(settings.type)) {
|
||||||
@ -407,7 +394,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||||||
|
|
||||||
String username = mUsernameView.getText().toString();
|
String username = mUsernameView.getText().toString();
|
||||||
String password = mPasswordView.getText().toString();
|
String password = mPasswordView.getText().toString();
|
||||||
String authType = ((SpinnerOption)mAuthTypeView.getSelectedItem()).label;
|
AuthType authType = (AuthType) mAuthTypeView.getSelectedItem();
|
||||||
String host = mServerView.getText().toString();
|
String host = mServerView.getText().toString();
|
||||||
int port = Integer.parseInt(mPortView.getText().toString());
|
int port = Integer.parseInt(mPortView.getText().toString());
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ import com.fsck.k9.*;
|
|||||||
import com.fsck.k9.activity.K9Activity;
|
import com.fsck.k9.activity.K9Activity;
|
||||||
import com.fsck.k9.activity.setup.AccountSetupCheckSettings.CheckDirection;
|
import com.fsck.k9.activity.setup.AccountSetupCheckSettings.CheckDirection;
|
||||||
import com.fsck.k9.helper.Utility;
|
import com.fsck.k9.helper.Utility;
|
||||||
import com.fsck.k9.mail.transport.SmtpTransport;
|
import com.fsck.k9.mail.AuthType;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
@ -48,13 +48,6 @@ 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[] = {
|
|
||||||
SmtpTransport.AUTH_AUTOMATIC,
|
|
||||||
SmtpTransport.AUTH_LOGIN,
|
|
||||||
SmtpTransport.AUTH_PLAIN,
|
|
||||||
SmtpTransport.AUTH_CRAM_MD5,
|
|
||||||
};
|
|
||||||
|
|
||||||
private EditText mUsernameView;
|
private EditText mUsernameView;
|
||||||
private EditText mPasswordView;
|
private EditText mPasswordView;
|
||||||
private EditText mServerView;
|
private EditText mServerView;
|
||||||
@ -127,18 +120,13 @@ 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)),
|
||||||
};
|
};
|
||||||
|
|
||||||
SpinnerOption authTypeSpinnerOptions[] = new SpinnerOption[authTypes.length];
|
|
||||||
for (int i = 0; i < authTypes.length; i++) {
|
|
||||||
authTypeSpinnerOptions[i] = new SpinnerOption(i, authTypes[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
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,
|
ArrayAdapter<AuthType> authTypesAdapter = new ArrayAdapter<AuthType>(this,
|
||||||
android.R.layout.simple_spinner_item, authTypeSpinnerOptions);
|
android.R.layout.simple_spinner_item, AuthType.values());
|
||||||
authTypesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
authTypesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||||
mAuthTypeView.setAdapter(authTypesAdapter);
|
mAuthTypeView.setAdapter(authTypesAdapter);
|
||||||
|
|
||||||
@ -208,11 +196,8 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (authType != null) {
|
if (authType != null) {
|
||||||
for (int i = 0; i < authTypes.length; i++) {
|
int position = AuthType.valueOf(authType).ordinal();
|
||||||
if (authTypes[i].equals(authType)) {
|
mAuthTypeView.setSelection(position, false);
|
||||||
SpinnerOption.setSpinnerOptionValue(mAuthTypeView, i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Select currently configured security type
|
// Select currently configured security type
|
||||||
@ -305,7 +290,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
|
|||||||
String passwordEnc = URLEncoder.encode(mPasswordView.getText().toString(), "UTF-8");
|
String passwordEnc = URLEncoder.encode(mPasswordView.getText().toString(), "UTF-8");
|
||||||
|
|
||||||
String userInfo = null;
|
String userInfo = null;
|
||||||
String authType = ((SpinnerOption)mAuthTypeView.getSelectedItem()).label;
|
String authType = ((AuthType) mAuthTypeView.getSelectedItem()).name();
|
||||||
if (mRequireLoginView.isChecked()) {
|
if (mRequireLoginView.isChecked()) {
|
||||||
userInfo = usernameEnc + ":" + passwordEnc + ":" + authType;
|
userInfo = usernameEnc + ":" + passwordEnc + ":" + authType;
|
||||||
}
|
}
|
||||||
|
32
src/com/fsck/k9/mail/AuthType.java
Normal file
32
src/com/fsck/k9/mail/AuthType.java
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package com.fsck.k9.mail;
|
||||||
|
|
||||||
|
import com.fsck.k9.K9;
|
||||||
|
import com.fsck.k9.R;
|
||||||
|
|
||||||
|
public enum AuthType {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The names of these auth. types are saved as strings when settings are
|
||||||
|
* exported, and are also saved as part of the Server URI saved in the
|
||||||
|
* account settings.
|
||||||
|
*/
|
||||||
|
AUTOMATIC(R.string.account_setup_auth_type_automatic),
|
||||||
|
PLAIN(R.string.account_setup_auth_type_normal_password),
|
||||||
|
CRAM_MD5(R.string.account_setup_auth_type_encrypted_password),
|
||||||
|
LOGIN(0);
|
||||||
|
|
||||||
|
private final int mResourceId;
|
||||||
|
|
||||||
|
private AuthType(int id) {
|
||||||
|
mResourceId = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
if (mResourceId == 0) {
|
||||||
|
return name();
|
||||||
|
} else {
|
||||||
|
return K9.app.getString(mResourceId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -48,7 +48,7 @@ public class ServerSettings {
|
|||||||
*
|
*
|
||||||
* {@code null} if not applicable for the store or transport.
|
* {@code null} if not applicable for the store or transport.
|
||||||
*/
|
*/
|
||||||
public final String authenticationType;
|
public final AuthType authenticationType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The username part of the credentials needed to authenticate to the server.
|
* The username part of the credentials needed to authenticate to the server.
|
||||||
@ -91,7 +91,7 @@ public class ServerSettings {
|
|||||||
* see {@link ServerSettings#password}
|
* see {@link ServerSettings#password}
|
||||||
*/
|
*/
|
||||||
public ServerSettings(String type, String host, int port,
|
public ServerSettings(String type, String host, int port,
|
||||||
ConnectionSecurity connectionSecurity, String authenticationType, String username,
|
ConnectionSecurity connectionSecurity, AuthType authenticationType, String username,
|
||||||
String password) {
|
String password) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.host = host;
|
this.host = host;
|
||||||
@ -124,7 +124,7 @@ public class ServerSettings {
|
|||||||
* see {@link ServerSettings#extra}
|
* see {@link ServerSettings#extra}
|
||||||
*/
|
*/
|
||||||
public ServerSettings(String type, String host, int port,
|
public ServerSettings(String type, String host, int port,
|
||||||
ConnectionSecurity connectionSecurity, String authenticationType, String username,
|
ConnectionSecurity connectionSecurity, AuthType authenticationType, String username,
|
||||||
String password, Map<String, String> extra) {
|
String password, Map<String, String> extra) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.host = host;
|
this.host = host;
|
||||||
|
@ -69,6 +69,7 @@ import com.fsck.k9.helper.StringUtils;
|
|||||||
import com.fsck.k9.helper.Utility;
|
import com.fsck.k9.helper.Utility;
|
||||||
import com.fsck.k9.helper.power.TracingPowerManager;
|
import com.fsck.k9.helper.power.TracingPowerManager;
|
||||||
import com.fsck.k9.helper.power.TracingPowerManager.TracingWakeLock;
|
import com.fsck.k9.helper.power.TracingPowerManager.TracingWakeLock;
|
||||||
|
import com.fsck.k9.mail.AuthType;
|
||||||
import com.fsck.k9.mail.Authentication;
|
import com.fsck.k9.mail.Authentication;
|
||||||
import com.fsck.k9.mail.AuthenticationFailedException;
|
import com.fsck.k9.mail.AuthenticationFailedException;
|
||||||
import com.fsck.k9.mail.Body;
|
import com.fsck.k9.mail.Body;
|
||||||
@ -117,8 +118,6 @@ public class ImapStore extends Store {
|
|||||||
public static final int CONNECTION_SECURITY_SSL_REQUIRED = 3;
|
public static final int CONNECTION_SECURITY_SSL_REQUIRED = 3;
|
||||||
public static final int CONNECTION_SECURITY_SSL_OPTIONAL = 4;
|
public static final int CONNECTION_SECURITY_SSL_OPTIONAL = 4;
|
||||||
|
|
||||||
public enum AuthType { PLAIN, CRAM_MD5 }
|
|
||||||
|
|
||||||
private static final int IDLE_READ_TIMEOUT_INCREMENT = 5 * 60 * 1000;
|
private static final int IDLE_READ_TIMEOUT_INCREMENT = 5 * 60 * 1000;
|
||||||
private static final int IDLE_FAILURE_COUNT_LIMIT = 10;
|
private static final int IDLE_FAILURE_COUNT_LIMIT = 10;
|
||||||
private static int MAX_DELAY_TIME = 5 * 60 * 1000; // 5 minutes
|
private static int MAX_DELAY_TIME = 5 * 60 * 1000; // 5 minutes
|
||||||
@ -163,7 +162,7 @@ public class ImapStore extends Store {
|
|||||||
String host;
|
String host;
|
||||||
int port;
|
int port;
|
||||||
ConnectionSecurity connectionSecurity;
|
ConnectionSecurity connectionSecurity;
|
||||||
String authenticationType = null;
|
AuthType authenticationType = null;
|
||||||
String username = null;
|
String username = null;
|
||||||
String password = null;
|
String password = null;
|
||||||
String pathPrefix = null;
|
String pathPrefix = null;
|
||||||
@ -209,14 +208,14 @@ public class ImapStore extends Store {
|
|||||||
|
|
||||||
if (userinfo.endsWith(":")) {
|
if (userinfo.endsWith(":")) {
|
||||||
// Password is empty. This can only happen after an account was imported.
|
// Password is empty. This can only happen after an account was imported.
|
||||||
authenticationType = AuthType.valueOf(userInfoParts[0]).name();
|
authenticationType = AuthType.valueOf(userInfoParts[0]);
|
||||||
username = URLDecoder.decode(userInfoParts[1], "UTF-8");
|
username = URLDecoder.decode(userInfoParts[1], "UTF-8");
|
||||||
} else if (userInfoParts.length == 2) {
|
} else if (userInfoParts.length == 2) {
|
||||||
authenticationType = AuthType.PLAIN.name();
|
authenticationType = AuthType.PLAIN;
|
||||||
username = URLDecoder.decode(userInfoParts[0], "UTF-8");
|
username = URLDecoder.decode(userInfoParts[0], "UTF-8");
|
||||||
password = URLDecoder.decode(userInfoParts[1], "UTF-8");
|
password = URLDecoder.decode(userInfoParts[1], "UTF-8");
|
||||||
} else {
|
} else {
|
||||||
authenticationType = AuthType.valueOf(userInfoParts[0]).name();
|
authenticationType = AuthType.valueOf(userInfoParts[0]);
|
||||||
username = URLDecoder.decode(userInfoParts[1], "UTF-8");
|
username = URLDecoder.decode(userInfoParts[1], "UTF-8");
|
||||||
password = URLDecoder.decode(userInfoParts[2], "UTF-8");
|
password = URLDecoder.decode(userInfoParts[2], "UTF-8");
|
||||||
}
|
}
|
||||||
@ -291,15 +290,9 @@ public class ImapStore extends Store {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
AuthType authType;
|
AuthType authType = server.authenticationType;
|
||||||
try {
|
|
||||||
authType = AuthType.valueOf(server.authenticationType);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new IllegalArgumentException("Invalid authentication type: " +
|
|
||||||
server.authenticationType);
|
|
||||||
}
|
|
||||||
|
|
||||||
String userInfo = authType.toString() + ":" + userEnc + ":" + passwordEnc;
|
String userInfo = authType.name() + ":" + userEnc + ":" + passwordEnc;
|
||||||
try {
|
try {
|
||||||
Map<String, String> extra = server.getExtra();
|
Map<String, String> extra = server.getExtra();
|
||||||
String path = null;
|
String path = null;
|
||||||
@ -334,7 +327,7 @@ public class ImapStore extends Store {
|
|||||||
public final String pathPrefix;
|
public final String pathPrefix;
|
||||||
|
|
||||||
protected ImapStoreSettings(String host, int port, ConnectionSecurity connectionSecurity,
|
protected ImapStoreSettings(String host, int port, ConnectionSecurity connectionSecurity,
|
||||||
String authenticationType, String username, String password,
|
AuthType authenticationType, String username, String password,
|
||||||
boolean autodetectNamespace, String pathPrefix) {
|
boolean autodetectNamespace, String pathPrefix) {
|
||||||
super(STORE_TYPE, host, port, connectionSecurity, authenticationType, username,
|
super(STORE_TYPE, host, port, connectionSecurity, authenticationType, username,
|
||||||
password);
|
password);
|
||||||
@ -485,7 +478,7 @@ public class ImapStore extends Store {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
mAuthType = AuthType.valueOf(settings.authenticationType);
|
mAuthType = settings.authenticationType;
|
||||||
mUsername = settings.username;
|
mUsername = settings.username;
|
||||||
mPassword = settings.password;
|
mPassword = settings.password;
|
||||||
|
|
||||||
|
@ -43,11 +43,6 @@ public class Pop3Store extends Store {
|
|||||||
public static final int CONNECTION_SECURITY_SSL_REQUIRED = 3;
|
public static final int CONNECTION_SECURITY_SSL_REQUIRED = 3;
|
||||||
public static final int CONNECTION_SECURITY_SSL_OPTIONAL = 4;
|
public static final int CONNECTION_SECURITY_SSL_OPTIONAL = 4;
|
||||||
|
|
||||||
private enum AuthType {
|
|
||||||
PLAIN,
|
|
||||||
CRAM_MD5
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final String STLS_COMMAND = "STLS";
|
private static final String STLS_COMMAND = "STLS";
|
||||||
private static final String USER_COMMAND = "USER";
|
private static final String USER_COMMAND = "USER";
|
||||||
private static final String PASS_COMMAND = "PASS";
|
private static final String PASS_COMMAND = "PASS";
|
||||||
@ -120,7 +115,7 @@ public class Pop3Store extends Store {
|
|||||||
port = pop3Uri.getPort();
|
port = pop3Uri.getPort();
|
||||||
}
|
}
|
||||||
|
|
||||||
String authType = AuthType.PLAIN.name();
|
AuthType authType = AuthType.PLAIN;
|
||||||
if (pop3Uri.getUserInfo() != null) {
|
if (pop3Uri.getUserInfo() != null) {
|
||||||
try {
|
try {
|
||||||
int userIndex = 0, passwordIndex = 1;
|
int userIndex = 0, passwordIndex = 1;
|
||||||
@ -131,7 +126,7 @@ public class Pop3Store extends Store {
|
|||||||
// after an account was imported (so authType and username are present).
|
// after an account was imported (so authType and username are present).
|
||||||
userIndex++;
|
userIndex++;
|
||||||
passwordIndex++;
|
passwordIndex++;
|
||||||
authType = userInfoParts[0];
|
authType = AuthType.valueOf(userInfoParts[0]);
|
||||||
}
|
}
|
||||||
username = URLDecoder.decode(userInfoParts[userIndex], "UTF-8");
|
username = URLDecoder.decode(userInfoParts[userIndex], "UTF-8");
|
||||||
if (userInfoParts.length > passwordIndex) {
|
if (userInfoParts.length > passwordIndex) {
|
||||||
@ -190,14 +185,7 @@ public class Pop3Store extends Store {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
String userInfo = server.authenticationType.name() + ":" + userEnc + ":" + passwordEnc;
|
||||||
AuthType.valueOf(server.authenticationType);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new IllegalArgumentException("Invalid authentication type (" +
|
|
||||||
server.authenticationType + ")");
|
|
||||||
}
|
|
||||||
|
|
||||||
String userInfo = server.authenticationType + ":" + userEnc + ":" + passwordEnc;
|
|
||||||
try {
|
try {
|
||||||
return new URI(scheme, userInfo, server.host, server.port, null, null,
|
return new URI(scheme, userInfo, server.host, server.port, null, null,
|
||||||
null).toString();
|
null).toString();
|
||||||
@ -257,7 +245,7 @@ public class Pop3Store extends Store {
|
|||||||
|
|
||||||
mUsername = settings.username;
|
mUsername = settings.username;
|
||||||
mPassword = settings.password;
|
mPassword = settings.password;
|
||||||
mAuthType = AuthType.valueOf(settings.authenticationType);
|
mAuthType = settings.authenticationType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -270,7 +270,7 @@ public class WebDavStore extends Store {
|
|||||||
public final String mailboxPath;
|
public final String mailboxPath;
|
||||||
|
|
||||||
protected WebDavStoreSettings(String host, int port, ConnectionSecurity connectionSecurity,
|
protected WebDavStoreSettings(String host, int port, ConnectionSecurity connectionSecurity,
|
||||||
String authenticationType, String username, String password, String alias,
|
AuthType authenticationType, String username, String password, String alias,
|
||||||
String path, String authPath, String mailboxPath) {
|
String path, String authPath, String mailboxPath) {
|
||||||
super(STORE_TYPE, host, port, connectionSecurity, authenticationType, username,
|
super(STORE_TYPE, host, port, connectionSecurity, authenticationType, username,
|
||||||
password);
|
password);
|
||||||
|
@ -39,15 +39,6 @@ public class SmtpTransport extends Transport {
|
|||||||
public static final int CONNECTION_SECURITY_SSL_REQUIRED = 3;
|
public static final int CONNECTION_SECURITY_SSL_REQUIRED = 3;
|
||||||
public static final int CONNECTION_SECURITY_SSL_OPTIONAL = 4;
|
public static final int CONNECTION_SECURITY_SSL_OPTIONAL = 4;
|
||||||
|
|
||||||
public static final String AUTH_PLAIN = "PLAIN";
|
|
||||||
|
|
||||||
public static final String AUTH_CRAM_MD5 = "CRAM_MD5";
|
|
||||||
|
|
||||||
public static final String AUTH_LOGIN = "LOGIN";
|
|
||||||
|
|
||||||
public static final String AUTH_AUTOMATIC = "AUTOMATIC";
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decodes a SmtpTransport URI.
|
* Decodes a SmtpTransport URI.
|
||||||
*
|
*
|
||||||
@ -64,7 +55,7 @@ public class SmtpTransport extends Transport {
|
|||||||
String host;
|
String host;
|
||||||
int port;
|
int port;
|
||||||
ConnectionSecurity connectionSecurity;
|
ConnectionSecurity connectionSecurity;
|
||||||
String authenticationType = AUTH_AUTOMATIC;
|
AuthType authType = AuthType.AUTOMATIC;
|
||||||
String username = null;
|
String username = null;
|
||||||
String password = null;
|
String password = null;
|
||||||
|
|
||||||
@ -109,7 +100,7 @@ public class SmtpTransport extends Transport {
|
|||||||
password = URLDecoder.decode(userInfoParts[1], "UTF-8");
|
password = URLDecoder.decode(userInfoParts[1], "UTF-8");
|
||||||
}
|
}
|
||||||
if (userInfoParts.length > 2) {
|
if (userInfoParts.length > 2) {
|
||||||
authenticationType = userInfoParts[2];
|
authType = AuthType.valueOf(userInfoParts[2]);
|
||||||
}
|
}
|
||||||
} catch (UnsupportedEncodingException enc) {
|
} catch (UnsupportedEncodingException enc) {
|
||||||
// This shouldn't happen since the encoding is hardcoded to UTF-8
|
// This shouldn't happen since the encoding is hardcoded to UTF-8
|
||||||
@ -118,7 +109,7 @@ public class SmtpTransport extends Transport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return new ServerSettings(TRANSPORT_TYPE, host, port, connectionSecurity,
|
return new ServerSettings(TRANSPORT_TYPE, host, port, connectionSecurity,
|
||||||
authenticationType, username, password);
|
authType, username, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -165,15 +156,11 @@ public class SmtpTransport extends Transport {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
String authType = server.authenticationType;
|
String userInfo = userEnc + ":" + passwordEnc;
|
||||||
if (!(AUTH_AUTOMATIC.equals(authType) ||
|
AuthType authType = server.authenticationType;
|
||||||
AUTH_LOGIN.equals(authType) ||
|
if (authType != null) {
|
||||||
AUTH_PLAIN.equals(authType) ||
|
userInfo += ":" + authType.name();
|
||||||
AUTH_CRAM_MD5.equals(authType))) {
|
|
||||||
throw new IllegalArgumentException("Invalid authentication type: " + authType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String userInfo = userEnc + ":" + passwordEnc + ":" + authType;
|
|
||||||
try {
|
try {
|
||||||
return new URI(scheme, userInfo, server.host, server.port, null, null,
|
return new URI(scheme, userInfo, server.host, server.port, null, null,
|
||||||
null).toString();
|
null).toString();
|
||||||
@ -187,7 +174,7 @@ public class SmtpTransport extends Transport {
|
|||||||
int mPort;
|
int mPort;
|
||||||
String mUsername;
|
String mUsername;
|
||||||
String mPassword;
|
String mPassword;
|
||||||
String mAuthType;
|
AuthType mAuthType;
|
||||||
int mConnectionSecurity;
|
int mConnectionSecurity;
|
||||||
Socket mSocket;
|
Socket mSocket;
|
||||||
PeekableInputStream mIn;
|
PeekableInputStream mIn;
|
||||||
@ -318,9 +305,9 @@ public class SmtpTransport extends Transport {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean useAuthLogin = AUTH_LOGIN.equals(mAuthType);
|
boolean useAuthLogin = AuthType.LOGIN.equals(mAuthType);
|
||||||
boolean useAuthPlain = AUTH_PLAIN.equals(mAuthType);
|
boolean useAuthPlain = AuthType.PLAIN.equals(mAuthType);
|
||||||
boolean useAuthCramMD5 = AUTH_CRAM_MD5.equals(mAuthType);
|
boolean useAuthCramMD5 = AuthType.CRAM_MD5.equals(mAuthType);
|
||||||
|
|
||||||
// Automatically choose best authentication method if none was explicitly selected
|
// Automatically choose best authentication method if none was explicitly selected
|
||||||
boolean useAutomaticAuth = !(useAuthLogin || useAuthPlain || useAuthCramMD5);
|
boolean useAutomaticAuth = !(useAuthLogin || useAuthPlain || useAuthCramMD5);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.fsck.k9.mail.transport.imap;
|
package com.fsck.k9.mail.transport.imap;
|
||||||
|
|
||||||
|
import com.fsck.k9.mail.AuthType;
|
||||||
import com.fsck.k9.mail.store.ImapStore;
|
import com.fsck.k9.mail.store.ImapStore;
|
||||||
import com.fsck.k9.mail.store.ImapStore.AuthType;
|
|
||||||
import com.fsck.k9.mail.store.ImapStore.ImapConnection;
|
import com.fsck.k9.mail.store.ImapStore.ImapConnection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -230,7 +230,7 @@ public class SettingsExporter {
|
|||||||
writeElement(serializer, PORT_ELEMENT, Integer.toString(incoming.port));
|
writeElement(serializer, PORT_ELEMENT, Integer.toString(incoming.port));
|
||||||
}
|
}
|
||||||
writeElement(serializer, CONNECTION_SECURITY_ELEMENT, incoming.connectionSecurity.name());
|
writeElement(serializer, CONNECTION_SECURITY_ELEMENT, incoming.connectionSecurity.name());
|
||||||
writeElement(serializer, AUTHENTICATION_TYPE_ELEMENT, incoming.authenticationType);
|
writeElement(serializer, AUTHENTICATION_TYPE_ELEMENT, incoming.authenticationType.name());
|
||||||
writeElement(serializer, USERNAME_ELEMENT, incoming.username);
|
writeElement(serializer, USERNAME_ELEMENT, incoming.username);
|
||||||
// XXX For now we don't export the password
|
// XXX For now we don't export the password
|
||||||
//writeElement(serializer, PASSWORD_ELEMENT, incoming.password);
|
//writeElement(serializer, PASSWORD_ELEMENT, incoming.password);
|
||||||
@ -257,7 +257,7 @@ public class SettingsExporter {
|
|||||||
writeElement(serializer, PORT_ELEMENT, Integer.toString(outgoing.port));
|
writeElement(serializer, PORT_ELEMENT, Integer.toString(outgoing.port));
|
||||||
}
|
}
|
||||||
writeElement(serializer, CONNECTION_SECURITY_ELEMENT, outgoing.connectionSecurity.name());
|
writeElement(serializer, CONNECTION_SECURITY_ELEMENT, outgoing.connectionSecurity.name());
|
||||||
writeElement(serializer, AUTHENTICATION_TYPE_ELEMENT, outgoing.authenticationType);
|
writeElement(serializer, AUTHENTICATION_TYPE_ELEMENT, outgoing.authenticationType.name());
|
||||||
writeElement(serializer, USERNAME_ELEMENT, outgoing.username);
|
writeElement(serializer, USERNAME_ELEMENT, outgoing.username);
|
||||||
// XXX For now we don't export the password
|
// XXX For now we don't export the password
|
||||||
//writeElement(serializer, PASSWORD_ELEMENT, outgoing.password);
|
//writeElement(serializer, PASSWORD_ELEMENT, outgoing.password);
|
||||||
|
@ -23,6 +23,7 @@ import com.fsck.k9.Identity;
|
|||||||
import com.fsck.k9.K9;
|
import com.fsck.k9.K9;
|
||||||
import com.fsck.k9.Preferences;
|
import com.fsck.k9.Preferences;
|
||||||
import com.fsck.k9.helper.Utility;
|
import com.fsck.k9.helper.Utility;
|
||||||
|
import com.fsck.k9.mail.AuthType;
|
||||||
import com.fsck.k9.mail.ConnectionSecurity;
|
import com.fsck.k9.mail.ConnectionSecurity;
|
||||||
import com.fsck.k9.mail.ServerSettings;
|
import com.fsck.k9.mail.ServerSettings;
|
||||||
import com.fsck.k9.mail.Store;
|
import com.fsck.k9.mail.Store;
|
||||||
@ -971,7 +972,8 @@ public class SettingsImporter {
|
|||||||
} else if (SettingsExporter.CONNECTION_SECURITY_ELEMENT.equals(element)) {
|
} else if (SettingsExporter.CONNECTION_SECURITY_ELEMENT.equals(element)) {
|
||||||
server.connectionSecurity = getText(xpp);
|
server.connectionSecurity = getText(xpp);
|
||||||
} else if (SettingsExporter.AUTHENTICATION_TYPE_ELEMENT.equals(element)) {
|
} else if (SettingsExporter.AUTHENTICATION_TYPE_ELEMENT.equals(element)) {
|
||||||
server.authenticationType = getText(xpp);
|
String text = getText(xpp);
|
||||||
|
server.authenticationType = AuthType.valueOf(text);
|
||||||
} else if (SettingsExporter.USERNAME_ELEMENT.equals(element)) {
|
} else if (SettingsExporter.USERNAME_ELEMENT.equals(element)) {
|
||||||
server.username = getText(xpp);
|
server.username = getText(xpp);
|
||||||
} else if (SettingsExporter.PASSWORD_ELEMENT.equals(element)) {
|
} else if (SettingsExporter.PASSWORD_ELEMENT.equals(element)) {
|
||||||
@ -1140,7 +1142,7 @@ public class SettingsImporter {
|
|||||||
public String host;
|
public String host;
|
||||||
public String port;
|
public String port;
|
||||||
public String connectionSecurity;
|
public String connectionSecurity;
|
||||||
public String authenticationType;
|
public AuthType authenticationType;
|
||||||
public String username;
|
public String username;
|
||||||
public String password;
|
public String password;
|
||||||
public ImportedSettings extras;
|
public ImportedSettings extras;
|
||||||
|
@ -2,6 +2,8 @@ package com.fsck.k9.mail.store;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.fsck.k9.mail.AuthType;
|
||||||
import com.fsck.k9.mail.ConnectionSecurity;
|
import com.fsck.k9.mail.ConnectionSecurity;
|
||||||
import com.fsck.k9.mail.ServerSettings;
|
import com.fsck.k9.mail.ServerSettings;
|
||||||
import com.fsck.k9.mail.Store;
|
import com.fsck.k9.mail.Store;
|
||||||
@ -13,7 +15,7 @@ public class ImapStoreUriTest extends TestCase {
|
|||||||
String uri = "imap://PLAIN:user:pass@server:143/0%7CcustomPathPrefix";
|
String uri = "imap://PLAIN:user:pass@server:143/0%7CcustomPathPrefix";
|
||||||
ServerSettings settings = Store.decodeStoreUri(uri);
|
ServerSettings settings = Store.decodeStoreUri(uri);
|
||||||
|
|
||||||
assertEquals("PLAIN", settings.authenticationType);
|
assertEquals(AuthType.PLAIN, settings.authenticationType);
|
||||||
assertEquals("user", settings.username);
|
assertEquals("user", settings.username);
|
||||||
assertEquals("pass", settings.password);
|
assertEquals("pass", settings.password);
|
||||||
assertEquals("server", settings.host);
|
assertEquals("server", settings.host);
|
||||||
@ -26,7 +28,7 @@ public class ImapStoreUriTest extends TestCase {
|
|||||||
String uri = "imap://PLAIN:user:pass@server:143/";
|
String uri = "imap://PLAIN:user:pass@server:143/";
|
||||||
ServerSettings settings = Store.decodeStoreUri(uri);
|
ServerSettings settings = Store.decodeStoreUri(uri);
|
||||||
|
|
||||||
assertEquals("PLAIN", settings.authenticationType);
|
assertEquals(AuthType.PLAIN, settings.authenticationType);
|
||||||
assertEquals("user", settings.username);
|
assertEquals("user", settings.username);
|
||||||
assertEquals("pass", settings.password);
|
assertEquals("pass", settings.password);
|
||||||
assertEquals("server", settings.host);
|
assertEquals("server", settings.host);
|
||||||
@ -38,7 +40,7 @@ public class ImapStoreUriTest extends TestCase {
|
|||||||
String uri = "imap://PLAIN:user:pass@server:143/customPathPrefix";
|
String uri = "imap://PLAIN:user:pass@server:143/customPathPrefix";
|
||||||
ServerSettings settings = Store.decodeStoreUri(uri);
|
ServerSettings settings = Store.decodeStoreUri(uri);
|
||||||
|
|
||||||
assertEquals("PLAIN", settings.authenticationType);
|
assertEquals(AuthType.PLAIN, settings.authenticationType);
|
||||||
assertEquals("user", settings.username);
|
assertEquals("user", settings.username);
|
||||||
assertEquals("pass", settings.password);
|
assertEquals("pass", settings.password);
|
||||||
assertEquals("server", settings.host);
|
assertEquals("server", settings.host);
|
||||||
@ -51,7 +53,7 @@ public class ImapStoreUriTest extends TestCase {
|
|||||||
String uri = "imap://PLAIN:user:pass@server:143/0%7C";
|
String uri = "imap://PLAIN:user:pass@server:143/0%7C";
|
||||||
ServerSettings settings = Store.decodeStoreUri(uri);
|
ServerSettings settings = Store.decodeStoreUri(uri);
|
||||||
|
|
||||||
assertEquals("PLAIN", settings.authenticationType);
|
assertEquals(AuthType.PLAIN, settings.authenticationType);
|
||||||
assertEquals("user", settings.username);
|
assertEquals("user", settings.username);
|
||||||
assertEquals("pass", settings.password);
|
assertEquals("pass", settings.password);
|
||||||
assertEquals("server", settings.host);
|
assertEquals("server", settings.host);
|
||||||
@ -64,7 +66,7 @@ public class ImapStoreUriTest extends TestCase {
|
|||||||
String uri = "imap://PLAIN:user:pass@server:143/1%7CcustomPathPrefix";
|
String uri = "imap://PLAIN:user:pass@server:143/1%7CcustomPathPrefix";
|
||||||
ServerSettings settings = Store.decodeStoreUri(uri);
|
ServerSettings settings = Store.decodeStoreUri(uri);
|
||||||
|
|
||||||
assertEquals("PLAIN", settings.authenticationType);
|
assertEquals(AuthType.PLAIN, settings.authenticationType);
|
||||||
assertEquals("user", settings.username);
|
assertEquals("user", settings.username);
|
||||||
assertEquals("pass", settings.password);
|
assertEquals("pass", settings.password);
|
||||||
assertEquals("server", settings.host);
|
assertEquals("server", settings.host);
|
||||||
@ -80,7 +82,7 @@ public class ImapStoreUriTest extends TestCase {
|
|||||||
extra.put("pathPrefix", "customPathPrefix");
|
extra.put("pathPrefix", "customPathPrefix");
|
||||||
|
|
||||||
ServerSettings settings = new ServerSettings(ImapStore.STORE_TYPE, "server", 143,
|
ServerSettings settings = new ServerSettings(ImapStore.STORE_TYPE, "server", 143,
|
||||||
ConnectionSecurity.NONE, "PLAIN", "user", "pass", extra);
|
ConnectionSecurity.NONE, AuthType.PLAIN, "user", "pass", extra);
|
||||||
|
|
||||||
String uri = Store.createStoreUri(settings);
|
String uri = Store.createStoreUri(settings);
|
||||||
|
|
||||||
@ -93,7 +95,7 @@ public class ImapStoreUriTest extends TestCase {
|
|||||||
extra.put("pathPrefix", "");
|
extra.put("pathPrefix", "");
|
||||||
|
|
||||||
ServerSettings settings = new ServerSettings(ImapStore.STORE_TYPE, "server", 143,
|
ServerSettings settings = new ServerSettings(ImapStore.STORE_TYPE, "server", 143,
|
||||||
ConnectionSecurity.NONE, "PLAIN", "user", "pass", extra);
|
ConnectionSecurity.NONE, AuthType.PLAIN, "user", "pass", extra);
|
||||||
|
|
||||||
String uri = Store.createStoreUri(settings);
|
String uri = Store.createStoreUri(settings);
|
||||||
|
|
||||||
@ -102,7 +104,7 @@ public class ImapStoreUriTest extends TestCase {
|
|||||||
|
|
||||||
public void testCreateStoreUriImapNoExtra() {
|
public void testCreateStoreUriImapNoExtra() {
|
||||||
ServerSettings settings = new ServerSettings(ImapStore.STORE_TYPE, "server", 143,
|
ServerSettings settings = new ServerSettings(ImapStore.STORE_TYPE, "server", 143,
|
||||||
ConnectionSecurity.NONE, "PLAIN", "user", "pass");
|
ConnectionSecurity.NONE, AuthType.PLAIN, "user", "pass");
|
||||||
|
|
||||||
String uri = Store.createStoreUri(settings);
|
String uri = Store.createStoreUri(settings);
|
||||||
|
|
||||||
@ -114,7 +116,7 @@ public class ImapStoreUriTest extends TestCase {
|
|||||||
extra.put("autoDetectNamespace", "true");
|
extra.put("autoDetectNamespace", "true");
|
||||||
|
|
||||||
ServerSettings settings = new ServerSettings(ImapStore.STORE_TYPE, "server", 143,
|
ServerSettings settings = new ServerSettings(ImapStore.STORE_TYPE, "server", 143,
|
||||||
ConnectionSecurity.NONE, "PLAIN", "user", "pass", extra);
|
ConnectionSecurity.NONE, AuthType.PLAIN, "user", "pass", extra);
|
||||||
|
|
||||||
String uri = Store.createStoreUri(settings);
|
String uri = Store.createStoreUri(settings);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user