Index: lib/smtp.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/smtp.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -p -r1.10 -r1.11
--- lib/smtp.c	25 Jan 2010 23:41:02 -0000	1.10
+++ lib/smtp.c	12 Feb 2010 22:23:47 -0000	1.11
@@ -20,7 +20,7 @@
  *
  * RFC2821 SMTP protocol
  *
- * $Id: smtp.c,v 1.10 2010-01-25 23:41:02 yangtse Exp $
+ * $Id: smtp.c,v 1.11 2010-02-12 22:23:47 bagder Exp $
  ***************************************************************************/
 
 #include "setup.h"
@@ -344,27 +344,18 @@ static CURLcode smtp_state_mail_resp(str
     state(conn, SMTP_STOP);
   }
   else {
+    struct smtp_conn *smtpc = &conn->proto.smtpc;
+
     /* send RCPT TO */
-    struct curl_slist *rcpt;
-    char *buffer = NULL;
+    smtpc->rcpt = data->set.mail_rcpt;
 
-    for(rcpt = data->set.mail_rcpt; rcpt; rcpt=rcpt->next) {
-      char *add = aprintf("%s%s%s", buffer?buffer:"", buffer?", ":"",
-                          rcpt->data);
-      if(!add) {
-        free(buffer);
-        return CURLE_OUT_OF_MEMORY;
-      }
-      buffer = add;
+    if(smtpc->rcpt) {
+      result = Curl_pp_sendf(&conn->proto.smtpc.pp, "RCPT TO:%s",
+                             smtpc->rcpt->data);
+      if(result)
+        return result;
     }
 
-    result = Curl_pp_sendf(&conn->proto.smtpc.pp, "RCPT TO:%s", buffer);
-
-    free(buffer);
-
-    if(result)
-      return result;
-
     state(conn, SMTP_RCPT);
   }
   return result;
@@ -385,6 +376,20 @@ static CURLcode smtp_state_rcpt_resp(str
     state(conn, SMTP_STOP);
   }
   else {
+    struct smtp_conn *smtpc = &conn->proto.smtpc;
+
+    /* one RCPT is done, but if there's one more to send go on */
+    smtpc->rcpt = smtpc->rcpt->next;
+    if(smtpc->rcpt) {
+      result = Curl_pp_sendf(&conn->proto.smtpc.pp, "RCPT TO:%s",
+                             smtpc->rcpt->data);
+      if(result)
+        return result;
+
+      state(conn, SMTP_RCPT);
+      return CURLE_OK;
+    }
+
     /* send DATA */
     result = Curl_pp_sendf(&conn->proto.smtpc.pp, "DATA", "");
     if(result)
Index: lib/smtp.h
===================================================================
RCS file: /cvsroot/curl/curl/lib/smtp.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -p -r1.4 -r1.5
--- lib/smtp.h	30 Dec 2009 22:50:42 -0000	1.4
+++ lib/smtp.h	12 Feb 2010 22:23:47 -0000	1.5
@@ -7,7 +7,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 2009, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 2009 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -20,7 +20,7 @@
  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  * KIND, either express or implied.
  *
- * $Id: smtp.h,v 1.4 2009-12-30 22:50:42 bagder Exp $
+ * $Id: smtp.h,v 1.5 2010-02-12 22:23:47 bagder Exp $
  ***************************************************************************/
 
 #include "pingpong.h"
@@ -49,6 +49,7 @@ struct smtp_conn {
   int eob;         /* number of bytes of the EOB (End Of Body) that has been
                       received thus far */
   smtpstate state; /* always use smtp.c:state() to change state! */
+  struct curl_slist *rcpt;
 };
 
 extern const struct Curl_handler Curl_handler_smtp;
