]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
smtp: Simplify the MAIL command and avoid a duplication of send strings
authorSteve Holme <steve_holme@hotmail.com>
Sun, 9 Feb 2020 15:50:57 +0000 (15:50 +0000)
committerSteve Holme <steve_holme@hotmail.com>
Sun, 9 Feb 2020 23:08:47 +0000 (23:08 +0000)
This avoids the duplication of strings when the optional AUTH and SIZE
parameters are required. It also assists with the modifications that
are part of #4892.

Closes #4903

lib/smtp.c

index 764a1b75ea19b9dbe2fb51f1c7db622938e89c15..7bcff0ce7bd5430953fa4009e02f93d5a343b62b 100644 (file)
@@ -584,18 +584,13 @@ static CURLcode smtp_perform_mail(struct connectdata *conn)
   }
 
   /* Send the MAIL command */
-  if(!auth && !size)
-    result = Curl_pp_sendf(&conn->proto.smtpc.pp,
-                           "MAIL FROM:%s", from);
-  else if(auth && !size)
-    result = Curl_pp_sendf(&conn->proto.smtpc.pp,
-                           "MAIL FROM:%s AUTH=%s", from, auth);
-  else if(auth && size)
-    result = Curl_pp_sendf(&conn->proto.smtpc.pp,
-                           "MAIL FROM:%s AUTH=%s SIZE=%s", from, auth, size);
-  else
-    result = Curl_pp_sendf(&conn->proto.smtpc.pp,
-                           "MAIL FROM:%s SIZE=%s", from, size);
+  result = Curl_pp_sendf(&conn->proto.smtpc.pp,
+                         "MAIL FROM:%s%s%s%s%s",
+                         from,                 /* Mandatory */
+                         auth ? " AUTH=" : "", /* Optional (on AUTH support) */
+                         auth ? auth : "",
+                         size ? " SIZE=" : "", /* Optional (on SIZE support) */
+                         size ? size : "");
 
   free(from);
   free(auth);