From 152e0a0530aa77654d1e10a420d0b62bd631567c Mon Sep 17 00:00:00 2001 From: cketti Date: Mon, 22 Dec 2014 18:23:52 +0100 Subject: [PATCH] Revert ImapStore URI change Reverts changes introduced with commit 8194c20ffeb31e2da304f3436b95f7291d013392 Adds test to make sure usernames/passwords with special characters encode/decode properly. --- .../fsck/k9/mail/store/imap/ImapStore.java | 9 ++++--- .../k9/mail/store/imap/ImapStoreUriTest.java | 25 +++++++++++-------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/k9mail-library/src/main/java/com/fsck/k9/mail/store/imap/ImapStore.java b/k9mail-library/src/main/java/com/fsck/k9/mail/store/imap/ImapStore.java index dfa7fbb75..f0959b4b0 100644 --- a/k9mail-library/src/main/java/com/fsck/k9/mail/store/imap/ImapStore.java +++ b/k9mail-library/src/main/java/com/fsck/k9/mail/store/imap/ImapStore.java @@ -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]); diff --git a/tests-on-jvm/src/test/java/com/fsck/k9/mail/store/imap/ImapStoreUriTest.java b/tests-on-jvm/src/test/java/com/fsck/k9/mail/store/imap/ImapStoreUriTest.java index 2e74e271b..f3f58a430 100644 --- a/tests-on-jvm/src/test/java/com/fsck/k9/mail/store/imap/ImapStoreUriTest.java +++ b/tests-on-jvm/src/test/java/com/fsck/k9/mail/store/imap/ImapStoreUriTest.java @@ -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 extra = new HashMap(); @@ -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); + } }