mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-23 18:02:15 -05:00
commit
f733cc38ba
@ -17,7 +17,30 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public class ServerSettings {
|
public class ServerSettings {
|
||||||
|
|
||||||
public enum Type { IMAP, SMTP, WebDAV, POP3 }
|
public enum Type {
|
||||||
|
|
||||||
|
IMAP(143, 993),
|
||||||
|
SMTP(587, 465),
|
||||||
|
WebDAV(80, 443),
|
||||||
|
POP3(110, 995);
|
||||||
|
|
||||||
|
public final int defaultPort;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Note: port for connections using TLS (=SSL) immediately
|
||||||
|
* from the initial TCP connection.
|
||||||
|
*
|
||||||
|
* STARTTLS uses the defaultPort, then upgrades.
|
||||||
|
*
|
||||||
|
* See https://www.fastmail.com/help/technical/ssltlsstarttls.html.
|
||||||
|
*/
|
||||||
|
public final int defaultTlsPort;
|
||||||
|
|
||||||
|
private Type(int defaultPort, int defaultTlsPort) {
|
||||||
|
this.defaultPort = defaultPort;
|
||||||
|
this.defaultTlsPort = defaultTlsPort;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name of the store or transport type (e.g. IMAP).
|
* Name of the store or transport type (e.g. IMAP).
|
||||||
|
@ -54,6 +54,7 @@ import com.fsck.k9.mail.Part;
|
|||||||
import com.fsck.k9.mail.PushReceiver;
|
import com.fsck.k9.mail.PushReceiver;
|
||||||
import com.fsck.k9.mail.Pusher;
|
import com.fsck.k9.mail.Pusher;
|
||||||
import com.fsck.k9.mail.ServerSettings;
|
import com.fsck.k9.mail.ServerSettings;
|
||||||
|
import com.fsck.k9.mail.ServerSettings.Type;
|
||||||
import com.fsck.k9.mail.filter.EOLConvertingOutputStream;
|
import com.fsck.k9.mail.filter.EOLConvertingOutputStream;
|
||||||
import com.fsck.k9.mail.filter.FixedLengthInputStream;
|
import com.fsck.k9.mail.filter.FixedLengthInputStream;
|
||||||
import com.fsck.k9.mail.internet.MimeBodyPart;
|
import com.fsck.k9.mail.internet.MimeBodyPart;
|
||||||
@ -145,13 +146,13 @@ public class ImapStore extends RemoteStore {
|
|||||||
*/
|
*/
|
||||||
if (scheme.equals("imap")) {
|
if (scheme.equals("imap")) {
|
||||||
connectionSecurity = ConnectionSecurity.NONE;
|
connectionSecurity = ConnectionSecurity.NONE;
|
||||||
port = 143;
|
port = Type.IMAP.defaultPort;
|
||||||
} else if (scheme.startsWith("imap+tls")) {
|
} else if (scheme.startsWith("imap+tls")) {
|
||||||
connectionSecurity = ConnectionSecurity.STARTTLS_REQUIRED;
|
connectionSecurity = ConnectionSecurity.STARTTLS_REQUIRED;
|
||||||
port = 143;
|
port = Type.IMAP.defaultPort;
|
||||||
} else if (scheme.startsWith("imap+ssl")) {
|
} else if (scheme.startsWith("imap+ssl")) {
|
||||||
connectionSecurity = ConnectionSecurity.SSL_TLS_REQUIRED;
|
connectionSecurity = ConnectionSecurity.SSL_TLS_REQUIRED;
|
||||||
port = 993;
|
port = Type.IMAP.defaultTlsPort;
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Unsupported protocol (" + scheme + ")");
|
throw new IllegalArgumentException("Unsupported protocol (" + scheme + ")");
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import com.fsck.k9.mail.filter.Hex;
|
|||||||
import com.fsck.k9.mail.internet.MimeMessage;
|
import com.fsck.k9.mail.internet.MimeMessage;
|
||||||
import com.fsck.k9.mail.CertificateValidationException;
|
import com.fsck.k9.mail.CertificateValidationException;
|
||||||
import com.fsck.k9.mail.MessageRetrievalListener;
|
import com.fsck.k9.mail.MessageRetrievalListener;
|
||||||
|
import com.fsck.k9.mail.ServerSettings.Type;
|
||||||
import com.fsck.k9.mail.ssl.TrustedSocketFactory;
|
import com.fsck.k9.mail.ssl.TrustedSocketFactory;
|
||||||
import com.fsck.k9.mail.store.RemoteStore;
|
import com.fsck.k9.mail.store.RemoteStore;
|
||||||
import com.fsck.k9.mail.store.StoreConfig;
|
import com.fsck.k9.mail.store.StoreConfig;
|
||||||
@ -100,13 +101,13 @@ public class Pop3Store extends RemoteStore {
|
|||||||
*/
|
*/
|
||||||
if (scheme.equals("pop3")) {
|
if (scheme.equals("pop3")) {
|
||||||
connectionSecurity = ConnectionSecurity.NONE;
|
connectionSecurity = ConnectionSecurity.NONE;
|
||||||
port = 110;
|
port = Type.POP3.defaultPort;
|
||||||
} else if (scheme.startsWith("pop3+tls")) {
|
} else if (scheme.startsWith("pop3+tls")) {
|
||||||
connectionSecurity = ConnectionSecurity.STARTTLS_REQUIRED;
|
connectionSecurity = ConnectionSecurity.STARTTLS_REQUIRED;
|
||||||
port = 110;
|
port = Type.POP3.defaultPort;
|
||||||
} else if (scheme.startsWith("pop3+ssl")) {
|
} else if (scheme.startsWith("pop3+ssl")) {
|
||||||
connectionSecurity = ConnectionSecurity.SSL_TLS_REQUIRED;
|
connectionSecurity = ConnectionSecurity.SSL_TLS_REQUIRED;
|
||||||
port = 995;
|
port = Type.POP3.defaultTlsPort;
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Unsupported protocol (" + scheme + ")");
|
throw new IllegalArgumentException("Unsupported protocol (" + scheme + ")");
|
||||||
}
|
}
|
||||||
|
@ -75,13 +75,13 @@ public class SmtpTransport extends Transport {
|
|||||||
*/
|
*/
|
||||||
if (scheme.equals("smtp")) {
|
if (scheme.equals("smtp")) {
|
||||||
connectionSecurity = ConnectionSecurity.NONE;
|
connectionSecurity = ConnectionSecurity.NONE;
|
||||||
port = 587;
|
port = ServerSettings.Type.SMTP.defaultPort;
|
||||||
} else if (scheme.startsWith("smtp+tls")) {
|
} else if (scheme.startsWith("smtp+tls")) {
|
||||||
connectionSecurity = ConnectionSecurity.STARTTLS_REQUIRED;
|
connectionSecurity = ConnectionSecurity.STARTTLS_REQUIRED;
|
||||||
port = 587;
|
port = ServerSettings.Type.SMTP.defaultPort;
|
||||||
} else if (scheme.startsWith("smtp+ssl")) {
|
} else if (scheme.startsWith("smtp+ssl")) {
|
||||||
connectionSecurity = ConnectionSecurity.SSL_TLS_REQUIRED;
|
connectionSecurity = ConnectionSecurity.SSL_TLS_REQUIRED;
|
||||||
port = 465;
|
port = ServerSettings.Type.SMTP.defaultTlsPort;
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Unsupported protocol (" + scheme + ")");
|
throw new IllegalArgumentException("Unsupported protocol (" + scheme + ")");
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
package com.fsck.k9.account;
|
package com.fsck.k9.account;
|
||||||
|
|
||||||
|
|
||||||
import com.fsck.k9.Account.DeletePolicy;
|
import com.fsck.k9.Account.DeletePolicy;
|
||||||
|
import com.fsck.k9.mail.ConnectionSecurity;
|
||||||
import com.fsck.k9.mail.ServerSettings.Type;
|
import com.fsck.k9.mail.ServerSettings.Type;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deals with logic surrounding account creation.
|
* Deals with logic surrounding account creation.
|
||||||
* <p/>
|
* <p/>
|
||||||
@ -25,4 +28,17 @@ public class AccountCreator {
|
|||||||
return defaults.get(type);
|
return defaults.get(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getDefaultPort(ConnectionSecurity securityType, Type storeType) {
|
||||||
|
switch (securityType) {
|
||||||
|
case NONE:
|
||||||
|
case STARTTLS_REQUIRED: {
|
||||||
|
return storeType.defaultPort;
|
||||||
|
}
|
||||||
|
case SSL_TLS_REQUIRED: {
|
||||||
|
return storeType.defaultTlsPort;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new AssertionError("Unhandled ConnectionSecurity type encountered: " + securityType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,13 +46,6 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||||||
private static final String STATE_SECURITY_TYPE_POSITION = "stateSecurityTypePosition";
|
private static final String STATE_SECURITY_TYPE_POSITION = "stateSecurityTypePosition";
|
||||||
private static final String STATE_AUTH_TYPE_POSITION = "authTypePosition";
|
private static final String STATE_AUTH_TYPE_POSITION = "authTypePosition";
|
||||||
|
|
||||||
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 Type mStoreType;
|
private Type mStoreType;
|
||||||
private EditText mUsernameView;
|
private EditText mUsernameView;
|
||||||
private EditText mPasswordView;
|
private EditText mPasswordView;
|
||||||
@ -79,8 +72,6 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||||||
private CheckBox mCompressionOther;
|
private CheckBox mCompressionOther;
|
||||||
private CheckBox mSubscribedFoldersOnly;
|
private CheckBox mSubscribedFoldersOnly;
|
||||||
private AuthTypeAdapter mAuthTypeAdapter;
|
private AuthTypeAdapter mAuthTypeAdapter;
|
||||||
private String mDefaultPort = "";
|
|
||||||
private String mDefaultSslPort = "";
|
|
||||||
private ConnectionSecurity[] mConnectionSecurityChoices = ConnectionSecurity.values();
|
private ConnectionSecurity[] mConnectionSecurityChoices = ConnectionSecurity.values();
|
||||||
|
|
||||||
public static void actionIncomingSettings(Activity context, Account account, boolean makeDefault) {
|
public static void actionIncomingSettings(Activity context, Account account, boolean makeDefault) {
|
||||||
@ -189,8 +180,6 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||||||
mStoreType = settings.type;
|
mStoreType = settings.type;
|
||||||
if (Type.POP3 == settings.type) {
|
if (Type.POP3 == settings.type) {
|
||||||
serverLabelView.setText(R.string.account_setup_incoming_pop_server_label);
|
serverLabelView.setText(R.string.account_setup_incoming_pop_server_label);
|
||||||
mDefaultPort = POP3_PORT;
|
|
||||||
mDefaultSslPort = POP3_SSL_PORT;
|
|
||||||
findViewById(R.id.imap_path_prefix_section).setVisibility(View.GONE);
|
findViewById(R.id.imap_path_prefix_section).setVisibility(View.GONE);
|
||||||
findViewById(R.id.webdav_advanced_header).setVisibility(View.GONE);
|
findViewById(R.id.webdav_advanced_header).setVisibility(View.GONE);
|
||||||
findViewById(R.id.webdav_mailbox_alias_section).setVisibility(View.GONE);
|
findViewById(R.id.webdav_mailbox_alias_section).setVisibility(View.GONE);
|
||||||
@ -201,8 +190,6 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||||||
mSubscribedFoldersOnly.setVisibility(View.GONE);
|
mSubscribedFoldersOnly.setVisibility(View.GONE);
|
||||||
} else if (Type.IMAP == settings.type) {
|
} else if (Type.IMAP == settings.type) {
|
||||||
serverLabelView.setText(R.string.account_setup_incoming_imap_server_label);
|
serverLabelView.setText(R.string.account_setup_incoming_imap_server_label);
|
||||||
mDefaultPort = IMAP_PORT;
|
|
||||||
mDefaultSslPort = IMAP_SSL_PORT;
|
|
||||||
|
|
||||||
ImapStoreSettings imapSettings = (ImapStoreSettings) settings;
|
ImapStoreSettings imapSettings = (ImapStoreSettings) settings;
|
||||||
|
|
||||||
@ -221,8 +208,6 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||||||
}
|
}
|
||||||
} else if (Type.WebDAV == settings.type) {
|
} else if (Type.WebDAV == settings.type) {
|
||||||
serverLabelView.setText(R.string.account_setup_incoming_webdav_server_label);
|
serverLabelView.setText(R.string.account_setup_incoming_webdav_server_label);
|
||||||
mDefaultPort = WEBDAV_PORT;
|
|
||||||
mDefaultSslPort = WEBDAV_SSL_PORT;
|
|
||||||
mConnectionSecurityChoices = new ConnectionSecurity[] {
|
mConnectionSecurityChoices = new ConnectionSecurity[] {
|
||||||
ConnectionSecurity.NONE,
|
ConnectionSecurity.NONE,
|
||||||
ConnectionSecurity.SSL_TLS_REQUIRED };
|
ConnectionSecurity.SSL_TLS_REQUIRED };
|
||||||
@ -488,27 +473,10 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||||||
// Remove listener so as not to trigger validateFields() which is called
|
// Remove listener so as not to trigger validateFields() which is called
|
||||||
// elsewhere as a result of user interaction.
|
// elsewhere as a result of user interaction.
|
||||||
mPortView.removeTextChangedListener(validationTextWatcher);
|
mPortView.removeTextChangedListener(validationTextWatcher);
|
||||||
mPortView.setText(getDefaultPort(securityType));
|
mPortView.setText(String.valueOf(AccountCreator.getDefaultPort(securityType, mStoreType)));
|
||||||
mPortView.addTextChangedListener(validationTextWatcher);
|
mPortView.addTextChangedListener(validationTextWatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getDefaultPort(ConnectionSecurity securityType) {
|
|
||||||
String port;
|
|
||||||
switch (securityType) {
|
|
||||||
case NONE:
|
|
||||||
case STARTTLS_REQUIRED:
|
|
||||||
port = mDefaultPort;
|
|
||||||
break;
|
|
||||||
case SSL_TLS_REQUIRED:
|
|
||||||
port = mDefaultSslPort;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
Log.e(K9.LOG_TAG, "Unhandled ConnectionSecurity type encountered");
|
|
||||||
port = "";
|
|
||||||
}
|
|
||||||
return port;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateAuthPlainTextFromSecurityType(ConnectionSecurity securityType) {
|
private void updateAuthPlainTextFromSecurityType(ConnectionSecurity securityType) {
|
||||||
mAuthTypeAdapter.useInsecureText(securityType == ConnectionSecurity.NONE);
|
mAuthTypeAdapter.useInsecureText(securityType == ConnectionSecurity.NONE);
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ import android.widget.AdapterView.OnItemSelectedListener;
|
|||||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||||
|
|
||||||
import com.fsck.k9.*;
|
import com.fsck.k9.*;
|
||||||
|
import com.fsck.k9.account.AccountCreator;
|
||||||
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;
|
||||||
@ -38,9 +39,6 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
|
|||||||
private static final String STATE_SECURITY_TYPE_POSITION = "stateSecurityTypePosition";
|
private static final String STATE_SECURITY_TYPE_POSITION = "stateSecurityTypePosition";
|
||||||
private static final String STATE_AUTH_TYPE_POSITION = "authTypePosition";
|
private static final String STATE_AUTH_TYPE_POSITION = "authTypePosition";
|
||||||
|
|
||||||
private static final String SMTP_PORT = "587";
|
|
||||||
private static final String SMTP_SSL_PORT = "465";
|
|
||||||
|
|
||||||
private EditText mUsernameView;
|
private EditText mUsernameView;
|
||||||
private EditText mPasswordView;
|
private EditText mPasswordView;
|
||||||
private ClientCertificateSpinner mClientCertificateSpinner;
|
private ClientCertificateSpinner mClientCertificateSpinner;
|
||||||
@ -427,27 +425,10 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
|
|||||||
// Remove listener so as not to trigger validateFields() which is called
|
// Remove listener so as not to trigger validateFields() which is called
|
||||||
// elsewhere as a result of user interaction.
|
// elsewhere as a result of user interaction.
|
||||||
mPortView.removeTextChangedListener(validationTextWatcher);
|
mPortView.removeTextChangedListener(validationTextWatcher);
|
||||||
mPortView.setText(getDefaultSmtpPort(securityType));
|
mPortView.setText(String.valueOf(AccountCreator.getDefaultPort(securityType, Type.SMTP)));
|
||||||
mPortView.addTextChangedListener(validationTextWatcher);
|
mPortView.addTextChangedListener(validationTextWatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getDefaultSmtpPort(ConnectionSecurity securityType) {
|
|
||||||
String port;
|
|
||||||
switch (securityType) {
|
|
||||||
case NONE:
|
|
||||||
case STARTTLS_REQUIRED:
|
|
||||||
port = SMTP_PORT;
|
|
||||||
break;
|
|
||||||
case SSL_TLS_REQUIRED:
|
|
||||||
port = SMTP_SSL_PORT;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
port = "";
|
|
||||||
Log.e(K9.LOG_TAG, "Unhandled ConnectionSecurity type encountered");
|
|
||||||
}
|
|
||||||
return port;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateAuthPlainTextFromSecurityType(ConnectionSecurity securityType) {
|
private void updateAuthPlainTextFromSecurityType(ConnectionSecurity securityType) {
|
||||||
mAuthTypeAdapter.useInsecureText(securityType == ConnectionSecurity.NONE);
|
mAuthTypeAdapter.useInsecureText(securityType == ConnectionSecurity.NONE);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user