From 9cb5c70e4bbe3bde7296df576142ab8049c59e6e Mon Sep 17 00:00:00 2001 From: cketti Date: Mon, 16 Jul 2018 18:41:39 +0200 Subject: [PATCH] Remove knowledge of store URI from :mail:protocols:pop3 module --- .../fsck/k9/backends/Pop3BackendFactory.kt | 7 ++--- .../k9/backend}/pop3/Pop3StoreUriCreator.java | 2 +- .../k9/backend}/pop3/Pop3StoreUriDecoder.java | 2 +- .../pop3/Pop3StoreUriCreatorTest.java | 2 +- .../pop3/Pop3StoreUriDecoderTest.java | 2 +- .../fsck/k9/mail/store/pop3/Pop3Store.java | 23 ++++++---------- .../k9/mail/store/pop3/Pop3StoreTest.java | 27 ++++++++++++------- 7 files changed, 34 insertions(+), 31 deletions(-) rename {mail/protocols/pop3/src/main/java/com/fsck/k9/mail/store => backend/pop3/src/main/java/com/fsck/k9/backend}/pop3/Pop3StoreUriCreator.java (98%) rename {mail/protocols/pop3/src/main/java/com/fsck/k9/mail/store => backend/pop3/src/main/java/com/fsck/k9/backend}/pop3/Pop3StoreUriDecoder.java (98%) rename {mail/protocols/pop3/src/test/java/com/fsck/k9/mail/store => backend/pop3/src/test/java/com/fsck/k9/backend}/pop3/Pop3StoreUriCreatorTest.java (98%) rename {mail/protocols/pop3/src/test/java/com/fsck/k9/mail/store => backend/pop3/src/test/java/com/fsck/k9/backend}/pop3/Pop3StoreUriDecoderTest.java (97%) diff --git a/app/k9mail/src/main/java/com/fsck/k9/backends/Pop3BackendFactory.kt b/app/k9mail/src/main/java/com/fsck/k9/backends/Pop3BackendFactory.kt index a0323ec29..e7593bcc4 100644 --- a/app/k9mail/src/main/java/com/fsck/k9/backends/Pop3BackendFactory.kt +++ b/app/k9mail/src/main/java/com/fsck/k9/backends/Pop3BackendFactory.kt @@ -10,8 +10,8 @@ import com.fsck.k9.mail.ServerSettings import com.fsck.k9.mail.oauth.OAuth2TokenProvider import com.fsck.k9.mail.ssl.DefaultTrustedSocketFactory import com.fsck.k9.mail.store.pop3.Pop3Store -import com.fsck.k9.mail.store.pop3.Pop3StoreUriCreator -import com.fsck.k9.mail.store.pop3.Pop3StoreUriDecoder +import com.fsck.k9.backend.pop3.Pop3StoreUriCreator +import com.fsck.k9.backend.pop3.Pop3StoreUriDecoder import com.fsck.k9.mail.transport.smtp.SmtpTransport import com.fsck.k9.mail.transport.smtp.SmtpTransportUriCreator import com.fsck.k9.mail.transport.smtp.SmtpTransportUriDecoder @@ -29,7 +29,8 @@ class Pop3BackendFactory(private val context: Context, private val preferences: } private fun createPop3Store(account: Account): Pop3Store { - return Pop3Store(account, DefaultTrustedSocketFactory(context)) + val serverSettings = decodeStoreUri(account.storeUri) + return Pop3Store(serverSettings, account, DefaultTrustedSocketFactory(context)) } private fun createSmtpTransport(account: Account): SmtpTransport { diff --git a/mail/protocols/pop3/src/main/java/com/fsck/k9/mail/store/pop3/Pop3StoreUriCreator.java b/backend/pop3/src/main/java/com/fsck/k9/backend/pop3/Pop3StoreUriCreator.java similarity index 98% rename from mail/protocols/pop3/src/main/java/com/fsck/k9/mail/store/pop3/Pop3StoreUriCreator.java rename to backend/pop3/src/main/java/com/fsck/k9/backend/pop3/Pop3StoreUriCreator.java index 5b6857415..2931f0e43 100644 --- a/mail/protocols/pop3/src/main/java/com/fsck/k9/mail/store/pop3/Pop3StoreUriCreator.java +++ b/backend/pop3/src/main/java/com/fsck/k9/backend/pop3/Pop3StoreUriCreator.java @@ -1,4 +1,4 @@ -package com.fsck.k9.mail.store.pop3; +package com.fsck.k9.backend.pop3; import java.net.URI; diff --git a/mail/protocols/pop3/src/main/java/com/fsck/k9/mail/store/pop3/Pop3StoreUriDecoder.java b/backend/pop3/src/main/java/com/fsck/k9/backend/pop3/Pop3StoreUriDecoder.java similarity index 98% rename from mail/protocols/pop3/src/main/java/com/fsck/k9/mail/store/pop3/Pop3StoreUriDecoder.java rename to backend/pop3/src/main/java/com/fsck/k9/backend/pop3/Pop3StoreUriDecoder.java index 40c4a5230..c110d83ac 100644 --- a/mail/protocols/pop3/src/main/java/com/fsck/k9/mail/store/pop3/Pop3StoreUriDecoder.java +++ b/backend/pop3/src/main/java/com/fsck/k9/backend/pop3/Pop3StoreUriDecoder.java @@ -1,4 +1,4 @@ -package com.fsck.k9.mail.store.pop3; +package com.fsck.k9.backend.pop3; import java.net.URI; diff --git a/mail/protocols/pop3/src/test/java/com/fsck/k9/mail/store/pop3/Pop3StoreUriCreatorTest.java b/backend/pop3/src/test/java/com/fsck/k9/backend/pop3/Pop3StoreUriCreatorTest.java similarity index 98% rename from mail/protocols/pop3/src/test/java/com/fsck/k9/mail/store/pop3/Pop3StoreUriCreatorTest.java rename to backend/pop3/src/test/java/com/fsck/k9/backend/pop3/Pop3StoreUriCreatorTest.java index b4c8ea892..7ff4ae07a 100644 --- a/mail/protocols/pop3/src/test/java/com/fsck/k9/mail/store/pop3/Pop3StoreUriCreatorTest.java +++ b/backend/pop3/src/test/java/com/fsck/k9/backend/pop3/Pop3StoreUriCreatorTest.java @@ -1,4 +1,4 @@ -package com.fsck.k9.mail.store.pop3; +package com.fsck.k9.backend.pop3; import com.fsck.k9.mail.AuthType; diff --git a/mail/protocols/pop3/src/test/java/com/fsck/k9/mail/store/pop3/Pop3StoreUriDecoderTest.java b/backend/pop3/src/test/java/com/fsck/k9/backend/pop3/Pop3StoreUriDecoderTest.java similarity index 97% rename from mail/protocols/pop3/src/test/java/com/fsck/k9/mail/store/pop3/Pop3StoreUriDecoderTest.java rename to backend/pop3/src/test/java/com/fsck/k9/backend/pop3/Pop3StoreUriDecoderTest.java index dd0446b0d..61026e009 100644 --- a/mail/protocols/pop3/src/test/java/com/fsck/k9/mail/store/pop3/Pop3StoreUriDecoderTest.java +++ b/backend/pop3/src/test/java/com/fsck/k9/backend/pop3/Pop3StoreUriDecoderTest.java @@ -1,4 +1,4 @@ -package com.fsck.k9.mail.store.pop3; +package com.fsck.k9.backend.pop3; import com.fsck.k9.mail.ConnectionSecurity; diff --git a/mail/protocols/pop3/src/main/java/com/fsck/k9/mail/store/pop3/Pop3Store.java b/mail/protocols/pop3/src/main/java/com/fsck/k9/mail/store/pop3/Pop3Store.java index 9cc6f7d17..59e09be38 100644 --- a/mail/protocols/pop3/src/main/java/com/fsck/k9/mail/store/pop3/Pop3Store.java +++ b/mail/protocols/pop3/src/main/java/com/fsck/k9/mail/store/pop3/Pop3Store.java @@ -29,23 +29,16 @@ public class Pop3Store extends RemoteStore { private Map mFolders = new HashMap(); - public Pop3Store(StoreConfig storeConfig, TrustedSocketFactory socketFactory) throws MessagingException { + public Pop3Store(ServerSettings serverSettings, StoreConfig storeConfig, TrustedSocketFactory socketFactory) { super(storeConfig, socketFactory); - ServerSettings settings; - try { - settings = Pop3StoreUriDecoder.decode(storeConfig.getStoreUri()); - } catch (IllegalArgumentException e) { - throw new MessagingException("Error while decoding store URI", e); - } - - host = settings.host; - port = settings.port; - connectionSecurity = settings.connectionSecurity; - username = settings.username; - password = settings.password; - clientCertificateAlias = settings.clientCertificateAlias; - authType = settings.authenticationType; + host = serverSettings.host; + port = serverSettings.port; + connectionSecurity = serverSettings.connectionSecurity; + username = serverSettings.username; + password = serverSettings.password; + clientCertificateAlias = serverSettings.clientCertificateAlias; + authType = serverSettings.authenticationType; } @Override diff --git a/mail/protocols/pop3/src/test/java/com/fsck/k9/mail/store/pop3/Pop3StoreTest.java b/mail/protocols/pop3/src/test/java/com/fsck/k9/mail/store/pop3/Pop3StoreTest.java index 7e37562f8..73b051954 100644 --- a/mail/protocols/pop3/src/test/java/com/fsck/k9/mail/store/pop3/Pop3StoreTest.java +++ b/mail/protocols/pop3/src/test/java/com/fsck/k9/mail/store/pop3/Pop3StoreTest.java @@ -8,9 +8,13 @@ import java.io.OutputStream; import java.net.Socket; import java.util.List; +import com.fsck.k9.mail.AuthType; import com.fsck.k9.mail.AuthenticationFailedException; +import com.fsck.k9.mail.ConnectionSecurity; import com.fsck.k9.mail.Folder; import com.fsck.k9.mail.MessagingException; +import com.fsck.k9.mail.ServerSettings; +import com.fsck.k9.mail.ServerSettings.Type; import com.fsck.k9.mail.filter.Base64; import com.fsck.k9.mail.ssl.TrustedSocketFactory; import com.fsck.k9.mail.store.StoreConfig; @@ -60,21 +64,14 @@ public class Pop3StoreTest { @Before public void setUp() throws Exception { - //Using a SSL socket allows us to mock it - when(mockStoreConfig.getStoreUri()).thenReturn("pop3+ssl+://PLAIN:user:password@server:12345"); + ServerSettings serverSettings = createServerSettings(); when(mockStoreConfig.getInboxFolder()).thenReturn(Pop3Folder.INBOX); when(mockTrustedSocketFactory.createSocket(null, "server", 12345, null)).thenReturn(mockSocket); when(mockSocket.isConnected()).thenReturn(true); when(mockSocket.isClosed()).thenReturn(false); when(mockSocket.getOutputStream()).thenReturn(mockOutputStream); - store = new Pop3Store(mockStoreConfig, mockTrustedSocketFactory); - } - - @Test(expected = MessagingException.class) - public void withInvalidStoreUri_shouldThrowMessagingException() throws MessagingException { - when(mockStoreConfig.getStoreUri()).thenReturn("pop3://CRAM_MD5:user:password@[]:12345"); - store = new Pop3Store(mockStoreConfig, mockTrustedSocketFactory); + store = new Pop3Store(serverSettings, mockStoreConfig, mockTrustedSocketFactory); } @Test @@ -176,4 +173,16 @@ public class Pop3StoreTest { folder.open(Folder.OPEN_MODE_RW); } + + private ServerSettings createServerSettings() { + return new ServerSettings( + Type.POP3, + "server", + 12345, + ConnectionSecurity.SSL_TLS_REQUIRED, + AuthType.PLAIN, + "user", + "password", + null); + } }