mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-23 09:52:16 -05:00
Move default port and default TLS port to a single location
This commit is contained in:
parent
147db8cc5e
commit
810d0cf6b4
@ -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 + ")");
|
||||||
}
|
}
|
||||||
|
@ -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,25 +473,20 @@ 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(getDefaultPort(securityType)));
|
||||||
mPortView.addTextChangedListener(validationTextWatcher);
|
mPortView.addTextChangedListener(validationTextWatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getDefaultPort(ConnectionSecurity securityType) {
|
private int getDefaultPort(ConnectionSecurity securityType) {
|
||||||
String port;
|
|
||||||
switch (securityType) {
|
switch (securityType) {
|
||||||
case NONE:
|
case NONE:
|
||||||
case STARTTLS_REQUIRED:
|
case STARTTLS_REQUIRED:
|
||||||
port = mDefaultPort;
|
return mStoreType.defaultPort;
|
||||||
break;
|
|
||||||
case SSL_TLS_REQUIRED:
|
case SSL_TLS_REQUIRED:
|
||||||
port = mDefaultSslPort;
|
return mStoreType.defaultTlsPort;
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
Log.e(K9.LOG_TAG, "Unhandled ConnectionSecurity type encountered");
|
throw new AssertionError("Unhandled ConnectionSecurity type encountered: " + securityType);
|
||||||
port = "";
|
|
||||||
}
|
}
|
||||||
return port;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateAuthPlainTextFromSecurityType(ConnectionSecurity securityType) {
|
private void updateAuthPlainTextFromSecurityType(ConnectionSecurity securityType) {
|
||||||
|
@ -38,9 +38,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,25 +424,20 @@ 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(getDefaultSmtpPort(securityType)));
|
||||||
mPortView.addTextChangedListener(validationTextWatcher);
|
mPortView.addTextChangedListener(validationTextWatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getDefaultSmtpPort(ConnectionSecurity securityType) {
|
private int getDefaultSmtpPort(ConnectionSecurity securityType) {
|
||||||
String port;
|
|
||||||
switch (securityType) {
|
switch (securityType) {
|
||||||
case NONE:
|
case NONE:
|
||||||
case STARTTLS_REQUIRED:
|
case STARTTLS_REQUIRED:
|
||||||
port = SMTP_PORT;
|
return Type.SMTP.defaultPort;
|
||||||
break;
|
|
||||||
case SSL_TLS_REQUIRED:
|
case SSL_TLS_REQUIRED:
|
||||||
port = SMTP_SSL_PORT;
|
return Type.SMTP.defaultTlsPort;
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
port = "";
|
throw new AssertionError("Unhandled ConnectionSecurity type encountered: " + securityType);
|
||||||
Log.e(K9.LOG_TAG, "Unhandled ConnectionSecurity type encountered");
|
|
||||||
}
|
}
|
||||||
return port;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateAuthPlainTextFromSecurityType(ConnectionSecurity securityType) {
|
private void updateAuthPlainTextFromSecurityType(ConnectionSecurity securityType) {
|
||||||
|
Loading…
Reference in New Issue
Block a user