use of com.fsck.k9.mail.store.webdav.WebDavStore in project k-9 by k9mail.
the class RemoteStore method getInstance.
/**
* Get an instance of a remote mail store.
*/
public static synchronized Store getInstance(Context context, StoreConfig storeConfig) throws MessagingException {
String uri = storeConfig.getStoreUri();
if (uri.startsWith("local")) {
throw new RuntimeException("Asked to get non-local Store object but given LocalStore URI");
}
Store store = sStores.get(uri);
if (store == null) {
if (uri.startsWith("imap")) {
OAuth2TokenProvider oAuth2TokenProvider = null;
store = new ImapStore(storeConfig, new DefaultTrustedSocketFactory(context), (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE), oAuth2TokenProvider);
} else if (uri.startsWith("pop3")) {
store = new Pop3Store(storeConfig, new DefaultTrustedSocketFactory(context));
} else if (uri.startsWith("webdav")) {
store = new WebDavStore(storeConfig, new WebDavHttpClient.WebDavHttpClientFactory());
}
if (store != null) {
sStores.put(uri, store);
}
}
if (store == null) {
throw new MessagingException("Unable to locate an applicable Store for " + uri);
}
return store;
}
use of com.fsck.k9.mail.store.webdav.WebDavStore in project k-9 by k9mail.
the class WebDavStoreUriDecoder method decode.
/**
* Decodes a WebDavStore URI.
* <p/>
* <p>Possible forms:</p>
* <pre>
* webdav://user:password@server:port ConnectionSecurity.NONE
* webdav+ssl+://user:password@server:port ConnectionSecurity.SSL_TLS_REQUIRED
* </pre>
*/
public static WebDavStoreSettings decode(String uri) {
String host;
int port;
ConnectionSecurity connectionSecurity;
String username = null;
String password = null;
String alias = null;
String path = null;
String authPath = null;
String mailboxPath = null;
URI webDavUri;
try {
webDavUri = new URI(uri);
} catch (URISyntaxException use) {
throw new IllegalArgumentException("Invalid WebDavStore URI", use);
}
String scheme = webDavUri.getScheme();
/*
* Currently available schemes are:
* webdav
* webdav+ssl+
*
* The following are obsolete schemes that may be found in pre-existing
* settings from earlier versions or that may be found when imported. We
* continue to recognize them and re-map them appropriately:
* webdav+tls
* webdav+tls+
* webdav+ssl
*/
if (scheme.equals("webdav")) {
connectionSecurity = ConnectionSecurity.NONE;
} else if (scheme.startsWith("webdav+")) {
connectionSecurity = ConnectionSecurity.SSL_TLS_REQUIRED;
} else {
throw new IllegalArgumentException("Unsupported protocol (" + scheme + ")");
}
host = webDavUri.getHost();
if (host.startsWith("http")) {
String[] hostParts = host.split("://", 2);
if (hostParts.length > 1) {
host = hostParts[1];
}
}
port = webDavUri.getPort();
String userInfo = webDavUri.getUserInfo();
if (userInfo != null) {
String[] userInfoParts = userInfo.split(":");
username = decodeUtf8(userInfoParts[0]);
String[] userParts = username.split("\\\\", 2);
if (userParts.length > 1) {
alias = userParts[1];
} else {
alias = username;
}
if (userInfoParts.length > 1) {
password = decodeUtf8(userInfoParts[1]);
}
}
String[] pathParts = webDavUri.getPath().split("\\|");
for (int i = 0, count = pathParts.length; i < count; i++) {
if (i == 0) {
if (pathParts[0] != null && pathParts[0].length() > 1) {
path = pathParts[0];
}
} else if (i == 1) {
if (pathParts[1] != null && pathParts[1].length() > 1) {
authPath = pathParts[1];
}
} else if (i == 2) {
if (pathParts[2] != null && pathParts[2].length() > 1) {
mailboxPath = pathParts[2];
}
}
}
return new WebDavStoreSettings(host, port, connectionSecurity, null, username, password, null, alias, path, authPath, mailboxPath);
}
use of com.fsck.k9.mail.store.webdav.WebDavStore in project k-9 by k9mail.
the class WebDavStoreTest method getPersonalNamespaces_shouldProvideListOfAllFoldersSentFromResponses.
@Test
public void getPersonalNamespaces_shouldProvideListOfAllFoldersSentFromResponses() throws Exception {
StoreConfig storeConfig = createStoreConfig("webdav://user:password@example.org:80");
WebDavStore webDavStore = new WebDavStore(storeConfig, mockHttpClientFactory);
configureHttpResponses(UNAUTHORIZED_401_RESPONSE, OK_200_RESPONSE, createOkPropfindResponse(), createOkSearchResponse());
List<? extends Folder> folders = webDavStore.getPersonalNamespaces(true);
List<HttpGeneric> requests = requestCaptor.getAllValues();
assertEquals(3, folders.size());
}
use of com.fsck.k9.mail.store.webdav.WebDavStore in project k-9 by k9mail.
the class WebDavStoreTest method getFolder_calledTwice_shouldReturnFirstInstance.
@Test
public void getFolder_calledTwice_shouldReturnFirstInstance() throws Exception {
WebDavStore webDavStore = createDefaultWebDavStore();
String folderName = "Trash";
Folder webDavFolder = webDavStore.getFolder(folderName);
Folder result = webDavStore.getFolder(folderName);
assertSame(webDavFolder, result);
}
use of com.fsck.k9.mail.store.webdav.WebDavStore in project k-9 by k9mail.
the class WebDavStoreTest method getPersonalNamespaces_shouldRequestSpecialFolders.
@Test
public void getPersonalNamespaces_shouldRequestSpecialFolders() throws Exception {
StoreConfig storeConfig = createStoreConfig("webdav://user:password@example.org:80");
WebDavStore webDavStore = new WebDavStore(storeConfig, mockHttpClientFactory);
configureHttpResponses(UNAUTHORIZED_401_RESPONSE, OK_200_RESPONSE, createOkPropfindResponse(), createOkSearchResponse());
webDavStore.getPersonalNamespaces(true);
List<HttpGeneric> requests = requestCaptor.getAllValues();
// AUTH + 2
assertEquals(4, requests.size());
//Special Folders
assertEquals("PROPFIND", requests.get(2).getMethod());
}
Aggregations