Make WebDavStore use ServerSettings directly
Instead of using WebDavStoreSettings as a ServerSettings subclass make it a helper to extract WebDav-specific settings.
This commit is contained in:
parent
42e180d6fa
commit
97051f3f7c
8 changed files with 69 additions and 73 deletions
|
@ -47,7 +47,6 @@ import com.fsck.k9.ui.R;
|
|||
import com.fsck.k9.view.ClientCertificateSpinner;
|
||||
import com.fsck.k9.view.ClientCertificateSpinner.OnClientCertificateChangedListener;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.android.material.textfield.TextInputEditText;
|
||||
|
@ -247,18 +246,19 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||
findViewById(R.id.compression_label).setVisibility(View.GONE);
|
||||
mSubscribedFoldersOnly.setVisibility(View.GONE);
|
||||
|
||||
WebDavStoreSettings webDavSettings = (WebDavStoreSettings) settings;
|
||||
|
||||
if (webDavSettings.path != null) {
|
||||
mWebdavPathPrefixView.setText(webDavSettings.path);
|
||||
String path = WebDavStoreSettings.getPath(settings);
|
||||
if (path != null) {
|
||||
mWebdavPathPrefixView.setText(path);
|
||||
}
|
||||
|
||||
if (webDavSettings.authPath != null) {
|
||||
mWebdavAuthPathView.setText(webDavSettings.authPath);
|
||||
String authPath = WebDavStoreSettings.getAuthPath(settings);
|
||||
if (authPath != null) {
|
||||
mWebdavAuthPathView.setText(authPath);
|
||||
}
|
||||
|
||||
if (webDavSettings.mailboxPath != null) {
|
||||
mWebdavMailboxPathView.setText(webDavSettings.mailboxPath);
|
||||
String mailboxPath = WebDavStoreSettings.getMailboxPath(settings);
|
||||
if (mailboxPath != null) {
|
||||
mWebdavMailboxPathView.setText(mailboxPath);
|
||||
}
|
||||
} else {
|
||||
throw new Exception("Unknown account type: " + mAccount.getStoreUri());
|
||||
|
@ -575,13 +575,10 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||
String pathPrefix = mImapPathPrefixView.getText().toString();
|
||||
extra = ImapStoreSettings.createExtra(autoDetectNamespace, pathPrefix);
|
||||
} else if (mStoreType.equals(Protocols.WEBDAV)) {
|
||||
extra = new HashMap<>();
|
||||
extra.put(WebDavStoreSettings.PATH_KEY,
|
||||
mWebdavPathPrefixView.getText().toString());
|
||||
extra.put(WebDavStoreSettings.AUTH_PATH_KEY,
|
||||
mWebdavAuthPathView.getText().toString());
|
||||
extra.put(WebDavStoreSettings.MAILBOX_PATH_KEY,
|
||||
mWebdavMailboxPathView.getText().toString());
|
||||
String path = mWebdavPathPrefixView.getText().toString();
|
||||
String authPath = mWebdavAuthPathView.getText().toString();
|
||||
String mailboxPath = mWebdavMailboxPathView.getText().toString();
|
||||
extra = WebDavStoreSettings.createExtra(null, path, authPath, mailboxPath);
|
||||
}
|
||||
|
||||
DI.get(LocalKeyStoreManager.class).deleteCertificate(mAccount, host, port, MailServerDirection.INCOMING);
|
||||
|
|
|
@ -38,11 +38,11 @@ public class WebDavStoreUriCreator {
|
|||
String uriPath;
|
||||
Map<String, String> extra = server.getExtra();
|
||||
if (extra != null) {
|
||||
String path = extra.get(WebDavStoreSettings.PATH_KEY);
|
||||
String path = WebDavStoreSettings.getPath(server);
|
||||
path = (path != null) ? path : "";
|
||||
String authPath = extra.get(WebDavStoreSettings.AUTH_PATH_KEY);
|
||||
String authPath = WebDavStoreSettings.getAuthPath(server);
|
||||
authPath = (authPath != null) ? authPath : "";
|
||||
String mailboxPath = extra.get(WebDavStoreSettings.MAILBOX_PATH_KEY);
|
||||
String mailboxPath = WebDavStoreSettings.getMailboxPath(server);
|
||||
mailboxPath = (mailboxPath != null) ? mailboxPath : "";
|
||||
uriPath = "/" + path + "|" + authPath + "|" + mailboxPath;
|
||||
} else {
|
||||
|
|
|
@ -2,10 +2,12 @@ package com.fsck.k9.backend.webdav;
|
|||
|
||||
|
||||
import com.fsck.k9.mail.ConnectionSecurity;
|
||||
import com.fsck.k9.mail.ServerSettings;
|
||||
import com.fsck.k9.mail.store.webdav.WebDavStoreSettings;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.fsck.k9.mail.helper.UrlEncodingHelper.decodeUtf8;
|
||||
|
||||
|
@ -20,7 +22,7 @@ public class WebDavStoreUriDecoder {
|
|||
* webdav+ssl+://user:password@server:port ConnectionSecurity.SSL_TLS_REQUIRED
|
||||
* </pre>
|
||||
*/
|
||||
public static WebDavStoreSettings decode(String uri) {
|
||||
public static ServerSettings decode(String uri) {
|
||||
String host;
|
||||
int port;
|
||||
ConnectionSecurity connectionSecurity;
|
||||
|
@ -106,7 +108,8 @@ public class WebDavStoreUriDecoder {
|
|||
}
|
||||
}
|
||||
|
||||
return new WebDavStoreSettings(host, port, connectionSecurity, null, username, password,
|
||||
null, alias, path, authPath, mailboxPath);
|
||||
Map<String, String> extra = WebDavStoreSettings.createExtra(alias, path, authPath, mailboxPath);
|
||||
|
||||
return new ServerSettings("webdav", host, port, connectionSecurity, null, username, password, null, extra);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -171,12 +171,6 @@ public class ServerSettings {
|
|||
return extra;
|
||||
}
|
||||
|
||||
protected void putIfNotNull(Map<String, String> map, String key, String value) {
|
||||
if (value != null) {
|
||||
map.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
public ServerSettings newPassword(String newPassword) {
|
||||
return new ServerSettings(type, host, port, connectionSecurity, authenticationType,
|
||||
username, newPassword, clientCertificateAlias);
|
||||
|
|
|
@ -22,6 +22,7 @@ import com.fsck.k9.mail.FolderType;
|
|||
import com.fsck.k9.mail.K9MailLib;
|
||||
import com.fsck.k9.mail.Message;
|
||||
import com.fsck.k9.mail.MessagingException;
|
||||
import com.fsck.k9.mail.ServerSettings;
|
||||
import com.fsck.k9.mail.filter.Base64;
|
||||
import com.fsck.k9.mail.ssl.TrustManagerFactory;
|
||||
import com.fsck.k9.mail.store.webdav.WebDavHttpClient.WebDavHttpClientFactory;
|
||||
|
@ -83,12 +84,12 @@ public class WebDavStore {
|
|||
private WebDavFolder sendFolder = null;
|
||||
private Map<String, WebDavFolder> folderList = new HashMap<>();
|
||||
|
||||
public WebDavStore(TrustManagerFactory trustManagerFactory, WebDavStoreSettings serverSettings,
|
||||
public WebDavStore(TrustManagerFactory trustManagerFactory, ServerSettings serverSettings,
|
||||
DraftsFolderProvider draftsFolderProvider) {
|
||||
this(trustManagerFactory, serverSettings, draftsFolderProvider, new WebDavHttpClient.WebDavHttpClientFactory());
|
||||
}
|
||||
|
||||
public WebDavStore(TrustManagerFactory trustManagerFactory, WebDavStoreSettings serverSettings,
|
||||
public WebDavStore(TrustManagerFactory trustManagerFactory, ServerSettings serverSettings,
|
||||
DraftsFolderProvider draftsFolderProvider, WebDavHttpClientFactory clientFactory) {
|
||||
this.draftsFolderProvider = draftsFolderProvider;
|
||||
httpClientFactory = clientFactory;
|
||||
|
@ -101,11 +102,11 @@ public class WebDavStore {
|
|||
|
||||
username = serverSettings.username;
|
||||
password = serverSettings.password;
|
||||
alias = serverSettings.alias;
|
||||
alias = WebDavStoreSettings.getAlias(serverSettings);
|
||||
|
||||
path = serverSettings.path;
|
||||
formBasedAuthPath = serverSettings.authPath;
|
||||
mailboxPath = serverSettings.mailboxPath;
|
||||
path = WebDavStoreSettings.getPath(serverSettings);
|
||||
formBasedAuthPath = WebDavStoreSettings.getAuthPath(serverSettings);
|
||||
mailboxPath = WebDavStoreSettings.getMailboxPath(serverSettings);
|
||||
|
||||
|
||||
if (path == null || path.equals("")) {
|
||||
|
|
|
@ -4,38 +4,39 @@ package com.fsck.k9.mail.store.webdav;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fsck.k9.mail.AuthType;
|
||||
import com.fsck.k9.mail.ConnectionSecurity;
|
||||
import com.fsck.k9.mail.ServerSettings;
|
||||
|
||||
|
||||
/**
|
||||
* This class is used to store the decoded contents of an WebDavStore URI.
|
||||
* Extract WebDav-specific server settings from {@link ServerSettings}.
|
||||
*/
|
||||
public class WebDavStoreSettings extends ServerSettings {
|
||||
public static final String ALIAS_KEY = "alias";
|
||||
public static final String PATH_KEY = "path";
|
||||
public static final String AUTH_PATH_KEY = "authPath";
|
||||
public static final String MAILBOX_PATH_KEY = "mailboxPath";
|
||||
public class WebDavStoreSettings {
|
||||
private static final String ALIAS_KEY = "alias";
|
||||
private static final String PATH_KEY = "path";
|
||||
private static final String AUTH_PATH_KEY = "authPath";
|
||||
private static final String MAILBOX_PATH_KEY = "mailboxPath";
|
||||
|
||||
public final String alias;
|
||||
public final String path;
|
||||
public final String authPath;
|
||||
public final String mailboxPath;
|
||||
|
||||
public WebDavStoreSettings(String host, int port, ConnectionSecurity connectionSecurity,
|
||||
AuthType authenticationType, String username, String password, String clientCertificateAlias, String alias,
|
||||
String path, String authPath, String mailboxPath) {
|
||||
super("webdav", host, port, connectionSecurity, authenticationType, username,
|
||||
password, clientCertificateAlias);
|
||||
this.alias = alias;
|
||||
this.path = path;
|
||||
this.authPath = authPath;
|
||||
this.mailboxPath = mailboxPath;
|
||||
public static String getAlias(ServerSettings serverSettings) {
|
||||
Map<String, String> extra = serverSettings.getExtra();
|
||||
return extra == null ? null : extra.get(ALIAS_KEY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getExtra() {
|
||||
public static String getPath(ServerSettings serverSettings) {
|
||||
Map<String, String> extra = serverSettings.getExtra();
|
||||
return extra == null ? null : extra.get(PATH_KEY);
|
||||
}
|
||||
|
||||
public static String getAuthPath(ServerSettings serverSettings) {
|
||||
Map<String, String> extra = serverSettings.getExtra();
|
||||
return extra == null ? null : extra.get(AUTH_PATH_KEY);
|
||||
}
|
||||
|
||||
public static String getMailboxPath(ServerSettings serverSettings) {
|
||||
Map<String, String> extra = serverSettings.getExtra();
|
||||
return extra == null ? null : extra.get(MAILBOX_PATH_KEY);
|
||||
}
|
||||
|
||||
public static Map<String, String> createExtra(String alias, String path, String authPath, String mailboxPath) {
|
||||
Map<String, String> extra = new HashMap<>();
|
||||
putIfNotNull(extra, ALIAS_KEY, alias);
|
||||
putIfNotNull(extra, PATH_KEY, path);
|
||||
|
@ -44,9 +45,9 @@ public class WebDavStoreSettings extends ServerSettings {
|
|||
return extra;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerSettings newPassword(String newPassword) {
|
||||
return new WebDavStoreSettings(host, port, connectionSecurity, authenticationType,
|
||||
username, newPassword, clientCertificateAlias, alias, path, authPath, mailboxPath);
|
||||
private static void putIfNotNull(Map<String, String> map, String key, String value) {
|
||||
if (value != null) {
|
||||
map.put(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,17 +6,17 @@ import java.util.Collections;
|
|||
import com.fsck.k9.mail.K9MailLib;
|
||||
import com.fsck.k9.mail.Message;
|
||||
import com.fsck.k9.mail.MessagingException;
|
||||
import com.fsck.k9.mail.ServerSettings;
|
||||
import com.fsck.k9.mail.Transport;
|
||||
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 timber.log.Timber;
|
||||
|
||||
public class WebDavTransport extends Transport {
|
||||
private WebDavStore store;
|
||||
|
||||
public WebDavTransport(TrustManagerFactory trustManagerFactory, WebDavStoreSettings serverSettings,
|
||||
public WebDavTransport(TrustManagerFactory trustManagerFactory, ServerSettings serverSettings,
|
||||
DraftsFolderProvider draftsFolderProvider) {
|
||||
store = new WebDavStore(trustManagerFactory, serverSettings, draftsFolderProvider);
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import com.fsck.k9.mail.ConnectionSecurity;
|
|||
import com.fsck.k9.mail.FolderType;
|
||||
import com.fsck.k9.mail.K9LibRobolectricTestRunner;
|
||||
import com.fsck.k9.mail.MessagingException;
|
||||
import com.fsck.k9.mail.ServerSettings;
|
||||
import com.fsck.k9.mail.filter.Base64;
|
||||
import com.fsck.k9.mail.ssl.TrustManagerFactory;
|
||||
|
||||
|
@ -73,7 +74,7 @@ public class WebDavStoreTest {
|
|||
|
||||
private ArgumentCaptor<HttpGeneric> requestCaptor;
|
||||
|
||||
private WebDavStoreSettings serverSettings;
|
||||
private ServerSettings serverSettings;
|
||||
private WebDavStore webDavStore;
|
||||
|
||||
|
||||
|
@ -87,7 +88,7 @@ public class WebDavStoreTest {
|
|||
when(mockHttpClient.getConnectionManager()).thenReturn(mockClientConnectionManager);
|
||||
when(mockClientConnectionManager.getSchemeRegistry()).thenReturn(mockSchemeRegistry);
|
||||
|
||||
serverSettings = createWebDavStoreSettings(ConnectionSecurity.SSL_TLS_REQUIRED);
|
||||
serverSettings = createServerSettings(ConnectionSecurity.SSL_TLS_REQUIRED);
|
||||
webDavStore = createWebDavStore();
|
||||
}
|
||||
|
||||
|
@ -336,8 +337,10 @@ public class WebDavStoreTest {
|
|||
};
|
||||
}
|
||||
|
||||
private WebDavStoreSettings createWebDavStoreSettings(ConnectionSecurity connectionSecurity) {
|
||||
return new WebDavStoreSettings(
|
||||
private ServerSettings createServerSettings(ConnectionSecurity connectionSecurity) {
|
||||
Map<String, String> extra = WebDavStoreSettings.createExtra(null, null, null, null);
|
||||
return new ServerSettings(
|
||||
"webdav",
|
||||
"webdav.example.org",
|
||||
443,
|
||||
connectionSecurity,
|
||||
|
@ -345,10 +348,7 @@ public class WebDavStoreTest {
|
|||
"user",
|
||||
"password",
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null);
|
||||
extra);
|
||||
}
|
||||
|
||||
private WebDavStore createWebDavStore() {
|
||||
|
@ -356,7 +356,7 @@ public class WebDavStoreTest {
|
|||
}
|
||||
|
||||
private WebDavStore createWebDavStore(ConnectionSecurity connectionSecurity) {
|
||||
WebDavStoreSettings serverSettings = createWebDavStoreSettings(connectionSecurity);
|
||||
ServerSettings serverSettings = createServerSettings(connectionSecurity);
|
||||
return new WebDavStore(trustManagerFactory, serverSettings, draftsFolderProvider, mockHttpClientFactory);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue