]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
imap: Added processing of more than one response when sent in same packet
authorJiri Hruska <jirka@fud.cz>
Wed, 27 Feb 2013 18:49:00 +0000 (19:49 +0100)
committerSteve Holme <steve_holme@hotmail.com>
Wed, 27 Feb 2013 20:08:04 +0000 (20:08 +0000)
Added a loop to imap_statemach_act() in which Curl_pp_readresp() is
called until the cache is drained. Without this multiple responses
received in a single packet could result in a hang or delay.

lib/imap.c

index 247d37779799631b627c18c921b8739b260c644b..37fbc453f9854bfa09d40325e095f058389751f5 100644 (file)
@@ -1351,16 +1351,19 @@ static CURLcode imap_statemach_act(struct connectdata *conn)
   if(pp->sendleft)
     return Curl_pp_flushsend(pp);
 
-  /* Read the response from the server */
-  result = Curl_pp_readresp(sock, pp, &imapcode, &nread);
-  if(result)
-    return result;
+  do {
+    /* Read the response from the server */
+    result = Curl_pp_readresp(sock, pp, &imapcode, &nread);
+    if(result)
+      return result;
 
-  /* Was there an error parsing the response line? */
-  if(imapcode == -1)
-    return CURLE_FTP_WEIRD_SERVER_REPLY;
+    /* Was there an error parsing the response line? */
+    if(imapcode == -1)
+      return CURLE_FTP_WEIRD_SERVER_REPLY;
+
+    if(!imapcode)
+      break;
 
-  if(imapcode) {
     /* We have now received a full IMAP server response */
     switch(imapc->state) {
     case IMAP_SERVERGREET:
@@ -1436,7 +1439,7 @@ static CURLcode imap_statemach_act(struct connectdata *conn)
       state(conn, IMAP_STOP);
       break;
     }
-  }
+  } while(!result && imapc->state != IMAP_STOP && Curl_pp_moredata(pp));
 
   return result;
 }