mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-30 13:12:25 -05:00
Simplify code with better use of enum ConnectionSecurity
This commit is contained in:
parent
90fedf7125
commit
c7e46faf0a
@ -39,27 +39,13 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
||||
private static final String EXTRA_ACCOUNT = "account";
|
||||
private static final String EXTRA_MAKE_DEFAULT = "makeDefault";
|
||||
|
||||
private static final int[] POP3_PORTS = {
|
||||
110, 995, 995, 110, 110
|
||||
};
|
||||
private static final String POP3_PORT = "110";
|
||||
private static final String POP3_SSL_PORT = "995";
|
||||
private static final String IMAP_PORT = "143";
|
||||
private static final String IMAP_SSL_PORT = "993";
|
||||
private static final String WEBDAV_PORT = "80";
|
||||
private static final String WEBDAV_SSL_PORT = "443";
|
||||
|
||||
private static final int[] IMAP_PORTS = {
|
||||
143, 993, 993, 143, 143
|
||||
};
|
||||
|
||||
private static final int[] WEBDAV_PORTS = {
|
||||
80, 443, 443, 443, 443
|
||||
};
|
||||
|
||||
private static final ConnectionSecurity[] CONNECTION_SECURITY_TYPES = {
|
||||
ConnectionSecurity.NONE,
|
||||
ConnectionSecurity.SSL_TLS_OPTIONAL,
|
||||
ConnectionSecurity.SSL_TLS_REQUIRED,
|
||||
ConnectionSecurity.STARTTLS_OPTIONAL,
|
||||
ConnectionSecurity.STARTTLS_REQUIRED
|
||||
};
|
||||
|
||||
private int[] mAccountPorts;
|
||||
private String mStoreType;
|
||||
private EditText mUsernameView;
|
||||
private EditText mPasswordView;
|
||||
@ -80,6 +66,8 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
||||
private CheckBox mCompressionOther;
|
||||
private CheckBox mSubscribedFoldersOnly;
|
||||
private ArrayAdapter<AuthType> mAuthTypeAdapter;
|
||||
private String mDefaultPort = "";
|
||||
private String mDefaultSslPort = "";
|
||||
|
||||
public static void actionIncomingSettings(Activity context, Account account, boolean makeDefault) {
|
||||
Intent i = new Intent(context, AccountSetupIncoming.class);
|
||||
@ -136,18 +124,8 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
||||
}
|
||||
});
|
||||
|
||||
SpinnerOption securityTypes[] = {
|
||||
new SpinnerOption(0, getString(R.string.account_setup_incoming_security_none_label)),
|
||||
new SpinnerOption(1,
|
||||
getString(R.string.account_setup_incoming_security_ssl_optional_label)),
|
||||
new SpinnerOption(2, getString(R.string.account_setup_incoming_security_ssl_label)),
|
||||
new SpinnerOption(3,
|
||||
getString(R.string.account_setup_incoming_security_tls_optional_label)),
|
||||
new SpinnerOption(4, getString(R.string.account_setup_incoming_security_tls_label)),
|
||||
};
|
||||
|
||||
ArrayAdapter<SpinnerOption> securityTypesAdapter = new ArrayAdapter<SpinnerOption>(this,
|
||||
android.R.layout.simple_spinner_item, securityTypes);
|
||||
ArrayAdapter<ConnectionSecurity> securityTypesAdapter = new ArrayAdapter<ConnectionSecurity>(this,
|
||||
android.R.layout.simple_spinner_item, ConnectionSecurity.values());
|
||||
securityTypesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
mSecurityTypeView.setAdapter(securityTypesAdapter);
|
||||
|
||||
@ -212,10 +190,14 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
||||
int position = mAuthTypeAdapter.getPosition(settings.authenticationType);
|
||||
mAuthTypeView.setSelection(position, false);
|
||||
|
||||
// Select currently configured security type
|
||||
mSecurityTypeView.setSelection(settings.connectionSecurity.ordinal(), false);
|
||||
|
||||
mStoreType = settings.type;
|
||||
if (Pop3Store.STORE_TYPE.equals(settings.type)) {
|
||||
serverLabelView.setText(R.string.account_setup_incoming_pop_server_label);
|
||||
mAccountPorts = POP3_PORTS;
|
||||
mDefaultPort = POP3_PORT;
|
||||
mDefaultSslPort = POP3_SSL_PORT;
|
||||
findViewById(R.id.imap_path_prefix_section).setVisibility(View.GONE);
|
||||
findViewById(R.id.webdav_advanced_header).setVisibility(View.GONE);
|
||||
findViewById(R.id.webdav_mailbox_alias_section).setVisibility(View.GONE);
|
||||
@ -227,7 +209,8 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
||||
mAccount.setDeletePolicy(Account.DELETE_POLICY_NEVER);
|
||||
} else if (ImapStore.STORE_TYPE.equals(settings.type)) {
|
||||
serverLabelView.setText(R.string.account_setup_incoming_imap_server_label);
|
||||
mAccountPorts = IMAP_PORTS;
|
||||
mDefaultPort = IMAP_PORT;
|
||||
mDefaultSslPort = IMAP_SSL_PORT;
|
||||
|
||||
ImapStoreSettings imapSettings = (ImapStoreSettings) settings;
|
||||
|
||||
@ -247,7 +230,8 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
||||
}
|
||||
} else if (WebDavStore.STORE_TYPE.equals(settings.type)) {
|
||||
serverLabelView.setText(R.string.account_setup_incoming_webdav_server_label);
|
||||
mAccountPorts = WEBDAV_PORTS;
|
||||
mDefaultPort = WEBDAV_PORT;
|
||||
mDefaultSslPort = WEBDAV_SSL_PORT;
|
||||
|
||||
// Hide the unnecessary fields
|
||||
findViewById(R.id.imap_path_prefix_section).setVisibility(View.GONE);
|
||||
@ -275,13 +259,6 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
||||
throw new Exception("Unknown account type: " + mAccount.getStoreUri());
|
||||
}
|
||||
|
||||
// Select currently configured security type
|
||||
for (int i = 0; i < CONNECTION_SECURITY_TYPES.length; i++) {
|
||||
if (CONNECTION_SECURITY_TYPES[i] == settings.connectionSecurity) {
|
||||
SpinnerOption.setSpinnerOptionValue(mSecurityTypeView, i);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Updates the port when the user changes the security type. This allows
|
||||
* us to show a reasonable default which the user can change.
|
||||
@ -340,10 +317,38 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
||||
}
|
||||
|
||||
private void updatePortFromSecurityType() {
|
||||
if (mAccountPorts != null) {
|
||||
int securityType = (Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value;
|
||||
mPortView.setText(Integer.toString(mAccountPorts[securityType]));
|
||||
ConnectionSecurity securityType = (ConnectionSecurity) mSecurityTypeView.getSelectedItem();
|
||||
mPortView.setText(getDefaultPort(securityType));
|
||||
}
|
||||
|
||||
private String getDefaultPort(ConnectionSecurity securityType) {
|
||||
String port;
|
||||
switch (securityType) {
|
||||
case NONE:
|
||||
port = mDefaultPort;
|
||||
break;
|
||||
case STARTTLS_OPTIONAL:
|
||||
case STARTTLS_REQUIRED:
|
||||
if (WebDavStore.STORE_TYPE.equals(mStoreType)) {
|
||||
/*
|
||||
* The concept of STARTTLS is not really applicable for WebDav and should never
|
||||
* have been made a user-selectable option. But now we must support the setting
|
||||
* if it exists.
|
||||
*/
|
||||
port = mDefaultSslPort;
|
||||
} else {
|
||||
port = mDefaultPort;
|
||||
}
|
||||
break;
|
||||
case SSL_TLS_OPTIONAL:
|
||||
case SSL_TLS_REQUIRED:
|
||||
port = mDefaultSslPort;
|
||||
break;
|
||||
default:
|
||||
Log.e(K9.LOG_TAG, "Unhandled ConnectionSecurity type encountered");
|
||||
port = "";
|
||||
}
|
||||
return port;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -389,8 +394,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
||||
|
||||
protected void onNext() {
|
||||
try {
|
||||
ConnectionSecurity connectionSecurity = CONNECTION_SECURITY_TYPES[
|
||||
(Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value];
|
||||
ConnectionSecurity connectionSecurity = (ConnectionSecurity) mSecurityTypeView.getSelectedItem();
|
||||
|
||||
String username = mUsernameView.getText().toString();
|
||||
String password = mPasswordView.getText().toString();
|
||||
|
@ -18,6 +18,7 @@ import com.fsck.k9.activity.K9Activity;
|
||||
import com.fsck.k9.activity.setup.AccountSetupCheckSettings.CheckDirection;
|
||||
import com.fsck.k9.helper.Utility;
|
||||
import com.fsck.k9.mail.AuthType;
|
||||
import com.fsck.k9.mail.ConnectionSecurity;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URI;
|
||||
@ -31,23 +32,12 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
|
||||
|
||||
private static final String EXTRA_MAKE_DEFAULT = "makeDefault";
|
||||
|
||||
private static final int smtpPorts[] = {
|
||||
587, 465, 465, 587, 587
|
||||
};
|
||||
private static final String SMTP_PORT = "587";
|
||||
private static final String SMTP_SSL_PORT = "465";
|
||||
|
||||
private static final String smtpSchemes[] = {
|
||||
"smtp", "smtp+ssl", "smtp+ssl+", "smtp+tls", "smtp+tls+"
|
||||
};
|
||||
/*
|
||||
private static final int webdavPorts[] =
|
||||
{
|
||||
80, 443, 443, 443, 443
|
||||
};
|
||||
private static final String webdavSchemes[] =
|
||||
{
|
||||
"webdav", "webdav+ssl", "webdav+ssl+", "webdav+tls", "webdav+tls+"
|
||||
};
|
||||
*/
|
||||
private EditText mUsernameView;
|
||||
private EditText mPasswordView;
|
||||
private EditText mServerView;
|
||||
@ -111,18 +101,8 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
|
||||
mNextButton.setOnClickListener(this);
|
||||
mRequireLoginView.setOnCheckedChangeListener(this);
|
||||
|
||||
SpinnerOption securityTypes[] = {
|
||||
new SpinnerOption(0, getString(R.string.account_setup_incoming_security_none_label)),
|
||||
new SpinnerOption(1,
|
||||
getString(R.string.account_setup_incoming_security_ssl_optional_label)),
|
||||
new SpinnerOption(2, getString(R.string.account_setup_incoming_security_ssl_label)),
|
||||
new SpinnerOption(3,
|
||||
getString(R.string.account_setup_incoming_security_tls_optional_label)),
|
||||
new SpinnerOption(4, getString(R.string.account_setup_incoming_security_tls_label)),
|
||||
};
|
||||
|
||||
ArrayAdapter<SpinnerOption> securityTypesAdapter = new ArrayAdapter<SpinnerOption>(this,
|
||||
android.R.layout.simple_spinner_item, securityTypes);
|
||||
ArrayAdapter<ConnectionSecurity> securityTypesAdapter = new ArrayAdapter<ConnectionSecurity>(this,
|
||||
android.R.layout.simple_spinner_item, ConnectionSecurity.values());
|
||||
securityTypesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
mSecurityTypeView.setAdapter(securityTypesAdapter);
|
||||
|
||||
@ -267,8 +247,27 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
|
||||
}
|
||||
|
||||
private void updatePortFromSecurityType() {
|
||||
int securityType = (Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value;
|
||||
mPortView.setText(Integer.toString(smtpPorts[securityType]));
|
||||
ConnectionSecurity securityType = (ConnectionSecurity) mSecurityTypeView.getSelectedItem();
|
||||
mPortView.setText(getDefaultSmtpPort(securityType));
|
||||
}
|
||||
|
||||
private String getDefaultSmtpPort(ConnectionSecurity securityType) {
|
||||
String port;
|
||||
switch (securityType) {
|
||||
case NONE:
|
||||
case STARTTLS_OPTIONAL:
|
||||
case STARTTLS_REQUIRED:
|
||||
port = SMTP_PORT;
|
||||
break;
|
||||
case SSL_TLS_OPTIONAL:
|
||||
case SSL_TLS_REQUIRED:
|
||||
port = SMTP_SSL_PORT;
|
||||
break;
|
||||
default:
|
||||
port = "";
|
||||
Log.e(K9.LOG_TAG, "Unhandled ConnectionSecurity type encountered");
|
||||
}
|
||||
return port;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,19 +1,23 @@
|
||||
package com.fsck.k9.mail;
|
||||
|
||||
/**
|
||||
* The currently available connection security types.
|
||||
*
|
||||
* <p>
|
||||
* Right now this enum is only used by {@link ServerSettings} and converted to store- or
|
||||
* transport-specific constants in the different {@link Store} and {@link Transport}
|
||||
* implementations. In the future we probably want to change this and use
|
||||
* {@code ConnectionSecurity} exclusively.
|
||||
* </p>
|
||||
*/
|
||||
import com.fsck.k9.K9;
|
||||
import com.fsck.k9.R;
|
||||
|
||||
public enum ConnectionSecurity {
|
||||
NONE,
|
||||
STARTTLS_OPTIONAL,
|
||||
STARTTLS_REQUIRED,
|
||||
SSL_TLS_OPTIONAL,
|
||||
SSL_TLS_REQUIRED
|
||||
NONE(R.string.account_setup_incoming_security_none_label),
|
||||
STARTTLS_OPTIONAL(R.string.account_setup_incoming_security_tls_optional_label),
|
||||
STARTTLS_REQUIRED(R.string.account_setup_incoming_security_tls_label),
|
||||
SSL_TLS_OPTIONAL(R.string.account_setup_incoming_security_ssl_optional_label),
|
||||
SSL_TLS_REQUIRED(R.string.account_setup_incoming_security_ssl_label);
|
||||
|
||||
private final int mResourceId;
|
||||
|
||||
private ConnectionSecurity(int id) {
|
||||
mResourceId = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return K9.app.getString(mResourceId);
|
||||
}
|
||||
}
|
||||
|
@ -112,12 +112,6 @@ import com.jcraft.jzlib.ZOutputStream;
|
||||
public class ImapStore extends Store {
|
||||
public static final String STORE_TYPE = "IMAP";
|
||||
|
||||
public static final int CONNECTION_SECURITY_NONE = 0;
|
||||
public static final int CONNECTION_SECURITY_TLS_OPTIONAL = 1;
|
||||
public static final int CONNECTION_SECURITY_TLS_REQUIRED = 2;
|
||||
public static final int CONNECTION_SECURITY_SSL_REQUIRED = 3;
|
||||
public static final int CONNECTION_SECURITY_SSL_OPTIONAL = 4;
|
||||
|
||||
private static final int IDLE_READ_TIMEOUT_INCREMENT = 5 * 60 * 1000;
|
||||
private static final int IDLE_FAILURE_COUNT_LIMIT = 10;
|
||||
private static int MAX_DELAY_TIME = 5 * 60 * 1000; // 5 minutes
|
||||
@ -355,7 +349,7 @@ public class ImapStore extends Store {
|
||||
private int mPort;
|
||||
private String mUsername;
|
||||
private String mPassword;
|
||||
private int mConnectionSecurity;
|
||||
private ConnectionSecurity mConnectionSecurity;
|
||||
private AuthType mAuthType;
|
||||
private volatile String mPathPrefix;
|
||||
private volatile String mCombinedPrefix = null;
|
||||
@ -374,7 +368,7 @@ public class ImapStore extends Store {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getConnectionSecurity() {
|
||||
public ConnectionSecurity getConnectionSecurity() {
|
||||
return mConnectionSecurity;
|
||||
}
|
||||
|
||||
@ -460,23 +454,7 @@ public class ImapStore extends Store {
|
||||
mHost = settings.host;
|
||||
mPort = settings.port;
|
||||
|
||||
switch (settings.connectionSecurity) {
|
||||
case NONE:
|
||||
mConnectionSecurity = CONNECTION_SECURITY_NONE;
|
||||
break;
|
||||
case STARTTLS_OPTIONAL:
|
||||
mConnectionSecurity = CONNECTION_SECURITY_TLS_OPTIONAL;
|
||||
break;
|
||||
case STARTTLS_REQUIRED:
|
||||
mConnectionSecurity = CONNECTION_SECURITY_TLS_REQUIRED;
|
||||
break;
|
||||
case SSL_TLS_OPTIONAL:
|
||||
mConnectionSecurity = CONNECTION_SECURITY_SSL_OPTIONAL;
|
||||
break;
|
||||
case SSL_TLS_REQUIRED:
|
||||
mConnectionSecurity = CONNECTION_SECURITY_SSL_REQUIRED;
|
||||
break;
|
||||
}
|
||||
mConnectionSecurity = settings.connectionSecurity;
|
||||
|
||||
mAuthType = settings.authenticationType;
|
||||
mUsername = settings.username;
|
||||
@ -2427,7 +2405,7 @@ public class ImapStore extends Store {
|
||||
}
|
||||
|
||||
try {
|
||||
int connectionSecurity = mSettings.getConnectionSecurity();
|
||||
ConnectionSecurity connectionSecurity = mSettings.getConnectionSecurity();
|
||||
|
||||
// Try all IPv4 and IPv6 addresses of the host
|
||||
InetAddress[] addresses = InetAddress.getAllByName(mSettings.getHost());
|
||||
@ -2441,10 +2419,10 @@ public class ImapStore extends Store {
|
||||
SocketAddress socketAddress = new InetSocketAddress(addresses[i],
|
||||
mSettings.getPort());
|
||||
|
||||
if (connectionSecurity == CONNECTION_SECURITY_SSL_REQUIRED ||
|
||||
connectionSecurity == CONNECTION_SECURITY_SSL_OPTIONAL) {
|
||||
if (connectionSecurity == ConnectionSecurity.SSL_TLS_REQUIRED ||
|
||||
connectionSecurity == ConnectionSecurity.SSL_TLS_OPTIONAL) {
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
boolean secure = connectionSecurity == CONNECTION_SECURITY_SSL_REQUIRED;
|
||||
boolean secure = connectionSecurity == ConnectionSecurity.SSL_TLS_REQUIRED;
|
||||
sslContext
|
||||
.init(null,
|
||||
new TrustManager[] { TrustManagerFactory.get(
|
||||
@ -2494,15 +2472,15 @@ public class ImapStore extends Store {
|
||||
}
|
||||
}
|
||||
|
||||
if (mSettings.getConnectionSecurity() == CONNECTION_SECURITY_TLS_OPTIONAL
|
||||
|| mSettings.getConnectionSecurity() == CONNECTION_SECURITY_TLS_REQUIRED) {
|
||||
if (mSettings.getConnectionSecurity() == ConnectionSecurity.STARTTLS_OPTIONAL
|
||||
|| mSettings.getConnectionSecurity() == ConnectionSecurity.STARTTLS_REQUIRED) {
|
||||
|
||||
if (hasCapability("STARTTLS")) {
|
||||
// STARTTLS
|
||||
executeSimpleCommand("STARTTLS");
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
boolean secure = mSettings.getConnectionSecurity() == CONNECTION_SECURITY_TLS_REQUIRED;
|
||||
boolean secure = mSettings.getConnectionSecurity() == ConnectionSecurity.STARTTLS_REQUIRED;
|
||||
sslContext.init(null,
|
||||
new TrustManager[] { TrustManagerFactory.get(
|
||||
mSettings.getHost(),
|
||||
@ -2523,7 +2501,7 @@ public class ImapStore extends Store {
|
||||
if (responses.size() != 2) {
|
||||
throw new MessagingException("Invalid CAPABILITY response received");
|
||||
}
|
||||
} else if (mSettings.getConnectionSecurity() == CONNECTION_SECURITY_TLS_REQUIRED) {
|
||||
} else if (mSettings.getConnectionSecurity() == ConnectionSecurity.STARTTLS_REQUIRED) {
|
||||
throw new MessagingException("TLS not supported but required");
|
||||
}
|
||||
}
|
||||
|
@ -37,12 +37,6 @@ import java.util.Set;
|
||||
public class Pop3Store extends Store {
|
||||
public static final String STORE_TYPE = "POP3";
|
||||
|
||||
public static final int CONNECTION_SECURITY_NONE = 0;
|
||||
public static final int CONNECTION_SECURITY_TLS_OPTIONAL = 1;
|
||||
public static final int CONNECTION_SECURITY_TLS_REQUIRED = 2;
|
||||
public static final int CONNECTION_SECURITY_SSL_REQUIRED = 3;
|
||||
public static final int CONNECTION_SECURITY_SSL_OPTIONAL = 4;
|
||||
|
||||
private static final String STLS_COMMAND = "STLS";
|
||||
private static final String USER_COMMAND = "USER";
|
||||
private static final String PASS_COMMAND = "PASS";
|
||||
@ -200,7 +194,7 @@ public class Pop3Store extends Store {
|
||||
private String mUsername;
|
||||
private String mPassword;
|
||||
private AuthType mAuthType;
|
||||
private int mConnectionSecurity;
|
||||
private ConnectionSecurity mConnectionSecurity;
|
||||
private HashMap<String, Folder> mFolders = new HashMap<String, Folder>();
|
||||
private Pop3Capabilities mCapabilities;
|
||||
|
||||
@ -225,23 +219,7 @@ public class Pop3Store extends Store {
|
||||
mHost = settings.host;
|
||||
mPort = settings.port;
|
||||
|
||||
switch (settings.connectionSecurity) {
|
||||
case NONE:
|
||||
mConnectionSecurity = CONNECTION_SECURITY_NONE;
|
||||
break;
|
||||
case STARTTLS_OPTIONAL:
|
||||
mConnectionSecurity = CONNECTION_SECURITY_TLS_OPTIONAL;
|
||||
break;
|
||||
case STARTTLS_REQUIRED:
|
||||
mConnectionSecurity = CONNECTION_SECURITY_TLS_REQUIRED;
|
||||
break;
|
||||
case SSL_TLS_OPTIONAL:
|
||||
mConnectionSecurity = CONNECTION_SECURITY_SSL_OPTIONAL;
|
||||
break;
|
||||
case SSL_TLS_REQUIRED:
|
||||
mConnectionSecurity = CONNECTION_SECURITY_SSL_REQUIRED;
|
||||
break;
|
||||
}
|
||||
mConnectionSecurity = settings.connectionSecurity;
|
||||
|
||||
mUsername = settings.username;
|
||||
mPassword = settings.password;
|
||||
@ -321,10 +299,10 @@ public class Pop3Store extends Store {
|
||||
|
||||
try {
|
||||
SocketAddress socketAddress = new InetSocketAddress(mHost, mPort);
|
||||
if (mConnectionSecurity == CONNECTION_SECURITY_SSL_REQUIRED ||
|
||||
mConnectionSecurity == CONNECTION_SECURITY_SSL_OPTIONAL) {
|
||||
if (mConnectionSecurity == ConnectionSecurity.SSL_TLS_REQUIRED ||
|
||||
mConnectionSecurity == ConnectionSecurity.SSL_TLS_OPTIONAL) {
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
final boolean secure = mConnectionSecurity == CONNECTION_SECURITY_SSL_REQUIRED;
|
||||
final boolean secure = mConnectionSecurity == ConnectionSecurity.SSL_TLS_REQUIRED;
|
||||
sslContext.init(null,
|
||||
new TrustManager[] { TrustManagerFactory.get(mHost,
|
||||
mPort, secure) }, new SecureRandom());
|
||||
@ -345,14 +323,14 @@ public class Pop3Store extends Store {
|
||||
String serverGreeting = executeSimpleCommand(null);
|
||||
|
||||
mCapabilities = getCapabilities();
|
||||
if (mConnectionSecurity == CONNECTION_SECURITY_TLS_OPTIONAL
|
||||
|| mConnectionSecurity == CONNECTION_SECURITY_TLS_REQUIRED) {
|
||||
if (mConnectionSecurity == ConnectionSecurity.STARTTLS_OPTIONAL
|
||||
|| mConnectionSecurity == ConnectionSecurity.STARTTLS_REQUIRED) {
|
||||
|
||||
if (mCapabilities.stls) {
|
||||
executeSimpleCommand(STLS_COMMAND);
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
boolean secure = mConnectionSecurity == CONNECTION_SECURITY_TLS_REQUIRED;
|
||||
boolean secure = mConnectionSecurity == ConnectionSecurity.STARTTLS_REQUIRED;
|
||||
sslContext.init(null,
|
||||
new TrustManager[] { TrustManagerFactory.get(
|
||||
mHost, mPort, secure) },
|
||||
@ -366,7 +344,7 @@ public class Pop3Store extends Store {
|
||||
throw new MessagingException("Unable to connect socket");
|
||||
}
|
||||
mCapabilities = getCapabilities();
|
||||
} else if (mConnectionSecurity == CONNECTION_SECURITY_TLS_REQUIRED) {
|
||||
} else if (mConnectionSecurity == ConnectionSecurity.STARTTLS_REQUIRED) {
|
||||
throw new MessagingException("TLS not supported but required");
|
||||
}
|
||||
}
|
||||
|
@ -57,13 +57,6 @@ import java.util.zip.GZIPInputStream;
|
||||
public class WebDavStore extends Store {
|
||||
public static final String STORE_TYPE = "WebDAV";
|
||||
|
||||
// Security options
|
||||
private static final short CONNECTION_SECURITY_NONE = 0;
|
||||
private static final short CONNECTION_SECURITY_TLS_OPTIONAL = 1;
|
||||
private static final short CONNECTION_SECURITY_TLS_REQUIRED = 2;
|
||||
private static final short CONNECTION_SECURITY_SSL_OPTIONAL = 3;
|
||||
private static final short CONNECTION_SECURITY_SSL_REQUIRED = 4;
|
||||
|
||||
// Authentication types
|
||||
private static final short AUTH_TYPE_NONE = 0;
|
||||
private static final short AUTH_TYPE_BASIC = 1;
|
||||
@ -298,7 +291,7 @@ public class WebDavStore extends Store {
|
||||
}
|
||||
|
||||
|
||||
private short mConnectionSecurity;
|
||||
private ConnectionSecurity mConnectionSecurity;
|
||||
private String mUsername; /* Stores the username for authentications */
|
||||
private String mAlias; /* Stores the alias for the user's mailbox */
|
||||
private String mPassword; /* Stores the password for authentications */
|
||||
@ -334,23 +327,7 @@ public class WebDavStore extends Store {
|
||||
mHost = settings.host;
|
||||
mPort = settings.port;
|
||||
|
||||
switch (settings.connectionSecurity) {
|
||||
case NONE:
|
||||
mConnectionSecurity = CONNECTION_SECURITY_NONE;
|
||||
break;
|
||||
case STARTTLS_OPTIONAL:
|
||||
mConnectionSecurity = CONNECTION_SECURITY_TLS_OPTIONAL;
|
||||
break;
|
||||
case STARTTLS_REQUIRED:
|
||||
mConnectionSecurity = CONNECTION_SECURITY_TLS_REQUIRED;
|
||||
break;
|
||||
case SSL_TLS_OPTIONAL:
|
||||
mConnectionSecurity = CONNECTION_SECURITY_SSL_OPTIONAL;
|
||||
break;
|
||||
case SSL_TLS_REQUIRED:
|
||||
mConnectionSecurity = CONNECTION_SECURITY_SSL_REQUIRED;
|
||||
break;
|
||||
}
|
||||
mConnectionSecurity = settings.connectionSecurity;
|
||||
|
||||
mUsername = settings.username;
|
||||
mPassword = settings.password;
|
||||
@ -383,16 +360,16 @@ public class WebDavStore extends Store {
|
||||
// The inbox path would look like: "https://mail.domain.com/Exchange/alias/Inbox".
|
||||
mUrl = getRoot() + mPath + mMailboxPath;
|
||||
|
||||
mSecure = mConnectionSecurity == CONNECTION_SECURITY_SSL_REQUIRED;
|
||||
mSecure = mConnectionSecurity == ConnectionSecurity.SSL_TLS_REQUIRED;
|
||||
mAuthString = "Basic " + Utility.base64Encode(mUsername + ":" + mPassword);
|
||||
}
|
||||
|
||||
private String getRoot() {
|
||||
String root;
|
||||
if (mConnectionSecurity == CONNECTION_SECURITY_TLS_REQUIRED ||
|
||||
mConnectionSecurity == CONNECTION_SECURITY_SSL_REQUIRED ||
|
||||
mConnectionSecurity == CONNECTION_SECURITY_TLS_OPTIONAL ||
|
||||
mConnectionSecurity == CONNECTION_SECURITY_SSL_OPTIONAL) {
|
||||
if (mConnectionSecurity == ConnectionSecurity.STARTTLS_REQUIRED ||
|
||||
mConnectionSecurity == ConnectionSecurity.SSL_TLS_REQUIRED ||
|
||||
mConnectionSecurity == ConnectionSecurity.STARTTLS_OPTIONAL ||
|
||||
mConnectionSecurity == ConnectionSecurity.SSL_TLS_OPTIONAL) {
|
||||
root = "https";
|
||||
} else {
|
||||
root = "http";
|
||||
|
@ -33,12 +33,6 @@ import java.util.*;
|
||||
public class SmtpTransport extends Transport {
|
||||
public static final String TRANSPORT_TYPE = "SMTP";
|
||||
|
||||
public static final int CONNECTION_SECURITY_NONE = 0;
|
||||
public static final int CONNECTION_SECURITY_TLS_OPTIONAL = 1;
|
||||
public static final int CONNECTION_SECURITY_TLS_REQUIRED = 2;
|
||||
public static final int CONNECTION_SECURITY_SSL_REQUIRED = 3;
|
||||
public static final int CONNECTION_SECURITY_SSL_OPTIONAL = 4;
|
||||
|
||||
/**
|
||||
* Decodes a SmtpTransport URI.
|
||||
*
|
||||
@ -175,7 +169,7 @@ public class SmtpTransport extends Transport {
|
||||
String mUsername;
|
||||
String mPassword;
|
||||
AuthType mAuthType;
|
||||
int mConnectionSecurity;
|
||||
ConnectionSecurity mConnectionSecurity;
|
||||
Socket mSocket;
|
||||
PeekableInputStream mIn;
|
||||
OutputStream mOut;
|
||||
@ -193,23 +187,7 @@ public class SmtpTransport extends Transport {
|
||||
mHost = settings.host;
|
||||
mPort = settings.port;
|
||||
|
||||
switch (settings.connectionSecurity) {
|
||||
case NONE:
|
||||
mConnectionSecurity = CONNECTION_SECURITY_NONE;
|
||||
break;
|
||||
case STARTTLS_OPTIONAL:
|
||||
mConnectionSecurity = CONNECTION_SECURITY_TLS_OPTIONAL;
|
||||
break;
|
||||
case STARTTLS_REQUIRED:
|
||||
mConnectionSecurity = CONNECTION_SECURITY_TLS_REQUIRED;
|
||||
break;
|
||||
case SSL_TLS_OPTIONAL:
|
||||
mConnectionSecurity = CONNECTION_SECURITY_SSL_OPTIONAL;
|
||||
break;
|
||||
case SSL_TLS_REQUIRED:
|
||||
mConnectionSecurity = CONNECTION_SECURITY_SSL_REQUIRED;
|
||||
break;
|
||||
}
|
||||
mConnectionSecurity = settings.connectionSecurity;
|
||||
|
||||
mAuthType = settings.authenticationType;
|
||||
mUsername = settings.username;
|
||||
@ -223,10 +201,10 @@ public class SmtpTransport extends Transport {
|
||||
for (int i = 0; i < addresses.length; i++) {
|
||||
try {
|
||||
SocketAddress socketAddress = new InetSocketAddress(addresses[i], mPort);
|
||||
if (mConnectionSecurity == CONNECTION_SECURITY_SSL_REQUIRED ||
|
||||
mConnectionSecurity == CONNECTION_SECURITY_SSL_OPTIONAL) {
|
||||
if (mConnectionSecurity == ConnectionSecurity.SSL_TLS_REQUIRED ||
|
||||
mConnectionSecurity == ConnectionSecurity.SSL_TLS_OPTIONAL) {
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
boolean secure = mConnectionSecurity == CONNECTION_SECURITY_SSL_REQUIRED;
|
||||
boolean secure = mConnectionSecurity == ConnectionSecurity.SSL_TLS_REQUIRED;
|
||||
sslContext.init(null,
|
||||
new TrustManager[] { TrustManagerFactory.get(
|
||||
mHost, mPort, secure) },
|
||||
@ -280,13 +258,13 @@ public class SmtpTransport extends Transport {
|
||||
m8bitEncodingAllowed = extensions.containsKey("8BITMIME");
|
||||
|
||||
|
||||
if (mConnectionSecurity == CONNECTION_SECURITY_TLS_OPTIONAL
|
||||
|| mConnectionSecurity == CONNECTION_SECURITY_TLS_REQUIRED) {
|
||||
if (mConnectionSecurity == ConnectionSecurity.STARTTLS_OPTIONAL
|
||||
|| mConnectionSecurity == ConnectionSecurity.STARTTLS_REQUIRED) {
|
||||
if (extensions.containsKey("STARTTLS")) {
|
||||
executeSimpleCommand("STARTTLS");
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
boolean secure = mConnectionSecurity == CONNECTION_SECURITY_TLS_REQUIRED;
|
||||
boolean secure = mConnectionSecurity == ConnectionSecurity.STARTTLS_REQUIRED;
|
||||
sslContext.init(null,
|
||||
new TrustManager[] { TrustManagerFactory.get(mHost,
|
||||
mPort, secure) }, new SecureRandom());
|
||||
@ -300,7 +278,7 @@ public class SmtpTransport extends Transport {
|
||||
* Exim.
|
||||
*/
|
||||
extensions = sendHello(localHost);
|
||||
} else if (mConnectionSecurity == CONNECTION_SECURITY_TLS_REQUIRED) {
|
||||
} else if (mConnectionSecurity == ConnectionSecurity.STARTTLS_REQUIRED) {
|
||||
throw new MessagingException("TLS not supported but required");
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.fsck.k9.mail.transport.imap;
|
||||
|
||||
import com.fsck.k9.mail.AuthType;
|
||||
import com.fsck.k9.mail.ConnectionSecurity;
|
||||
import com.fsck.k9.mail.store.ImapStore;
|
||||
import com.fsck.k9.mail.store.ImapStore.ImapConnection;
|
||||
|
||||
@ -12,7 +13,7 @@ public interface ImapSettings {
|
||||
|
||||
int getPort();
|
||||
|
||||
int getConnectionSecurity();
|
||||
ConnectionSecurity getConnectionSecurity();
|
||||
|
||||
AuthType getAuthType();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user