]> granicus.if.org Git - curl/commitdiff
imap: Moved the sending of the AUTHENICATE command into a separate function
authorSteve Holme <steve_holme@hotmail.com>
Wed, 18 Dec 2013 07:00:00 +0000 (07:00 +0000)
committerSteve Holme <steve_holme@hotmail.com>
Wed, 18 Dec 2013 00:10:39 +0000 (00:10 +0000)
lib/imap.c

index 547b7904f47a3201add4e5345faa818d6da259fb..23b020be45690082069053c95f8dea9028220994 100644 (file)
@@ -555,6 +555,38 @@ static CURLcode imap_perform_login(struct connectdata *conn)
   return result;
 }
 
+/***********************************************************************
+ *
+ * imap_perform_authenticate()
+ *
+ * Sends an AUTHENTICATE command allowing the client to login with the given
+ * SASL authentication mechanism.
+ */
+static CURLcode imap_perform_authenticate(struct connectdata *conn,
+                                          const char *mech,
+                                          const char *initresp,
+                                          imapstate state1, imapstate state2)
+{
+  CURLcode result = CURLE_OK;
+
+  if(initresp) {
+    /* Send the AUTHENTICATE command with the initial response */
+    result = imap_sendf(conn, "AUTHENTICATE %s %s", mech, initresp);
+
+    if(!result)
+      state(conn, state2);
+  }
+  else {
+    /* Send the AUTHENTICATE command */
+    result = imap_sendf(conn, "AUTHENTICATE %s", mech);
+
+    if(!result)
+      state(conn, state1);
+  }
+
+  return result;
+}
+
 /***********************************************************************
  *
  * imap_perform_authentication()
@@ -653,18 +685,7 @@ static CURLcode imap_perform_authentication(struct connectdata *conn)
   if(!result) {
     if(mech && (imapc->preftype & IMAP_TYPE_SASL)) {
       /* 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, state1);
-      }
+      result = imap_perform_authenticate(conn, mech, initresp, state1, state2);
 
       Curl_safefree(initresp);
     }