diff --git a/k9mail-library/src/main/java/com/fsck/k9/mail/ServerSettings.java b/k9mail-library/src/main/java/com/fsck/k9/mail/ServerSettings.java index 59633ffdd..b3d2852ea 100644 --- a/k9mail-library/src/main/java/com/fsck/k9/mail/ServerSettings.java +++ b/k9mail-library/src/main/java/com/fsck/k9/mail/ServerSettings.java @@ -16,10 +16,13 @@ import java.util.Map; * @see com.fsck.k9.mail.store.StoreConfig#getTransportUri() */ public class ServerSettings { + + public enum Type { IMAP, SMTP, WebDAV, POP3 } + /** - * Name of the store or transport type (e.g. "IMAP"). + * Name of the store or transport type (e.g. IMAP). */ - public final String type; + public final Type type; /** * The host name of the server. @@ -99,7 +102,7 @@ public class ServerSettings { * @param clientCertificateAlias * see {@link ServerSettings#clientCertificateAlias} */ - public ServerSettings(String type, String host, int port, + public ServerSettings(Type type, String host, int port, ConnectionSecurity connectionSecurity, AuthType authenticationType, String username, String password, String clientCertificateAlias) { this.type = type; @@ -135,7 +138,7 @@ public class ServerSettings { * @param extra * see {@link ServerSettings#extra} */ - public ServerSettings(String type, String host, int port, + public ServerSettings(Type type, String host, int port, ConnectionSecurity connectionSecurity, AuthType authenticationType, String username, String password, String clientCertificateAlias, Map extra) { this.type = type; @@ -158,7 +161,7 @@ public class ServerSettings { * @param type * see {@link ServerSettings#type} */ - public ServerSettings(String type) { + public ServerSettings(Type type) { this.type = type; host = null; port = -1; diff --git a/k9mail-library/src/main/java/com/fsck/k9/mail/Transport.java b/k9mail-library/src/main/java/com/fsck/k9/mail/Transport.java index 068e8ee86..a549de0d4 100644 --- a/k9mail-library/src/main/java/com/fsck/k9/mail/Transport.java +++ b/k9mail-library/src/main/java/com/fsck/k9/mail/Transport.java @@ -5,6 +5,7 @@ import android.content.Context; import com.fsck.k9.mail.ssl.DefaultTrustedSocketFactory; import com.fsck.k9.mail.store.StoreConfig; +import com.fsck.k9.mail.ServerSettings.Type; import com.fsck.k9.mail.transport.SmtpTransport; import com.fsck.k9.mail.transport.WebDavTransport; @@ -63,9 +64,9 @@ public abstract class Transport { * @see WebDavTransport#createUri(ServerSettings) */ public static String createTransportUri(ServerSettings server) { - if (SmtpTransport.TRANSPORT_TYPE.equals(server.type)) { + if (Type.SMTP == server.type) { return SmtpTransport.createUri(server); - } else if (WebDavTransport.TRANSPORT_TYPE.equals(server.type)) { + } else if (Type.WebDAV == server.type) { return WebDavTransport.createUri(server); } else { throw new IllegalArgumentException("Not a valid transport URI"); diff --git a/k9mail-library/src/main/java/com/fsck/k9/mail/store/RemoteStore.java b/k9mail-library/src/main/java/com/fsck/k9/mail/store/RemoteStore.java index 0c7562dd3..d2850f2ba 100644 --- a/k9mail-library/src/main/java/com/fsck/k9/mail/store/RemoteStore.java +++ b/k9mail-library/src/main/java/com/fsck/k9/mail/store/RemoteStore.java @@ -5,6 +5,7 @@ import android.net.ConnectivityManager; import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mail.ServerSettings; +import com.fsck.k9.mail.ServerSettings.Type; import com.fsck.k9.mail.Store; import com.fsck.k9.mail.ssl.DefaultTrustedSocketFactory; import com.fsck.k9.mail.ssl.TrustedSocketFactory; @@ -121,11 +122,11 @@ public abstract class RemoteStore extends Store { * @see com.fsck.k9.mail.store.webdav.WebDavStore#createUri(com.fsck.k9.mail.ServerSettings) */ public static String createStoreUri(ServerSettings server) { - if (ImapStore.STORE_TYPE.equals(server.type)) { + if (Type.IMAP == server.type) { return ImapStore.createUri(server); - } else if (Pop3Store.STORE_TYPE.equals(server.type)) { + } else if (Type.POP3 == server.type) { return Pop3Store.createUri(server); - } else if (WebDavStore.STORE_TYPE.equals(server.type)) { + } else if (Type.WebDAV == server.type) { return WebDavStore.createUri(server); } else { throw new IllegalArgumentException("Not a valid store URI"); diff --git a/k9mail-library/src/main/java/com/fsck/k9/mail/store/imap/ImapStore.java b/k9mail-library/src/main/java/com/fsck/k9/mail/store/imap/ImapStore.java index 7df04e2b4..006ef7ee0 100644 --- a/k9mail-library/src/main/java/com/fsck/k9/mail/store/imap/ImapStore.java +++ b/k9mail-library/src/main/java/com/fsck/k9/mail/store/imap/ImapStore.java @@ -77,7 +77,6 @@ import static com.fsck.k9.mail.K9MailLib.PUSH_WAKE_LOCK_TIMEOUT; * */ public class ImapStore extends RemoteStore { - public static final String STORE_TYPE = "IMAP"; private static final int IDLE_READ_TIMEOUT_INCREMENT = 5 * 60 * 1000; private static final int IDLE_FAILURE_COUNT_LIMIT = 10; @@ -284,7 +283,7 @@ public class ImapStore extends RemoteStore { protected ImapStoreSettings(String host, int port, ConnectionSecurity connectionSecurity, AuthType authenticationType, String username, String password, String clientCertificateAlias, boolean autodetectNamespace, String pathPrefix) { - super(STORE_TYPE, host, port, connectionSecurity, authenticationType, username, + super(Type.IMAP, host, port, connectionSecurity, authenticationType, username, password, clientCertificateAlias); this.autoDetectNamespace = autodetectNamespace; this.pathPrefix = pathPrefix; diff --git a/k9mail-library/src/main/java/com/fsck/k9/mail/store/pop3/Pop3Store.java b/k9mail-library/src/main/java/com/fsck/k9/mail/store/pop3/Pop3Store.java index 922115e4e..37a5718f9 100644 --- a/k9mail-library/src/main/java/com/fsck/k9/mail/store/pop3/Pop3Store.java +++ b/k9mail-library/src/main/java/com/fsck/k9/mail/store/pop3/Pop3Store.java @@ -38,7 +38,6 @@ import static com.fsck.k9.mail.K9MailLib.LOG_TAG; import static com.fsck.k9.mail.CertificateValidationException.Reason.MissingCapability; public class Pop3Store extends RemoteStore { - public static final String STORE_TYPE = "POP3"; private static final String STLS_COMMAND = "STLS"; private static final String USER_COMMAND = "USER"; @@ -140,7 +139,7 @@ public class Pop3Store extends RemoteStore { } } - return new ServerSettings(STORE_TYPE, host, port, connectionSecurity, authType, username, + return new ServerSettings(ServerSettings.Type.POP3, host, port, connectionSecurity, authType, username, password, clientCertificateAlias); } diff --git a/k9mail-library/src/main/java/com/fsck/k9/mail/store/webdav/WebDavStore.java b/k9mail-library/src/main/java/com/fsck/k9/mail/store/webdav/WebDavStore.java index 550fad50e..4048d5553 100644 --- a/k9mail-library/src/main/java/com/fsck/k9/mail/store/webdav/WebDavStore.java +++ b/k9mail-library/src/main/java/com/fsck/k9/mail/store/webdav/WebDavStore.java @@ -58,7 +58,6 @@ import static com.fsck.k9.mail.K9MailLib.LOG_TAG; * */ public class WebDavStore extends RemoteStore { - public static final String STORE_TYPE = "WebDAV"; // Authentication types private static final short AUTH_TYPE_NONE = 0; @@ -248,7 +247,7 @@ public class WebDavStore extends RemoteStore { protected WebDavStoreSettings(String host, int port, ConnectionSecurity connectionSecurity, AuthType authenticationType, String username, String password, String clientCertificateAlias, String alias, String path, String authPath, String mailboxPath) { - super(STORE_TYPE, host, port, connectionSecurity, authenticationType, username, + super(Type.WebDAV, host, port, connectionSecurity, authenticationType, username, password, clientCertificateAlias); this.alias = alias; this.path = path; diff --git a/k9mail-library/src/main/java/com/fsck/k9/mail/transport/SmtpTransport.java b/k9mail-library/src/main/java/com/fsck/k9/mail/transport/SmtpTransport.java index 9a4fab54d..27600198b 100644 --- a/k9mail-library/src/main/java/com/fsck/k9/mail/transport/SmtpTransport.java +++ b/k9mail-library/src/main/java/com/fsck/k9/mail/transport/SmtpTransport.java @@ -32,8 +32,6 @@ import static com.fsck.k9.mail.CertificateValidationException.Reason.MissingCapa public class SmtpTransport extends Transport { private TrustedSocketFactory mTrustedSocketFactory; - public static final String TRANSPORT_TYPE = "SMTP"; - /** * Decodes a SmtpTransport URI. * @@ -115,7 +113,7 @@ public class SmtpTransport extends Transport { } } - return new ServerSettings(TRANSPORT_TYPE, host, port, connectionSecurity, + return new ServerSettings(ServerSettings.Type.SMTP, host, port, connectionSecurity, authType, username, password, clientCertificateAlias); } diff --git a/k9mail-library/src/main/java/com/fsck/k9/mail/transport/WebDavTransport.java b/k9mail-library/src/main/java/com/fsck/k9/mail/transport/WebDavTransport.java index 5f420d455..61ac6f102 100644 --- a/k9mail-library/src/main/java/com/fsck/k9/mail/transport/WebDavTransport.java +++ b/k9mail-library/src/main/java/com/fsck/k9/mail/transport/WebDavTransport.java @@ -16,7 +16,6 @@ import java.util.Collections; import static com.fsck.k9.mail.K9MailLib.LOG_TAG; public class WebDavTransport extends Transport { - public static final String TRANSPORT_TYPE = WebDavStore.STORE_TYPE; /** * Decodes a WebDavTransport URI. diff --git a/k9mail/src/main/java/com/fsck/k9/account/AccountCreator.java b/k9mail/src/main/java/com/fsck/k9/account/AccountCreator.java new file mode 100644 index 000000000..4b19e8759 --- /dev/null +++ b/k9mail/src/main/java/com/fsck/k9/account/AccountCreator.java @@ -0,0 +1,28 @@ +package com.fsck.k9.account; + +import com.fsck.k9.Account.DeletePolicy; +import com.fsck.k9.mail.ServerSettings.Type; + +import java.util.HashMap; +import java.util.Map; + +/** + * Deals with logic surrounding account creation. + *

