Create DraftsFolderProvider

This commit is contained in:
cketti 2020-05-01 05:38:37 +02:00
parent 82db38bd08
commit 02049c5882
7 changed files with 37 additions and 37 deletions

View file

@ -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 {

View file

@ -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 {

View file

@ -0,0 +1,5 @@
package com.fsck.k9.mail.store.webdav;
public interface DraftsFolderProvider {
String getDraftsFolder();
}

View file

@ -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<String, WebDavFolder> 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<Message> messages) throws MessagingException {
WebDavFolder tmpFolder = getFolder(storeConfig.getDraftsFolder());
WebDavFolder tmpFolder = getFolder(draftsFolderProvider.getDraftsFolder());
try {
tmpFolder.open();
List<WebDavMessage> retMessages = tmpFolder.appendWebDavMessages(messages);

View file

@ -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");

View file

@ -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<Map<String, String>> 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);

View file

@ -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<HttpGeneric> 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 {