mirror of
https://github.com/moparisthebest/k-9
synced 2024-12-26 01:28:50 -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 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).
|
||||
|
@ -54,6 +54,7 @@ import com.fsck.k9.mail.Part;
|
||||
import com.fsck.k9.mail.PushReceiver;
|
||||
import com.fsck.k9.mail.Pusher;
|
||||
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.FixedLengthInputStream;
|
||||
import com.fsck.k9.mail.internet.MimeBodyPart;
|
||||
@ -145,13 +146,13 @@ public class ImapStore extends RemoteStore {
|
||||
*/
|
||||
if (scheme.equals("imap")) {
|
||||
connectionSecurity = ConnectionSecurity.NONE;
|
||||
port = 143;
|
||||
port = Type.IMAP.defaultPort;
|
||||
} else if (scheme.startsWith("imap+tls")) {
|
||||
connectionSecurity = ConnectionSecurity.STARTTLS_REQUIRED;
|
||||
port = 143;
|
||||
port = Type.IMAP.defaultPort;
|
||||
} else if (scheme.startsWith("imap+ssl")) {
|
||||
connectionSecurity = ConnectionSecurity.SSL_TLS_REQUIRED;
|
||||
port = 993;
|
||||
port = Type.IMAP.defaultTlsPort;
|
||||
} else {
|
||||
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.CertificateValidationException;
|
||||
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.store.RemoteStore;
|
||||
import com.fsck.k9.mail.store.StoreConfig;
|
||||
@ -100,13 +101,13 @@ public class Pop3Store extends RemoteStore {
|
||||
*/
|
||||
if (scheme.equals("pop3")) {
|
||||
connectionSecurity = ConnectionSecurity.NONE;
|
||||
port = 110;
|
||||
port = Type.POP3.defaultPort;
|
||||
} else if (scheme.startsWith("pop3+tls")) {
|
||||
connectionSecurity = ConnectionSecurity.STARTTLS_REQUIRED;
|
||||
port = 110;
|
||||
port = Type.POP3.defaultPort;
|
||||
} else if (scheme.startsWith("pop3+ssl")) {
|
||||
connectionSecurity = ConnectionSecurity.SSL_TLS_REQUIRED;
|
||||
port = 995;
|
||||
port = Type.POP3.defaultTlsPort;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unsupported protocol (" + scheme + ")");
|
||||
}
|
||||
|
@ -75,13 +75,13 @@ public class SmtpTransport extends Transport {
|
||||
*/
|
||||
if (scheme.equals("smtp")) {
|
||||
connectionSecurity = ConnectionSecurity.NONE;
|
||||
port = 587;
|
||||
port = ServerSettings.Type.SMTP.defaultPort;
|
||||
} else if (scheme.startsWith("smtp+tls")) {
|
||||
connectionSecurity = ConnectionSecurity.STARTTLS_REQUIRED;
|
||||
port = 587;
|
||||
port = ServerSettings.Type.SMTP.defaultPort;
|
||||
} else if (scheme.startsWith("smtp+ssl")) {
|
||||
connectionSecurity = ConnectionSecurity.SSL_TLS_REQUIRED;
|
||||
port = 465;
|
||||
port = ServerSettings.Type.SMTP.defaultTlsPort;
|
||||
} else {
|
||||
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_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 EditText mUsernameView;
|
||||
private EditText mPasswordView;
|
||||
@ -79,8 +72,6 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
||||
private CheckBox mCompressionOther;
|
||||
private CheckBox mSubscribedFoldersOnly;
|
||||
private AuthTypeAdapter mAuthTypeAdapter;
|
||||
private String mDefaultPort = "";
|
||||
private String mDefaultSslPort = "";
|
||||
private ConnectionSecurity[] mConnectionSecurityChoices = ConnectionSecurity.values();
|
||||
|
||||
public static void actionIncomingSettings(Activity context, Account account, boolean makeDefault) {
|
||||
@ -189,8 +180,6 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
||||
mStoreType = settings.type;
|
||||
if (Type.POP3 == settings.type) {
|
||||
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.webdav_advanced_header).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);
|
||||
} else if (Type.IMAP == settings.type) {
|
||||
serverLabelView.setText(R.string.account_setup_incoming_imap_server_label);
|
||||
mDefaultPort = IMAP_PORT;
|
||||
mDefaultSslPort = IMAP_SSL_PORT;
|
||||
|
||||
ImapStoreSettings imapSettings = (ImapStoreSettings) settings;
|
||||
|
||||
@ -221,8 +208,6 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
||||
}
|
||||
} else if (Type.WebDAV == settings.type) {
|
||||
serverLabelView.setText(R.string.account_setup_incoming_webdav_server_label);
|
||||
mDefaultPort = WEBDAV_PORT;
|
||||
mDefaultSslPort = WEBDAV_SSL_PORT;
|
||||
mConnectionSecurityChoices = new ConnectionSecurity[] {
|
||||
ConnectionSecurity.NONE,
|
||||
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
|
||||
// elsewhere as a result of user interaction.
|
||||
mPortView.removeTextChangedListener(validationTextWatcher);
|
||||
mPortView.setText(getDefaultPort(securityType));
|
||||
mPortView.setText(String.valueOf(getDefaultPort(securityType)));
|
||||
mPortView.addTextChangedListener(validationTextWatcher);
|
||||
}
|
||||
|
||||
private String getDefaultPort(ConnectionSecurity securityType) {
|
||||
String port;
|
||||
private int getDefaultPort(ConnectionSecurity securityType) {
|
||||
switch (securityType) {
|
||||
case NONE:
|
||||
case STARTTLS_REQUIRED:
|
||||
port = mDefaultPort;
|
||||
break;
|
||||
return mStoreType.defaultPort;
|
||||
case SSL_TLS_REQUIRED:
|
||||
port = mDefaultSslPort;
|
||||
break;
|
||||
return mStoreType.defaultTlsPort;
|
||||
default:
|
||||
Log.e(K9.LOG_TAG, "Unhandled ConnectionSecurity type encountered");
|
||||
port = "";
|
||||
throw new AssertionError("Unhandled ConnectionSecurity type encountered: " + securityType);
|
||||
}
|
||||
return port;
|
||||
}
|
||||
|
||||
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_AUTH_TYPE_POSITION = "authTypePosition";
|
||||
|
||||
private static final String SMTP_PORT = "587";
|
||||
private static final String SMTP_SSL_PORT = "465";
|
||||
|
||||
private EditText mUsernameView;
|
||||
private EditText mPasswordView;
|
||||
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
|
||||
// elsewhere as a result of user interaction.
|
||||
mPortView.removeTextChangedListener(validationTextWatcher);
|
||||
mPortView.setText(getDefaultSmtpPort(securityType));
|
||||
mPortView.setText(String.valueOf(getDefaultSmtpPort(securityType)));
|
||||
mPortView.addTextChangedListener(validationTextWatcher);
|
||||
}
|
||||
|
||||
private String getDefaultSmtpPort(ConnectionSecurity securityType) {
|
||||
String port;
|
||||
private int getDefaultSmtpPort(ConnectionSecurity securityType) {
|
||||
switch (securityType) {
|
||||
case NONE:
|
||||
case STARTTLS_REQUIRED:
|
||||
port = SMTP_PORT;
|
||||
break;
|
||||
return Type.SMTP.defaultPort;
|
||||
case SSL_TLS_REQUIRED:
|
||||
port = SMTP_SSL_PORT;
|
||||
break;
|
||||
return Type.SMTP.defaultTlsPort;
|
||||
default:
|
||||
port = "";
|
||||
Log.e(K9.LOG_TAG, "Unhandled ConnectionSecurity type encountered");
|
||||
throw new AssertionError("Unhandled ConnectionSecurity type encountered: " + securityType);
|
||||
}
|
||||
return port;
|
||||
}
|
||||
|
||||
private void updateAuthPlainTextFromSecurityType(ConnectionSecurity securityType) {
|
||||
|
Loading…
Reference in New Issue
Block a user