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();
}
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]);

View File

@ -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);
}
}