Search in sources :

Example 1 with WebDavStore

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;
}
Also used : Pop3Store(com.fsck.k9.mail.store.pop3.Pop3Store) DefaultTrustedSocketFactory(com.fsck.k9.mail.ssl.DefaultTrustedSocketFactory) MessagingException(com.fsck.k9.mail.MessagingException) OAuth2TokenProvider(com.fsck.k9.mail.oauth.OAuth2TokenProvider) ConnectivityManager(android.net.ConnectivityManager) Pop3Store(com.fsck.k9.mail.store.pop3.Pop3Store) Store(com.fsck.k9.mail.Store) WebDavStore(com.fsck.k9.mail.store.webdav.WebDavStore) ImapStore(com.fsck.k9.mail.store.imap.ImapStore) ImapStore(com.fsck.k9.mail.store.imap.ImapStore) WebDavStore(com.fsck.k9.mail.store.webdav.WebDavStore)

Example 2 with WebDavStore

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);
}
Also used : ConnectionSecurity(com.fsck.k9.mail.ConnectionSecurity) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 3 with WebDavStore

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());
}
Also used : StoreConfig(com.fsck.k9.mail.store.StoreConfig) Test(org.junit.Test)

Example 4 with WebDavStore

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);
}
Also used : Folder(com.fsck.k9.mail.Folder) Test(org.junit.Test)

Example 5 with WebDavStore

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());
}
Also used : StoreConfig(com.fsck.k9.mail.store.StoreConfig) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 StoreConfig (com.fsck.k9.mail.store.StoreConfig)5 Folder (com.fsck.k9.mail.Folder)2 ConnectivityManager (android.net.ConnectivityManager)1 ConnectionSecurity (com.fsck.k9.mail.ConnectionSecurity)1 MessagingException (com.fsck.k9.mail.MessagingException)1 Store (com.fsck.k9.mail.Store)1 OAuth2TokenProvider (com.fsck.k9.mail.oauth.OAuth2TokenProvider)1 DefaultTrustedSocketFactory (com.fsck.k9.mail.ssl.DefaultTrustedSocketFactory)1 ImapStore (com.fsck.k9.mail.store.imap.ImapStore)1 Pop3Store (com.fsck.k9.mail.store.pop3.Pop3Store)1 WebDavStore (com.fsck.k9.mail.store.webdav.WebDavStore)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1