From 02049c5882674e888110c47e9ad19e37ebe45581 Mon Sep 17 00:00:00 2001 From: cketti Date: Fri, 1 May 2020 05:38:37 +0200 Subject: [PATCH] Create DraftsFolderProvider --- .../fsck/k9/backends/WebDavBackendFactory.kt | 13 +++++++----- .../fsck/k9/backends/WebDavBackendFactory.kt | 13 +++++++----- .../store/webdav/DraftsFolderProvider.java | 5 +++++ .../k9/mail/store/webdav/WebDavStore.java | 20 ++++++++----------- .../k9/mail/transport/WebDavTransport.java | 7 ++++--- .../mail/store/webdav/WebDavFolderTest.java | 8 -------- .../k9/mail/store/webdav/WebDavStoreTest.java | 8 ++++---- 7 files changed, 37 insertions(+), 37 deletions(-) create mode 100644 mail/protocols/webdav/src/main/java/com/fsck/k9/mail/store/webdav/DraftsFolderProvider.java diff --git a/app/k9mail-jmap/src/main/java/com/fsck/k9/backends/WebDavBackendFactory.kt b/app/k9mail-jmap/src/main/java/com/fsck/k9/backends/WebDavBackendFactory.kt index 88e5d132a..a7bf31176 100644 --- a/app/k9mail-jmap/src/main/java/com/fsck/k9/backends/WebDavBackendFactory.kt +++ b/app/k9mail-jmap/src/main/java/com/fsck/k9/backends/WebDavBackendFactory.kt @@ -8,8 +8,8 @@ import com.fsck.k9.backend.webdav.WebDavStoreUriCreator import com.fsck.k9.backend.webdav.WebDavStoreUriDecoder import com.fsck.k9.mail.ServerSettings import com.fsck.k9.mail.ssl.TrustManagerFactory +import com.fsck.k9.mail.store.webdav.DraftsFolderProvider import com.fsck.k9.mail.store.webdav.WebDavStore -import com.fsck.k9.mail.store.webdav.WebDavStoreSettings import com.fsck.k9.mail.transport.WebDavTransport import com.fsck.k9.mailstore.K9BackendStorageFactory @@ -23,13 +23,16 @@ class WebDavBackendFactory( val accountName = account.displayName val backendStorage = backendStorageFactory.createBackendStorage(account) val serverSettings = WebDavStoreUriDecoder.decode(account.storeUri) - val webDavStore = createWebDavStore(serverSettings, account) - val webDavTransport = WebDavTransport(trustManagerFactory, serverSettings, account) + val draftsFolderProvider = createDraftsFolderProvider(account) + val webDavStore = WebDavStore(trustManagerFactory, serverSettings, draftsFolderProvider) + val webDavTransport = WebDavTransport(trustManagerFactory, serverSettings, draftsFolderProvider) return WebDavBackend(accountName, backendStorage, webDavStore, webDavTransport) } - private fun createWebDavStore(serverSettings: WebDavStoreSettings, account: Account): WebDavStore { - return WebDavStore(trustManagerFactory, serverSettings, account) + private fun createDraftsFolderProvider(account: Account): DraftsFolderProvider { + return DraftsFolderProvider { + account.draftsFolder ?: error("No Drafts folder configured") + } } override fun decodeStoreUri(storeUri: String): ServerSettings { diff --git a/app/k9mail/src/main/java/com/fsck/k9/backends/WebDavBackendFactory.kt b/app/k9mail/src/main/java/com/fsck/k9/backends/WebDavBackendFactory.kt index 88e5d132a..a7bf31176 100644 --- a/app/k9mail/src/main/java/com/fsck/k9/backends/WebDavBackendFactory.kt +++ b/app/k9mail/src/main/java/com/fsck/k9/backends/WebDavBackendFactory.kt @@ -8,8 +8,8 @@ import com.fsck.k9.backend.webdav.WebDavStoreUriCreator import com.fsck.k9.backend.webdav.WebDavStoreUriDecoder import com.fsck.k9.mail.ServerSettings import com.fsck.k9.mail.ssl.TrustManagerFactory +import com.fsck.k9.mail.store.webdav.DraftsFolderProvider import com.fsck.k9.mail.store.webdav.WebDavStore -import com.fsck.k9.mail.store.webdav.WebDavStoreSettings import com.fsck.k9.mail.transport.WebDavTransport import com.fsck.k9.mailstore.K9BackendStorageFactory @@ -23,13 +23,16 @@ class WebDavBackendFactory( val accountName = account.displayName val backendStorage = backendStorageFactory.createBackendStorage(account) val serverSettings = WebDavStoreUriDecoder.decode(account.storeUri) - val webDavStore = createWebDavStore(serverSettings, account) - val webDavTransport = WebDavTransport(trustManagerFactory, serverSettings, account) + val draftsFolderProvider = createDraftsFolderProvider(account) + val webDavStore = WebDavStore(trustManagerFactory, serverSettings, draftsFolderProvider) + val webDavTransport = WebDavTransport(trustManagerFactory, serverSettings, draftsFolderProvider) return WebDavBackend(accountName, backendStorage, webDavStore, webDavTransport) } - private fun createWebDavStore(serverSettings: WebDavStoreSettings, account: Account): WebDavStore { - return WebDavStore(trustManagerFactory, serverSettings, account) + private fun createDraftsFolderProvider(account: Account): DraftsFolderProvider { + return DraftsFolderProvider { + account.draftsFolder ?: error("No Drafts folder configured") + } } override fun decodeStoreUri(storeUri: String): ServerSettings { diff --git a/mail/protocols/webdav/src/main/java/com/fsck/k9/mail/store/webdav/DraftsFolderProvider.java b/mail/protocols/webdav/src/main/java/com/fsck/k9/mail/store/webdav/DraftsFolderProvider.java new file mode 100644 index 000000000..62eb93aaa --- /dev/null +++ b/mail/protocols/webdav/src/main/java/com/fsck/k9/mail/store/webdav/DraftsFolderProvider.java @@ -0,0 +1,5 @@ +package com.fsck.k9.mail.store.webdav; + +public interface DraftsFolderProvider { + String getDraftsFolder(); +} diff --git a/mail/protocols/webdav/src/main/java/com/fsck/k9/mail/store/webdav/WebDavStore.java b/mail/protocols/webdav/src/main/java/com/fsck/k9/mail/store/webdav/WebDavStore.java index b7f287894..13faa53fc 100644 --- a/mail/protocols/webdav/src/main/java/com/fsck/k9/mail/store/webdav/WebDavStore.java +++ b/mail/protocols/webdav/src/main/java/com/fsck/k9/mail/store/webdav/WebDavStore.java @@ -24,7 +24,6 @@ import com.fsck.k9.mail.Message; import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mail.filter.Base64; import com.fsck.k9.mail.ssl.TrustManagerFactory; -import com.fsck.k9.mail.store.StoreConfig; import com.fsck.k9.mail.store.webdav.WebDavHttpClient.WebDavHttpClientFactory; import javax.net.ssl.SSLException; import javax.xml.parsers.ParserConfigurationException; @@ -60,7 +59,7 @@ import static com.fsck.k9.mail.helper.UrlEncodingHelper.decodeUtf8; */ @SuppressWarnings("deprecation") public class WebDavStore { - private final StoreConfig storeConfig; + private final DraftsFolderProvider draftsFolderProvider; private ConnectionSecurity mConnectionSecurity; private String username; private String alias; @@ -84,13 +83,14 @@ public class WebDavStore { private WebDavFolder sendFolder = null; private Map folderList = new HashMap<>(); - public WebDavStore(TrustManagerFactory trustManagerFactory, WebDavStoreSettings serverSettings, StoreConfig storeConfig) { - this(trustManagerFactory, serverSettings, storeConfig, new WebDavHttpClient.WebDavHttpClientFactory()); + public WebDavStore(TrustManagerFactory trustManagerFactory, WebDavStoreSettings serverSettings, + DraftsFolderProvider draftsFolderProvider) { + this(trustManagerFactory, serverSettings, draftsFolderProvider, new WebDavHttpClient.WebDavHttpClientFactory()); } - public WebDavStore(TrustManagerFactory trustManagerFactory, WebDavStoreSettings serverSettings, StoreConfig storeConfig, - WebDavHttpClientFactory clientFactory) { - this.storeConfig = storeConfig; + public WebDavStore(TrustManagerFactory trustManagerFactory, WebDavStoreSettings serverSettings, + DraftsFolderProvider draftsFolderProvider, WebDavHttpClientFactory clientFactory) { + this.draftsFolderProvider = draftsFolderProvider; httpClientFactory = clientFactory; this.trustManagerFactory = trustManagerFactory; @@ -152,10 +152,6 @@ public class WebDavStore { return authenticationType; } - StoreConfig getStoreConfig() { - return storeConfig; - } - public void checkSettings() throws MessagingException { authenticate(); } @@ -935,7 +931,7 @@ public class WebDavStore { } public void sendMessages(List messages) throws MessagingException { - WebDavFolder tmpFolder = getFolder(storeConfig.getDraftsFolder()); + WebDavFolder tmpFolder = getFolder(draftsFolderProvider.getDraftsFolder()); try { tmpFolder.open(); List retMessages = tmpFolder.appendWebDavMessages(messages); diff --git a/mail/protocols/webdav/src/main/java/com/fsck/k9/mail/transport/WebDavTransport.java b/mail/protocols/webdav/src/main/java/com/fsck/k9/mail/transport/WebDavTransport.java index 7c24c322f..40b28410e 100644 --- a/mail/protocols/webdav/src/main/java/com/fsck/k9/mail/transport/WebDavTransport.java +++ b/mail/protocols/webdav/src/main/java/com/fsck/k9/mail/transport/WebDavTransport.java @@ -8,7 +8,7 @@ import com.fsck.k9.mail.Message; import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mail.Transport; import com.fsck.k9.mail.ssl.TrustManagerFactory; -import com.fsck.k9.mail.store.StoreConfig; +import com.fsck.k9.mail.store.webdav.DraftsFolderProvider; import com.fsck.k9.mail.store.webdav.WebDavStore; import com.fsck.k9.mail.store.webdav.WebDavStoreSettings; import timber.log.Timber; @@ -16,8 +16,9 @@ import timber.log.Timber; public class WebDavTransport extends Transport { private WebDavStore store; - public WebDavTransport(TrustManagerFactory trustManagerFactory, WebDavStoreSettings serverSettings, StoreConfig storeConfig) { - store = new WebDavStore(trustManagerFactory, serverSettings, storeConfig); + public WebDavTransport(TrustManagerFactory trustManagerFactory, WebDavStoreSettings serverSettings, + DraftsFolderProvider draftsFolderProvider) { + store = new WebDavStore(trustManagerFactory, serverSettings, draftsFolderProvider); if (K9MailLib.isDebug()) Timber.d(">>> New WebDavTransport creation complete"); diff --git a/mail/protocols/webdav/src/test/java/com/fsck/k9/mail/store/webdav/WebDavFolderTest.java b/mail/protocols/webdav/src/test/java/com/fsck/k9/mail/store/webdav/WebDavFolderTest.java index 8fbb3ca55..339501a3d 100644 --- a/mail/protocols/webdav/src/test/java/com/fsck/k9/mail/store/webdav/WebDavFolderTest.java +++ b/mail/protocols/webdav/src/test/java/com/fsck/k9/mail/store/webdav/WebDavFolderTest.java @@ -16,7 +16,6 @@ import com.fsck.k9.mail.Message; import com.fsck.k9.mail.MessageRetrievalListener; import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mail.internet.BinaryTempFileBody; -import com.fsck.k9.mail.store.StoreConfig; import org.apache.http.HttpResponse; import org.apache.http.StatusLine; import org.apache.http.client.methods.HttpUriRequest; @@ -62,12 +61,6 @@ public class WebDavFolderTest { private DataSet mockDataSet; @Mock private WebDavHttpClient mockHttpClient; - @Mock - private StoreConfig mockStoreConfig; - @Mock - private HttpResponse mockHttpResponse; - @Mock - private StatusLine mockStatusLine; @Captor private ArgumentCaptor> headerCaptor; @Captor @@ -89,7 +82,6 @@ public class WebDavFolderTest { MockitoAnnotations.initMocks(this); when(mockStore.getUrl()).thenReturn(storeUrl); when(mockStore.getHttpClient()).thenReturn(mockHttpClient); - when(mockStore.getStoreConfig()).thenReturn(mockStoreConfig); when(mockStore.getMessageEnvelopeXml(any(String[].class))).thenReturn("mockEnvelopeXml"); when(mockStore.getMessageFlagsXml(any(String[].class))).thenReturn("mockFlagsXml"); folder = new WebDavFolder(mockStore, folderName); diff --git a/mail/protocols/webdav/src/test/java/com/fsck/k9/mail/store/webdav/WebDavStoreTest.java b/mail/protocols/webdav/src/test/java/com/fsck/k9/mail/store/webdav/WebDavStoreTest.java index 2152cc704..e9f8af677 100644 --- a/mail/protocols/webdav/src/test/java/com/fsck/k9/mail/store/webdav/WebDavStoreTest.java +++ b/mail/protocols/webdav/src/test/java/com/fsck/k9/mail/store/webdav/WebDavStoreTest.java @@ -16,7 +16,7 @@ import com.fsck.k9.mail.K9LibRobolectricTestRunner; import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mail.filter.Base64; import com.fsck.k9.mail.ssl.TrustManagerFactory; -import com.fsck.k9.mail.store.StoreConfig; + import javax.net.ssl.SSLException; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; @@ -69,7 +69,7 @@ public class WebDavStoreTest { @Mock private TrustManagerFactory trustManagerFactory; @Mock - private StoreConfig storeConfig; + private DraftsFolderProvider draftsFolderProvider; private ArgumentCaptor requestCaptor; @@ -352,12 +352,12 @@ public class WebDavStoreTest { } private WebDavStore createWebDavStore() { - return new WebDavStore(trustManagerFactory, serverSettings, storeConfig, mockHttpClientFactory); + return new WebDavStore(trustManagerFactory, serverSettings, draftsFolderProvider, mockHttpClientFactory); } private WebDavStore createWebDavStore(ConnectionSecurity connectionSecurity) { WebDavStoreSettings serverSettings = createWebDavStoreSettings(connectionSecurity); - return new WebDavStore(trustManagerFactory, serverSettings, storeConfig, mockHttpClientFactory); + return new WebDavStore(trustManagerFactory, serverSettings, draftsFolderProvider, mockHttpClientFactory); } private void configureHttpResponses(HttpResponse... responses) throws IOException {