+ * TODO Move much of the code from com.fsck.k9.activity.setup.* into here + */ +public class AccountCreator { + + private static Map defaults = new HashMap(); + + static { + defaults.put(Type.IMAP, DeletePolicy.ON_DELETE); + defaults.put(Type.POP3, DeletePolicy.NEVER); + defaults.put(Type.WebDAV, DeletePolicy.ON_DELETE); + } + + public static DeletePolicy calculateDefaultDeletePolicy(Type type) { + return defaults.get(type); + } + +} diff --git a/k9mail/src/main/java/com/fsck/k9/activity/Accounts.java b/k9mail/src/main/java/com/fsck/k9/activity/Accounts.java index 735a522c2..6454ebedf 100644 --- a/k9mail/src/main/java/com/fsck/k9/activity/Accounts.java +++ b/k9mail/src/main/java/com/fsck/k9/activity/Accounts.java @@ -81,7 +81,6 @@ import com.fsck.k9.mail.Transport; import com.fsck.k9.mail.internet.MimeUtility; import com.fsck.k9.mail.store.RemoteStore; import com.fsck.k9.mailstore.StorageManager; -import com.fsck.k9.mail.store.webdav.WebDavStore; import com.fsck.k9.preferences.SettingsExporter; import com.fsck.k9.preferences.SettingsImportExportException; import com.fsck.k9.preferences.SettingsImporter; @@ -779,7 +778,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener { * Also don't ask when the AuthType is EXTERNAL. */ boolean configureOutgoingServer = AuthType.EXTERNAL != outgoing.authenticationType - && !WebDavStore.STORE_TYPE.equals(outgoing.type) + && !(ServerSettings.Type.WebDAV == outgoing.type) && outgoing.username != null && !outgoing.username.isEmpty() && (outgoing.password == null || outgoing.password diff --git a/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupBasics.java b/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupBasics.java index 3477cc0bb..93835a0c4 100644 --- a/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupBasics.java +++ b/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupBasics.java @@ -27,7 +27,6 @@ import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.EditText; import com.fsck.k9.Account; -import com.fsck.k9.Account.DeletePolicy; import com.fsck.k9.EmailAddressValidator; import com.fsck.k9.K9; import com.fsck.k9.Preferences; @@ -40,9 +39,8 @@ import com.fsck.k9.mail.AuthType; import com.fsck.k9.mail.ConnectionSecurity; import com.fsck.k9.mail.ServerSettings; import com.fsck.k9.mail.Transport; -import com.fsck.k9.mail.store.imap.ImapStore; import com.fsck.k9.mail.store.RemoteStore; -import com.fsck.k9.mail.transport.SmtpTransport; +import com.fsck.k9.account.AccountCreator; import com.fsck.k9.view.ClientCertificateSpinner; import com.fsck.k9.view.ClientCertificateSpinner.OnClientCertificateChangedListener; @@ -319,21 +317,12 @@ public class AccountSetupBasics extends K9Activity mAccount.setEmail(email); mAccount.setStoreUri(incomingUri.toString()); mAccount.setTransportUri(outgoingUri.toString()); - mAccount.setDraftsFolderName(getString(R.string.special_mailbox_name_drafts)); - mAccount.setTrashFolderName(getString(R.string.special_mailbox_name_trash)); - mAccount.setArchiveFolderName(getString(R.string.special_mailbox_name_archive)); - // Yahoo! has a special folder for Spam, called "Bulk Mail". - if (incomingUriTemplate.getHost().toLowerCase(Locale.US).endsWith(".yahoo.com")) { - mAccount.setSpamFolderName("Bulk Mail"); - } else { - mAccount.setSpamFolderName(getString(R.string.special_mailbox_name_spam)); - } - mAccount.setSentFolderName(getString(R.string.special_mailbox_name_sent)); - if (incomingUri.toString().startsWith("imap")) { - mAccount.setDeletePolicy(DeletePolicy.ON_DELETE); - } else if (incomingUri.toString().startsWith("pop3")) { - mAccount.setDeletePolicy(DeletePolicy.NEVER); - } + + setupFolderNames(incomingUriTemplate.getHost().toLowerCase(Locale.US)); + + ServerSettings incomingSettings = RemoteStore.decodeStoreUri(incomingUri.toString()); + mAccount.setDeletePolicy(AccountCreator.calculateDefaultDeletePolicy(incomingSettings.type)); + // Check incoming here. Then check outgoing in onActivityResult() AccountSetupCheckSettings.actionCheckSettings(this, mAccount, CheckDirection.INCOMING); } catch (URISyntaxException use) { @@ -416,31 +405,37 @@ public class AccountSetupBasics extends K9Activity // set default uris // NOTE: they will be changed again in AccountSetupAccountType! - ServerSettings storeServer = new ServerSettings(ImapStore.STORE_TYPE, "mail." + domain, -1, + ServerSettings storeServer = new ServerSettings(ServerSettings.Type.IMAP, "mail." + domain, -1, ConnectionSecurity.SSL_TLS_REQUIRED, authenticationType, user, password, clientCertificateAlias); - ServerSettings transportServer = new ServerSettings(SmtpTransport.TRANSPORT_TYPE, "mail." + domain, -1, + ServerSettings transportServer = new ServerSettings(ServerSettings.Type.SMTP, "mail." + domain, -1, ConnectionSecurity.SSL_TLS_REQUIRED, authenticationType, user, password, clientCertificateAlias); String storeUri = RemoteStore.createStoreUri(storeServer); String transportUri = Transport.createTransportUri(transportServer); mAccount.setStoreUri(storeUri); mAccount.setTransportUri(transportUri); + setupFolderNames(domain); + + AccountSetupAccountType.actionSelectAccountType(this, mAccount, false); + + finish(); + } + + private void setupFolderNames(String domain) { mAccount.setDraftsFolderName(getString(R.string.special_mailbox_name_drafts)); mAccount.setTrashFolderName(getString(R.string.special_mailbox_name_trash)); mAccount.setSentFolderName(getString(R.string.special_mailbox_name_sent)); mAccount.setArchiveFolderName(getString(R.string.special_mailbox_name_archive)); + // Yahoo! has a special folder for Spam, called "Bulk Mail". if (domain.endsWith(".yahoo.com")) { mAccount.setSpamFolderName("Bulk Mail"); } else { mAccount.setSpamFolderName(getString(R.string.special_mailbox_name_spam)); } - - AccountSetupAccountType.actionSelectAccountType(this, mAccount, false); - - finish(); } + public void onClick(View v) { switch (v.getId()) { case R.id.next: diff --git a/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupIncoming.java b/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupIncoming.java index 07281a48b..ec84f663d 100644 --- a/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupIncoming.java +++ b/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupIncoming.java @@ -16,7 +16,6 @@ import android.widget.AdapterView.OnItemSelectedListener; import android.widget.CompoundButton.OnCheckedChangeListener; import com.fsck.k9.*; -import com.fsck.k9.Account.DeletePolicy; import com.fsck.k9.Account.FolderMode; import com.fsck.k9.Account.NetworkType; import com.fsck.k9.activity.K9Activity; @@ -25,15 +24,13 @@ import com.fsck.k9.helper.Utility; import com.fsck.k9.mail.AuthType; import com.fsck.k9.mail.ConnectionSecurity; import com.fsck.k9.mail.ServerSettings; +import com.fsck.k9.mail.ServerSettings.Type; import com.fsck.k9.mail.Store; import com.fsck.k9.mail.Transport; -import com.fsck.k9.mail.store.imap.ImapStore; -import com.fsck.k9.mail.store.pop3.Pop3Store; import com.fsck.k9.mail.store.RemoteStore; -import com.fsck.k9.mail.store.webdav.WebDavStore; import com.fsck.k9.mail.store.imap.ImapStore.ImapStoreSettings; import com.fsck.k9.mail.store.webdav.WebDavStore.WebDavStoreSettings; -import com.fsck.k9.mail.transport.SmtpTransport; +import com.fsck.k9.account.AccountCreator; import com.fsck.k9.service.MailService; import com.fsck.k9.view.ClientCertificateSpinner; import com.fsck.k9.view.ClientCertificateSpinner.OnClientCertificateChangedListener; @@ -56,7 +53,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener private static final String WEBDAV_PORT = "80"; private static final String WEBDAV_SSL_PORT = "443"; - private String mStoreType; + private Type mStoreType; private EditText mUsernameView; private EditText mPasswordView; private ClientCertificateSpinner mClientCertificateSpinner; @@ -190,7 +187,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener } mStoreType = settings.type; - if (Pop3Store.STORE_TYPE.equals(settings.type)) { + if (Type.POP3 == settings.type) { serverLabelView.setText(R.string.account_setup_incoming_pop_server_label); mDefaultPort = POP3_PORT; mDefaultSslPort = POP3_SSL_PORT; @@ -202,8 +199,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener findViewById(R.id.compression_section).setVisibility(View.GONE); findViewById(R.id.compression_label).setVisibility(View.GONE); mSubscribedFoldersOnly.setVisibility(View.GONE); - mAccount.setDeletePolicy(DeletePolicy.NEVER); - } else if (ImapStore.STORE_TYPE.equals(settings.type)) { + } else if (Type.IMAP == settings.type) { serverLabelView.setText(R.string.account_setup_incoming_imap_server_label); mDefaultPort = IMAP_PORT; mDefaultSslPort = IMAP_SSL_PORT; @@ -219,12 +215,11 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener findViewById(R.id.webdav_mailbox_alias_section).setVisibility(View.GONE); findViewById(R.id.webdav_owa_path_section).setVisibility(View.GONE); findViewById(R.id.webdav_auth_path_section).setVisibility(View.GONE); - mAccount.setDeletePolicy(DeletePolicy.ON_DELETE); if (!Intent.ACTION_EDIT.equals(getIntent().getAction())) { findViewById(R.id.imap_folder_setup_section).setVisibility(View.GONE); } - } else if (WebDavStore.STORE_TYPE.equals(settings.type)) { + } else if (Type.WebDAV == settings.type) { serverLabelView.setText(R.string.account_setup_incoming_webdav_server_label); mDefaultPort = WEBDAV_PORT; mDefaultSslPort = WEBDAV_SSL_PORT; @@ -253,11 +248,12 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener if (webDavSettings.mailboxPath != null) { mWebdavMailboxPathView.setText(webDavSettings.mailboxPath); } - mAccount.setDeletePolicy(DeletePolicy.ON_DELETE); } else { throw new Exception("Unknown account type: " + mAccount.getStoreUri()); } + mAccount.setDeletePolicy(AccountCreator.calculateDefaultDeletePolicy(settings.type)); + // Note that mConnectionSecurityChoices is configured above based on server type ConnectionSecurityAdapter securityTypesAdapter = ConnectionSecurityAdapter.get(this, mConnectionSecurityChoices); @@ -551,7 +547,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener } URI oldUri = new URI(mAccount.getTransportUri()); - ServerSettings transportServer = new ServerSettings(SmtpTransport.TRANSPORT_TYPE, oldUri.getHost(), oldUri.getPort(), + ServerSettings transportServer = new ServerSettings(Type.SMTP, oldUri.getHost(), oldUri.getPort(), ConnectionSecurity.SSL_TLS_REQUIRED, authType, username, password, clientCertificateAlias); String transportUri = Transport.createTransportUri(transportServer); mAccount.setTransportUri(transportUri); @@ -587,13 +583,13 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener int port = Integer.parseInt(mPortView.getText().toString()); Map extra = null; - if (ImapStore.STORE_TYPE.equals(mStoreType)) { + if (Type.IMAP == mStoreType) { extra = new HashMap(); extra.put(ImapStoreSettings.AUTODETECT_NAMESPACE_KEY, Boolean.toString(mImapAutoDetectNamespaceView.isChecked())); extra.put(ImapStoreSettings.PATH_PREFIX_KEY, mImapPathPrefixView.getText().toString()); - } else if (WebDavStore.STORE_TYPE.equals(mStoreType)) { + } else if (Type.WebDAV == mStoreType) { extra = new HashMap(); extra.put(WebDavStoreSettings.PATH_KEY, mWebdavPathPrefixView.getText().toString()); diff --git a/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupOutgoing.java b/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupOutgoing.java index 7a3e7228c..6a511ee86 100644 --- a/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupOutgoing.java +++ b/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupOutgoing.java @@ -20,10 +20,10 @@ 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.ServerSettings.Type; import com.fsck.k9.mail.ConnectionSecurity; import com.fsck.k9.mail.ServerSettings; import com.fsck.k9.mail.Transport; -import com.fsck.k9.mail.transport.SmtpTransport; import com.fsck.k9.view.ClientCertificateSpinner; import com.fsck.k9.view.ClientCertificateSpinner.OnClientCertificateChangedListener; @@ -485,8 +485,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener, String newHost = mServerView.getText().toString(); int newPort = Integer.parseInt(mPortView.getText().toString()); - String type = SmtpTransport.TRANSPORT_TYPE; - ServerSettings server = new ServerSettings(type, newHost, newPort, securityType, authType, username, password, clientCertificateAlias); + ServerSettings server = new ServerSettings(Type.SMTP, newHost, newPort, securityType, authType, username, password, clientCertificateAlias); uri = Transport.createTransportUri(server); mAccount.deleteCertificate(newHost, newPort, CheckDirection.OUTGOING); mAccount.setTransportUri(uri); diff --git a/k9mail/src/main/java/com/fsck/k9/preferences/SettingsExporter.java b/k9mail/src/main/java/com/fsck/k9/preferences/SettingsExporter.java index f49ec7a20..f05f99dd0 100644 --- a/k9mail/src/main/java/com/fsck/k9/preferences/SettingsExporter.java +++ b/k9mail/src/main/java/com/fsck/k9/preferences/SettingsExporter.java @@ -225,7 +225,7 @@ public class SettingsExporter { // Write incoming server settings ServerSettings incoming = RemoteStore.decodeStoreUri(account.getStoreUri()); serializer.startTag(null, INCOMING_SERVER_ELEMENT); - serializer.attribute(null, TYPE_ATTRIBUTE, incoming.type); + serializer.attribute(null, TYPE_ATTRIBUTE, incoming.type.name()); writeElement(serializer, HOST_ELEMENT, incoming.host); if (incoming.port != -1) { @@ -257,7 +257,7 @@ public class SettingsExporter { // Write outgoing server settings ServerSettings outgoing = Transport.decodeTransportUri(account.getTransportUri()); serializer.startTag(null, OUTGOING_SERVER_ELEMENT); - serializer.attribute(null, TYPE_ATTRIBUTE, outgoing.type); + serializer.attribute(null, TYPE_ATTRIBUTE, outgoing.type.name()); writeElement(serializer, HOST_ELEMENT, outgoing.host); if (outgoing.port != -1) { diff --git a/k9mail/src/main/java/com/fsck/k9/preferences/SettingsImporter.java b/k9mail/src/main/java/com/fsck/k9/preferences/SettingsImporter.java index 070fd6521..8de46a85a 100644 --- a/k9mail/src/main/java/com/fsck/k9/preferences/SettingsImporter.java +++ b/k9mail/src/main/java/com/fsck/k9/preferences/SettingsImporter.java @@ -28,7 +28,6 @@ import com.fsck.k9.mail.ServerSettings; import com.fsck.k9.mail.Transport; import com.fsck.k9.mail.filter.Base64; import com.fsck.k9.mail.store.RemoteStore; -import com.fsck.k9.mail.store.webdav.WebDavStore; import com.fsck.k9.preferences.Settings.InvalidSettingValueException; public class SettingsImporter { @@ -384,7 +383,7 @@ public class SettingsImporter { boolean createAccountDisabled = AuthType.EXTERNAL != incoming.authenticationType && (incoming.password == null || incoming.password.isEmpty()); - if (account.outgoing == null && !WebDavStore.STORE_TYPE.equals(account.incoming.type)) { + if (account.outgoing == null && !ServerSettings.Type.WebDAV.name().equals(account.incoming.type)) { // All account types except WebDAV need to provide outgoing server settings throw new InvalidSettingValueException(); } @@ -403,7 +402,7 @@ public class SettingsImporter { * password required if the AuthType is EXTERNAL. */ boolean outgoingPasswordNeeded = AuthType.EXTERNAL != outgoing.authenticationType && - !WebDavStore.STORE_TYPE.equals(outgoing.type) && + !(ServerSettings.Type.WebDAV == outgoing.type) && outgoing.username != null && !outgoing.username.isEmpty() && (outgoing.password == null || outgoing.password.isEmpty()); @@ -1100,7 +1099,7 @@ public class SettingsImporter { private final ImportedServer mImportedServer; public ImportedServerSettings(ImportedServer server) { - super(server.type, server.host, convertPort(server.port), + super(ServerSettings.Type.valueOf(server.type), server.host, convertPort(server.port), convertConnectionSecurity(server.connectionSecurity), server.authenticationType, server.username, server.password, server.clientCertificateAlias); diff --git a/tests-on-jvm/src/test/java/com/fsck/k9/mail/store/imap/ImapStoreUriTest.java b/tests-on-jvm/src/test/java/com/fsck/k9/mail/store/imap/ImapStoreUriTest.java index f3f58a430..38d9572e2 100644 --- a/tests-on-jvm/src/test/java/com/fsck/k9/mail/store/imap/ImapStoreUriTest.java +++ b/tests-on-jvm/src/test/java/com/fsck/k9/mail/store/imap/ImapStoreUriTest.java @@ -91,7 +91,7 @@ public class ImapStoreUriTest { extra.put("autoDetectNamespace", "false"); extra.put("pathPrefix", "customPathPrefix"); - ServerSettings settings = new ServerSettings(ImapStore.STORE_TYPE, "server", 143, + ServerSettings settings = new ServerSettings(ServerSettings.Type.IMAP, "server", 143, ConnectionSecurity.NONE, AuthType.PLAIN, "user", "pass", null, extra); String uri = RemoteStore.createStoreUri(settings); @@ -105,7 +105,7 @@ public class ImapStoreUriTest { extra.put("autoDetectNamespace", "false"); extra.put("pathPrefix", ""); - ServerSettings settings = new ServerSettings(ImapStore.STORE_TYPE, "server", 143, + ServerSettings settings = new ServerSettings(ServerSettings.Type.IMAP, "server", 143, ConnectionSecurity.NONE, AuthType.PLAIN, "user", "pass", null, extra); String uri = RemoteStore.createStoreUri(settings); @@ -115,7 +115,7 @@ public class ImapStoreUriTest { @Test public void testCreateStoreUriImapNoExtra() { - ServerSettings settings = new ServerSettings(ImapStore.STORE_TYPE, "server", 143, + ServerSettings settings = new ServerSettings(ServerSettings.Type.IMAP, "server", 143, ConnectionSecurity.NONE, AuthType.PLAIN, "user", "pass", null); String uri = RemoteStore.createStoreUri(settings); @@ -128,7 +128,7 @@ public class ImapStoreUriTest { Map extra = new HashMap(); extra.put("autoDetectNamespace", "true"); - ServerSettings settings = new ServerSettings(ImapStore.STORE_TYPE, "server", 143, + ServerSettings settings = new ServerSettings(ServerSettings.Type.IMAP, "server", 143, ConnectionSecurity.NONE, AuthType.PLAIN, "user", "pass", null, extra); String uri = RemoteStore.createStoreUri(settings); @@ -138,7 +138,7 @@ public class ImapStoreUriTest { @Test public void testCreateDecodeStoreUriWithSpecialCharactersInUsernameAndPassword() { - ServerSettings settings = new ServerSettings(ImapStore.STORE_TYPE, "server", 143, + ServerSettings settings = new ServerSettings(ServerSettings.Type.IMAP, "server", 143, ConnectionSecurity.NONE, AuthType.PLAIN, "user@doma:n", "p@ssw:rd%", null, null); String uri = RemoteStore.createStoreUri(settings);