diff --git a/src/com/android/email/mail/store/ImapStore.java b/src/com/android/email/mail/store/ImapStore.java index a85ae0453..2004531f6 100644 --- a/src/com/android/email/mail/store/ImapStore.java +++ b/src/com/android/email/mail/store/ImapStore.java @@ -1203,6 +1203,8 @@ public class ImapStore extends Store { if (isOpen()) { return; } + + boolean authSuccess = false; mNextCommandTag = 1; try @@ -1277,7 +1279,8 @@ public class ImapStore extends Store { try { // TODO eventually we need to add additional authentication // options such as SASL - executeSimpleCommand("LOGIN " + mUsername + " " + mPassword, true); + executeSimpleCommand("LOGIN \"" + mUsername + "\" \"" + mPassword + "\"", true); + authSuccess = true; } catch (ImapException ie) { throw new AuthenticationFailedException(ie.getAlertText(), ie); @@ -1304,6 +1307,14 @@ public class ImapStore extends Store { throw ce; } } + finally + { + if (authSuccess == false) + { + Log.e(Email.LOG_TAG, "Failed to login, closing connection"); + close(); + } + } } public boolean isOpen() {