]> granicus.if.org Git - curl/commitdiff
smtp_mail: Added support to MAIL FROM for the optional AUTH parameter
authorSteve Holme <steve_holme@hotmail.com>
Wed, 5 Oct 2011 21:22:29 +0000 (22:22 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 14 Feb 2012 21:50:49 +0000 (22:50 +0100)
Added a new CURLOPT_MAIL_AUTH option that allows the calling program to
set the optional AUTH parameter in the MAIL FROM command.

When this option is specified and an authentication mechanism is used
to communicate with the mail server then the AUTH parameter will be
included in the MAIL FROM command. This is particularly useful when the
calling program is acting as a relay in a trusted environment and
performing server to server communication, as it allows the relaying
server to specify the address of the mailbox that was used to
authenticate and send the original email.

include/curl/curl.h
lib/smtp.c
lib/url.c
lib/urldata.h

index 3c9c41d8a9bdcc336f1ef55a6bbe699528cb2f8c..f2501cd2b44f9c42b8183c8e6a1c08c6c787b9b7 100644 (file)
@@ -1518,6 +1518,9 @@ typedef enum {
   /* Enable/disable specific SSL features with a bitmask, see CURLSSLOPT_* */
   CINIT(SSL_OPTIONS, LONG, 216),
 
+  /* set the SMTP auth originator */
+  CINIT(MAIL_AUTH, OBJECTPOINT, 217),
+
   CURLOPT_LASTENTRY /* the last unused */
 } CURLoption;
 
index 95e71d75af7987c85b08002d695f2c2dcf6d0fb8..c02c9bdd469e67b4dae2809cce37aa2a21d1d2f9 100644 (file)
@@ -893,6 +893,7 @@ static CURLcode smtp_state_auth_resp(struct connectdata *conn,
 static CURLcode smtp_mail(struct connectdata *conn)
 {
   char *from = NULL;
+  char *auth = NULL;
   char *size = NULL;
   CURLcode result = CURLE_OK;
   struct SessionHandle *data = conn->data;
@@ -909,26 +910,49 @@ static CURLcode smtp_mail(struct connectdata *conn)
   if(!from)
     return CURLE_OUT_OF_MEMORY;
 
+  /* calculate the optional AUTH parameter */
+  if(data->set.str[STRING_MAIL_AUTH] && conn->proto.smtpc.authused) {
+    if(data->set.str[STRING_MAIL_AUTH][0] == '<')
+      auth = aprintf("%s", data->set.str[STRING_MAIL_AUTH]);
+    else
+      auth = aprintf("<%s>", data->set.str[STRING_MAIL_AUTH]);
+
+    if(!auth) {
+      Curl_safefree(from);
+
+      return CURLE_OUT_OF_MEMORY;
+    }
+  }
+
   /* calculate the optional SIZE parameter */
   if(conn->data->set.infilesize > 0) {
     size = aprintf("%" FORMAT_OFF_T, data->set.infilesize);
 
     if(!size) {
       Curl_safefree(from);
+      Curl_safefree(auth);
 
       return CURLE_OUT_OF_MEMORY;
     }
   }
 
   /* send MAIL FROM */
-  if(!size)
-    result = Curl_pp_sendf(&conn->proto.smtpc.pp, "MAIL FROM:%s", from);
+  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 SIZE=%s", from, size);
 
-  Curl_safefree(size);
   Curl_safefree(from);
+  Curl_safefree(auth);
+  Curl_safefree(size);
 
   if(result)
     return result;
@@ -1308,7 +1332,7 @@ static CURLcode smtp_connect(struct connectdata *conn,
   pp->conn = conn;
 
   if(!*path) {
-    if(!Curl_gethostname(localhost, sizeof localhost))
+    if(!Curl_gethostname(localhost, sizeof(localhost)))
       path = localhost;
     else
       path = "localhost";
index 277078ebf11a2c51fea2ae569dc2148157c1ea79..c4e84550f05a2eccfcce6fa387ef51ec0e575d55 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -2402,6 +2402,11 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
                        va_arg(param, char *));
     break;
 
+  case CURLOPT_MAIL_AUTH:
+    result = setstropt(&data->set.str[STRING_MAIL_AUTH],
+                       va_arg(param, char *));
+    break;
+
   case CURLOPT_MAIL_RCPT:
     /* get a list of mail recipients */
     data->set.mail_rcpt = va_arg(param, struct curl_slist *);
index 0463006c65fe7886c13e730f2f56e7100377ad49..1f3853dc73453f05b542b063b4d7e1690e911ebc 100644 (file)
@@ -1335,6 +1335,7 @@ enum dupstring {
   STRING_SOCKS5_GSSAPI_SERVICE,  /* GSSAPI service name */
 #endif
   STRING_MAIL_FROM,
+  STRING_MAIL_AUTH,
 
 #ifdef USE_TLS_SRP
   STRING_TLSAUTH_USERNAME,     /* TLS auth <username> */