diff --git a/lib/imap.c b/lib/imap.c
index 6bdd5c1ae46a5b554cace711b9459087346e49f9..b13bd3da745479caa9e435dc6370e713026820fc 100644
--- a/lib/imap.c
+++ b/lib/imap.c
@@ -596,33 +596,32 @@ static CURLcode imap_perform_authenticate(struct connectdata *conn)
                                               conn->passwd, &initresp, &len);
   }
 
-  if(result)
-    return result;
+  if(!result) {
+    if(mech) {
+      /* Perform SASL based authentication */
+      if(initresp) {
+        result = imap_sendf(conn, "AUTHENTICATE %s %s", mech, initresp);
 
-  if(mech) {
-    /* Perform SASL based authentication */
-    if(initresp) {
-      result = imap_sendf(conn, "AUTHENTICATE %s %s", mech, initresp);
+        if(!result)
+          state(conn, state2);
+      }
+      else {
+        result = imap_sendf(conn, "AUTHENTICATE %s", mech);
 
-      if(!result)
-        state(conn, state2);
+        if(!result)
+          state(conn, state1);
+      }
+
+      Curl_safefree(initresp);
     }
+    else if(!imapc->login_disabled)
+      /* Perform clear text authentication */
+      result = imap_perform_login(conn);
     else {
-      result = imap_sendf(conn, "AUTHENTICATE %s", mech);
-
-      if(!result)
-        state(conn, state1);
+      /* Other mechanisms not supported */
+      infof(conn->data, "No known authentication mechanisms supported!\n");
+      result = CURLE_LOGIN_DENIED;
     }
-
-    Curl_safefree(initresp);
-  }
-  else if(!imapc->login_disabled)
-    /* Perform clear text authentication */
-    result = imap_perform_login(conn);
-  else {
-    /* Other mechanisms not supported */
-    infof(conn->data, "No known authentication mechanisms supported!\n");
-    result = CURLE_LOGIN_DENIED;
   }
 
   return result;
diff --git a/lib/pop3.c b/lib/pop3.c
index bace72a11a2a55b6fe2dbd5496767c71b01f3f02..6f188b254b213526c82aace7e46002cec257606b 100644
--- a/lib/pop3.c
+++ b/lib/pop3.c
@@ -624,42 +624,40 @@ static CURLcode pop3_perform_authenticate(struct connectdata *conn)
     }
   }
 
-  if(result)
-    return result;
+  if(!result) {
+    if(mech && (pop3c->preftype & POP3_TYPE_SASL)) {
+      /* Perform SASL based authentication */
+      if(initresp &&
+         8 + strlen(mech) + len <= 255) { /* AUTH <mech> ...<crlf> */
+        result = Curl_pp_sendf(&pop3c->pp, "AUTH %s %s", mech, initresp);
 
-  if(mech && (pop3c->preftype & POP3_TYPE_SASL)) {
-    /* Perform SASL based authentication */
-    if(initresp &&
-       8 + strlen(mech) + len <= 255) { /* AUTH <mech> ...<crlf> */
-      result = Curl_pp_sendf(&pop3c->pp, "AUTH %s %s", mech, initresp);
+        if(!result)
+          state(conn, state2);
+      }
+      else {
+        result = Curl_pp_sendf(&pop3c->pp, "AUTH %s", mech);
 
-      if(!result)
-        state(conn, state2);
-    }
-    else {
-      /* Perform SASL based authentication */
-      result = Curl_pp_sendf(&pop3c->pp, "AUTH %s", mech);
+        if(!result)
+          state(conn, state1);
+      }
 
-      if(!result)
-        state(conn, state1);
+      Curl_safefree(initresp);
     }
-
-    Curl_safefree(initresp);
-  }
 #ifndef CURL_DISABLE_CRYPTO_AUTH
-  else if((pop3c->authtypes & POP3_TYPE_APOP) &&
-          (pop3c->preftype & POP3_TYPE_APOP))
-    /* Perform APOP authentication */
-    result = pop3_perform_apop(conn);
+    else if((pop3c->authtypes & POP3_TYPE_APOP) &&
+            (pop3c->preftype & POP3_TYPE_APOP))
+      /* Perform APOP authentication */
+      result = pop3_perform_apop(conn);
 #endif
-  else if((pop3c->authtypes & POP3_TYPE_CLEARTEXT) &&
-          (pop3c->preftype & POP3_TYPE_CLEARTEXT))
-    /* Perform clear text authentication */
-    result = pop3_perform_user(conn);
-  else {
-    /* Other mechanisms not supported */
-    infof(conn->data, "No known authentication mechanisms supported!\n");
-    result = CURLE_LOGIN_DENIED;
+    else if((pop3c->authtypes & POP3_TYPE_CLEARTEXT) &&
+            (pop3c->preftype & POP3_TYPE_CLEARTEXT))
+      /* Perform clear text authentication */
+      result = pop3_perform_user(conn);
+    else {
+      /* Other mechanisms not supported */
+      infof(conn->data, "No known authentication mechanisms supported!\n");
+      result = CURLE_LOGIN_DENIED;
+    }
   }
 
   return result;
diff --git a/lib/smtp.c b/lib/smtp.c
index 72b3bbf6ac61fb8e94fe03d2d4d26aba9bf01835..72a6135ffd19dcb955444d789d4ab3ef9f54544b 100644
--- a/lib/smtp.c
+++ b/lib/smtp.c
@@ -518,29 +518,31 @@ static CURLcode smtp_perform_authenticate(struct connectdata *conn)
       result = Curl_sasl_create_plain_message(conn->data, conn->user,
                                               conn->passwd, &initresp, &len);
   }
-  else {
-    /* Other mechanisms not supported */
-    infof(conn->data, "No known authentication mechanisms supported!\n");
-    result = CURLE_LOGIN_DENIED;
-  }
 
   if(!result) {
-    /* Perform SASL based authentication */
-    if(initresp &&
-       8 + strlen(mech) + len <= 512) { /* AUTH <mech> ...<crlf> */
-       result = Curl_pp_sendf(&smtpc->pp, "AUTH %s %s", mech, initresp);
+    if(mech) {
+      /* Perform SASL based authentication */
+      if(initresp &&
+         8 + strlen(mech) + len <= 512) { /* AUTH <mech> ...<crlf> */
+        result = Curl_pp_sendf(&smtpc->pp, "AUTH %s %s", mech, initresp);
 
-      if(!result)
-        state(conn, state2);
+        if(!result)
+          state(conn, state2);
+      }
+      else {
+        result = Curl_pp_sendf(&smtpc->pp, "AUTH %s", mech);
+
+        if(!result)
+          state(conn, state1);
+      }
+
+      Curl_safefree(initresp);
     }
     else {
-      result = Curl_pp_sendf(&smtpc->pp, "AUTH %s", mech);
-
-      if(!result)
-        state(conn, state1);
+      /* Other mechanisms not supported */
+      infof(conn->data, "No known authentication mechanisms supported!\n");
+      result = CURLE_LOGIN_DENIED;
     }
-
-    Curl_safefree(initresp);
   }
 
   return result;