From dd8cd33c5aebc930c17ba3ad09eef6ea0a2fe1d6 Mon Sep 17 00:00:00 2001 From: cketti Date: Tue, 18 Oct 2011 05:05:40 +0200 Subject: [PATCH] Fixed decoding of store URIs with empty passwords --- src/com/fsck/k9/mail/store/ImapStore.java | 10 ++++++++-- src/com/fsck/k9/mail/store/Pop3Store.java | 7 +++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/com/fsck/k9/mail/store/ImapStore.java b/src/com/fsck/k9/mail/store/ImapStore.java index e1af45a78..b88d84f76 100644 --- a/src/com/fsck/k9/mail/store/ImapStore.java +++ b/src/com/fsck/k9/mail/store/ImapStore.java @@ -191,8 +191,14 @@ public class ImapStore extends Store { if (imapUri.getUserInfo() != null) { try { - String[] userInfoParts = imapUri.getUserInfo().split(":"); - if (userInfoParts.length == 2) { + 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]).name(); + username = URLDecoder.decode(userInfoParts[1], "UTF-8"); + } else if (userInfoParts.length == 2) { authenticationType = AuthType.PLAIN.name(); username = URLDecoder.decode(userInfoParts[0], "UTF-8"); password = URLDecoder.decode(userInfoParts[1], "UTF-8"); diff --git a/src/com/fsck/k9/mail/store/Pop3Store.java b/src/com/fsck/k9/mail/store/Pop3Store.java index 8144124fc..4b11cdf83 100644 --- a/src/com/fsck/k9/mail/store/Pop3Store.java +++ b/src/com/fsck/k9/mail/store/Pop3Store.java @@ -115,8 +115,11 @@ public class Pop3Store extends Store { if (pop3Uri.getUserInfo() != null) { try { int userIndex = 0, passwordIndex = 1; - String[] userInfoParts = pop3Uri.getUserInfo().split(":"); - if (userInfoParts.length > 2) { + String userinfo = pop3Uri.getUserInfo(); + String[] userInfoParts = userinfo.split(":"); + if (userInfoParts.length > 2 || userinfo.endsWith(":") ) { + // If 'userinfo' ends with ":" the password is empty. This can only happen + // after an account was imported (so authType and username are present). userIndex++; passwordIndex++; authType = userInfoParts[0];