Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 152e0a05 authored by cketti's avatar cketti
Browse files

Revert ImapStore URI change

Reverts changes introduced with commit 8194c20f
Adds test to make sure usernames/passwords with special characters encode/decode properly.
parent 703c007f
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -159,10 +159,11 @@ public class ImapStore extends RemoteStore {
            port = imapUri.getPort();
        }

        final String userInfo = imapUri.getRawUserInfo();
        if (userInfo != null) {
            String[] userInfoParts = userInfo.split(":");
            if (userInfo.endsWith(":")) {
        if (imapUri.getUserInfo() != null) {
            String userinfo = imapUri.getUserInfo();
            String[] userInfoParts = userinfo.split(":");

            if (userinfo.endsWith(":")) {
                // Password is empty. This can only happen after an account was imported.
                authenticationType = AuthType.valueOf(userInfoParts[0]);
                username = decodeUtf8(userInfoParts[1]);
+14 −11
Original line number Diff line number Diff line
@@ -85,17 +85,6 @@ public class ImapStoreUriTest {
        assertNull(settings.getExtra().get("pathPrefix"));
    }

    @Test
    public void testDecodeStoreUriWithColonsInUsernameAndPassword() {
        String uri = "imap://PLAIN:a%3Auser:password%3Ahas%3Acolons@foo.com:993";
        ServerSettings settings = RemoteStore.decodeStoreUri(uri);
        assertEquals(AuthType.PLAIN, settings.authenticationType);
        assertEquals("a:user", settings.username);
        assertEquals("password:has:colons", settings.password);
        assertEquals("foo.com", settings.host);
        assertEquals(993, settings.port);
    }

    @Test
    public void testCreateStoreUriImapPrefix() {
        Map<String, String> extra = new HashMap<String, String>();
@@ -146,4 +135,18 @@ public class ImapStoreUriTest {

        assertEquals("imap://PLAIN:user:pass@server:143/1%7C", uri);
    }

    @Test
    public void testCreateDecodeStoreUriWithSpecialCharactersInUsernameAndPassword() {
        ServerSettings settings = new ServerSettings(ImapStore.STORE_TYPE, "server", 143,
                ConnectionSecurity.NONE, AuthType.PLAIN, "user@doma:n", "p@ssw:rd%", null, null);

        String uri = RemoteStore.createStoreUri(settings);

        assertEquals("imap://PLAIN:user%2540doma%253An:p%2540ssw%253Ard%2525@server:143/1%7C", uri);

        ServerSettings outSettings = RemoteStore.decodeStoreUri(uri);
        assertEquals("user@doma:n", outSettings.username);
        assertEquals("p@ssw:rd%", outSettings.password);
    }
}