1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 11:42:16 -05:00

Revert ImapStore URI change

Reverts changes introduced with commit 8194c20ffe
Adds test to make sure usernames/passwords with special characters encode/decode properly.
This commit is contained in:
cketti 2014-12-22 18:23:52 +01:00
parent 703c007fc8
commit 152e0a0530
2 changed files with 19 additions and 15 deletions

View File

@ -159,10 +159,11 @@ public class ImapStore extends RemoteStore {
port = imapUri.getPort(); port = imapUri.getPort();
} }
final String userInfo = imapUri.getRawUserInfo(); if (imapUri.getUserInfo() != null) {
if (userInfo != null) { String userinfo = imapUri.getUserInfo();
String[] userInfoParts = userInfo.split(":"); String[] userInfoParts = userinfo.split(":");
if (userInfo.endsWith(":")) {
if (userinfo.endsWith(":")) {
// Password is empty. This can only happen after an account was imported. // Password is empty. This can only happen after an account was imported.
authenticationType = AuthType.valueOf(userInfoParts[0]); authenticationType = AuthType.valueOf(userInfoParts[0]);
username = decodeUtf8(userInfoParts[1]); username = decodeUtf8(userInfoParts[1]);

View File

@ -85,17 +85,6 @@ public class ImapStoreUriTest {
assertNull(settings.getExtra().get("pathPrefix")); 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 @Test
public void testCreateStoreUriImapPrefix() { public void testCreateStoreUriImapPrefix() {
Map<String, String> extra = new HashMap<String, String>(); 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); 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);
}
} }