diff --git a/app/core/src/test/java/com/fsck/k9/preferences/SettingsImporterTestExtra.kt b/app/core/src/test/java/com/fsck/k9/preferences/SettingsImporterTestExtra.kt index 52d440c39..1956000ca 100644 --- a/app/core/src/test/java/com/fsck/k9/preferences/SettingsImporterTestExtra.kt +++ b/app/core/src/test/java/com/fsck/k9/preferences/SettingsImporterTestExtra.kt @@ -6,7 +6,8 @@ import com.fsck.k9.backend.BackendFactory import com.fsck.k9.backend.BackendManager import com.fsck.k9.backend.api.Backend import com.fsck.k9.mail.ServerSettings -import com.fsck.k9.mail.store.imap.ImapStore +import com.fsck.k9.mail.store.imap.ImapStoreUriCreator +import com.fsck.k9.mail.store.imap.ImapStoreUriDecoder import com.fsck.k9.mail.transport.smtp.SmtpTransportUriCreator import com.fsck.k9.mail.transport.smtp.SmtpTransportUriDecoder import org.koin.dsl.module.applicationContext @@ -21,11 +22,11 @@ fun setUpBackendManager() { } override fun decodeStoreUri(storeUri: String): ServerSettings { - return ImapStore.decodeUri(storeUri) + return ImapStoreUriDecoder.decode(storeUri) } override fun createStoreUri(serverSettings: ServerSettings): String { - return ImapStore.createUri(serverSettings) + return ImapStoreUriCreator.create(serverSettings) } override fun decodeTransportUri(transportUri: String): ServerSettings { diff --git a/app/k9mail/src/main/java/com/fsck/k9/backends/ImapBackendFactory.kt b/app/k9mail/src/main/java/com/fsck/k9/backends/ImapBackendFactory.kt index b2433ef01..6f7ded683 100644 --- a/app/k9mail/src/main/java/com/fsck/k9/backends/ImapBackendFactory.kt +++ b/app/k9mail/src/main/java/com/fsck/k9/backends/ImapBackendFactory.kt @@ -12,6 +12,8 @@ import com.fsck.k9.mail.oauth.OAuth2TokenProvider import com.fsck.k9.mail.power.PowerManager import com.fsck.k9.mail.ssl.DefaultTrustedSocketFactory import com.fsck.k9.mail.store.imap.ImapStore +import com.fsck.k9.mail.store.imap.ImapStoreUriCreator +import com.fsck.k9.mail.store.imap.ImapStoreUriDecoder import com.fsck.k9.mail.transport.smtp.SmtpTransport import com.fsck.k9.mail.transport.smtp.SmtpTransportUriCreator import com.fsck.k9.mail.transport.smtp.SmtpTransportUriDecoder @@ -48,11 +50,11 @@ class ImapBackendFactory( } override fun decodeStoreUri(storeUri: String): ServerSettings { - return ImapStore.decodeUri(storeUri) + return ImapStoreUriDecoder.decode(storeUri) } override fun createStoreUri(serverSettings: ServerSettings): String { - return ImapStore.createUri(serverSettings) + return ImapStoreUriCreator.create(serverSettings) } override fun decodeTransportUri(transportUri: String): ServerSettings { diff --git a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapStore.java b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapStore.java index 47fbd0de2..85f66819b 100644 --- a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapStore.java +++ b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapStore.java @@ -23,7 +23,6 @@ import com.fsck.k9.mail.Flag; import com.fsck.k9.mail.K9MailLib; import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mail.NetworkType; -import com.fsck.k9.mail.ServerSettings; import com.fsck.k9.mail.oauth.OAuth2TokenProvider; import com.fsck.k9.mail.ssl.TrustedSocketFactory; import com.fsck.k9.mail.store.RemoteStore; @@ -64,21 +63,13 @@ public class ImapStore extends RemoteStore { private final Map folderCache = new HashMap(); - public static ImapStoreSettings decodeUri(String uri) { - return ImapStoreUriDecoder.decode(uri); - } - - public static String createUri(ServerSettings server) { - return ImapStoreUriCreator.create(server); - } - public ImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory, ConnectivityManager connectivityManager, OAuth2TokenProvider oauthTokenProvider) throws MessagingException { super(storeConfig, trustedSocketFactory); ImapStoreSettings settings; try { - settings = decodeUri(storeConfig.getStoreUri()); + settings = ImapStoreUriDecoder.decode(storeConfig.getStoreUri()); } catch (IllegalArgumentException e) { throw new MessagingException("Error while decoding store URI", e); } diff --git a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapStoreUriCreator.java b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapStoreUriCreator.java index b5d9ced48..9df135c05 100644 --- a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapStoreUriCreator.java +++ b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapStoreUriCreator.java @@ -11,7 +11,7 @@ import com.fsck.k9.mail.ServerSettings; import static com.fsck.k9.mail.helper.UrlEncodingHelper.encodeUtf8; -class ImapStoreUriCreator { +public class ImapStoreUriCreator { /** * Creates an ImapStore URI with the supplied settings. * @@ -21,7 +21,6 @@ class ImapStoreUriCreator { * @return An ImapStore URI that holds the same information as the {@code server} parameter. * * @see com.fsck.k9.mail.store.StoreConfig#getStoreUri() - * @see ImapStore#decodeUri(String) */ public static String create(ServerSettings server) { String userEnc = encodeUtf8(server.username); diff --git a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapStoreUriDecoder.java b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapStoreUriDecoder.java index c34302802..c7dabb858 100644 --- a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapStoreUriDecoder.java +++ b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapStoreUriDecoder.java @@ -12,7 +12,7 @@ import com.fsck.k9.mail.ServerSettings.Type; import static com.fsck.k9.mail.helper.UrlEncodingHelper.decodeUtf8; -class ImapStoreUriDecoder { +public class ImapStoreUriDecoder { /** * Decodes an ImapStore URI. * diff --git a/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/ImapStoreUriTest.java b/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/ImapStoreUriTest.java index d2aa38826..e08a065c0 100644 --- a/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/ImapStoreUriTest.java +++ b/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/ImapStoreUriTest.java @@ -18,7 +18,7 @@ public class ImapStoreUriTest { public void testDecodeStoreUriImapNoAuth() { String uri = "imap://user:pass@server/"; - ServerSettings settings = ImapStore.decodeUri(uri); + ServerSettings settings = ImapStoreUriDecoder.decode(uri); assertEquals(AuthType.PLAIN, settings.authenticationType); assertEquals("user", settings.username); @@ -30,7 +30,7 @@ public class ImapStoreUriTest { public void testDecodeStoreUriImapNoPassword() { String uri = "imap://user:@server/"; - ServerSettings settings = ImapStore.decodeUri(uri); + ServerSettings settings = ImapStoreUriDecoder.decode(uri); assertEquals(AuthType.PLAIN, settings.authenticationType); assertEquals("user", settings.username); @@ -42,7 +42,7 @@ public class ImapStoreUriTest { public void testDecodeStoreUriImapPlainNoPassword() { String uri = "imap://PLAIN:user:@server/"; - ServerSettings settings = ImapStore.decodeUri(uri); + ServerSettings settings = ImapStoreUriDecoder.decode(uri); assertEquals(AuthType.PLAIN, settings.authenticationType); assertEquals("user", settings.username); @@ -54,7 +54,7 @@ public class ImapStoreUriTest { public void testDecodeStoreUriImapExternalAuth() { String uri = "imap://EXTERNAL:user:clientCertAlias@server/"; - ServerSettings settings = ImapStore.decodeUri(uri); + ServerSettings settings = ImapStoreUriDecoder.decode(uri); assertEquals(AuthType.EXTERNAL, settings.authenticationType); assertEquals("user", settings.username); @@ -67,7 +67,7 @@ public class ImapStoreUriTest { public void testDecodeStoreUriImapXOAuth2() { String uri = "imap://XOAUTH2:user:@server/"; - ServerSettings settings = ImapStore.decodeUri(uri); + ServerSettings settings = ImapStoreUriDecoder.decode(uri); assertEquals(AuthType.XOAUTH2, settings.authenticationType); assertEquals("user", settings.username); @@ -79,7 +79,7 @@ public class ImapStoreUriTest { @Test public void testDecodeStoreUriImapSSL() { String uri = "imap+tls+://PLAIN:user:pass@server/"; - ServerSettings settings = ImapStore.decodeUri(uri); + ServerSettings settings = ImapStoreUriDecoder.decode(uri); assertEquals(ConnectionSecurity.STARTTLS_REQUIRED, settings.connectionSecurity); assertEquals(AuthType.PLAIN, settings.authenticationType); @@ -92,7 +92,7 @@ public class ImapStoreUriTest { public void testDecodeStoreUriImapTLS() { String uri = "imap+ssl+://PLAIN:user:pass@server/"; - ServerSettings settings = ImapStore.decodeUri(uri); + ServerSettings settings = ImapStoreUriDecoder.decode(uri); assertEquals(ConnectionSecurity.SSL_TLS_REQUIRED, settings.connectionSecurity); assertEquals(AuthType.PLAIN, settings.authenticationType); @@ -105,7 +105,7 @@ public class ImapStoreUriTest { public void testDecodeStoreUriImapAllExtras() { String uri = "imap://PLAIN:user:pass@server:143/0%7CcustomPathPrefix"; - ServerSettings settings = ImapStore.decodeUri(uri); + ServerSettings settings = ImapStoreUriDecoder.decode(uri); assertEquals(AuthType.PLAIN, settings.authenticationType); assertEquals("user", settings.username); @@ -120,7 +120,7 @@ public class ImapStoreUriTest { public void testDecodeStoreUriImapNoExtras() { String uri = "imap://PLAIN:user:pass@server:143/"; - ServerSettings settings = ImapStore.decodeUri(uri); + ServerSettings settings = ImapStoreUriDecoder.decode(uri); assertEquals(AuthType.PLAIN, settings.authenticationType); assertEquals("user", settings.username); @@ -134,7 +134,7 @@ public class ImapStoreUriTest { public void testDecodeStoreUriImapPrefixOnly() { String uri = "imap://PLAIN:user:pass@server:143/customPathPrefix"; - ServerSettings settings = ImapStore.decodeUri(uri); + ServerSettings settings = ImapStoreUriDecoder.decode(uri); assertEquals(AuthType.PLAIN, settings.authenticationType); assertEquals("user", settings.username); @@ -149,7 +149,7 @@ public class ImapStoreUriTest { public void testDecodeStoreUriImapEmptyPrefix() { String uri = "imap://PLAIN:user:pass@server:143/0%7C"; - ServerSettings settings = ImapStore.decodeUri(uri); + ServerSettings settings = ImapStoreUriDecoder.decode(uri); assertEquals(AuthType.PLAIN, settings.authenticationType); assertEquals("user", settings.username); @@ -164,7 +164,7 @@ public class ImapStoreUriTest { public void testDecodeStoreUriImapAutodetectAndPrefix() { String uri = "imap://PLAIN:user:pass@server:143/1%7CcustomPathPrefix"; - ServerSettings settings = ImapStore.decodeUri(uri); + ServerSettings settings = ImapStoreUriDecoder.decode(uri); assertEquals(AuthType.PLAIN, settings.authenticationType); assertEquals("user", settings.username); @@ -183,7 +183,7 @@ public class ImapStoreUriTest { ServerSettings settings = new ServerSettings(ServerSettings.Type.IMAP, "server", 143, ConnectionSecurity.NONE, AuthType.PLAIN, "user", "pass", null, extra); - String uri = ImapStore.createUri(settings); + String uri = ImapStoreUriCreator.create(settings); assertEquals("imap://PLAIN:user:pass@server:143/0%7CcustomPathPrefix", uri); } @@ -196,7 +196,7 @@ public class ImapStoreUriTest { ServerSettings settings = new ServerSettings(ServerSettings.Type.IMAP, "server", 143, ConnectionSecurity.NONE, AuthType.PLAIN, "user", "pass", null, extra); - String uri = ImapStore.createUri(settings); + String uri = ImapStoreUriCreator.create(settings); assertEquals("imap://PLAIN:user:pass@server:143/0%7C", uri); } @@ -206,7 +206,7 @@ public class ImapStoreUriTest { ServerSettings settings = new ServerSettings(ServerSettings.Type.IMAP, "server", 143, ConnectionSecurity.NONE, AuthType.PLAIN, "user", "pass", null); - String uri = ImapStore.createUri(settings); + String uri = ImapStoreUriCreator.create(settings); assertEquals("imap://PLAIN:user:pass@server:143/1%7C", uri); } @@ -219,7 +219,7 @@ public class ImapStoreUriTest { ServerSettings settings = new ServerSettings(ServerSettings.Type.IMAP, "server", 143, ConnectionSecurity.NONE, AuthType.PLAIN, "user", "pass", null, extra); - String uri = ImapStore.createUri(settings); + String uri = ImapStoreUriCreator.create(settings); assertEquals("imap://PLAIN:user:pass@server:143/1%7C", uri); } @@ -229,11 +229,11 @@ public class ImapStoreUriTest { ServerSettings settings = new ServerSettings(ServerSettings.Type.IMAP, "server", 143, ConnectionSecurity.NONE, AuthType.PLAIN, "user@doma:n", "p@ssw:rd%", null, null); - String uri = ImapStore.createUri(settings); + String uri = ImapStoreUriCreator.create(settings); assertEquals("imap://PLAIN:user%2540doma%253An:p%2540ssw%253Ard%2525@server:143/1%7C", uri); - ServerSettings outSettings = ImapStore.decodeUri(uri); + ServerSettings outSettings = ImapStoreUriDecoder.decode(uri); assertEquals("user@doma:n", outSettings.username); assertEquals("p@ssw:rd%", outSettings.password);