From f00512207e0ceeff7ba0df728a749c3270d7378c Mon Sep 17 00:00:00 2001
From: William Betts <william@phpbakery.com>
Date: Wed, 17 Nov 2010 18:55:04 -0800
Subject: [PATCH] include/curl/curl.h: Added a CINIT call for MAIL_GREETING
 lib/smtp.c: In smtp_state_ehlo it checks to see if conn->data->set.str[STRING_MAIL_GREETING] is non empty. If it is use that for the HELO or EHLO otherwise use smtpc->domain
 lib/url.c: Added CURLOPT_MAIL_GREETING to switch statement in Curl_setopt. This is where the str[STRING_MAIL_GREETING] comes from.
 lib/urldata.c: Added STRING_MAIL_GREETING to the enum dupstring
 src/main.c: Add a variable to the Configurable struct to store the greeting.
 src/main.c: Add entry to free_config_fields function to free the variable
 src/main.c: Add a my_setopt call for CURLOPT_MAIL_GREETING

This is a patch that will add the opt command CURLOPT_MAIL_GREET and
allow the user to set the string sent for the HELO or EHLO.
---
 include/curl/curl.h |    1 +
 lib/smtp.c          |    8 +++++++-
 lib/url.c           |    5 +++++
 lib/urldata.h       |    1 +
 src/main.c          |    6 ++++++
 5 files changed, 20 insertions(+), 1 deletions(-)

diff --git a/include/curl/curl.h b/include/curl/curl.h
index fbd0d9b..61cd331 100644
--- a/include/curl/curl.h
+++ b/include/curl/curl.h
@@ -1442,6 +1442,7 @@ typedef enum {
   /* send linked-list of name:port:address sets */
   CINIT(RESOLVE, OBJECTPOINT, 203),
 
+  CINIT(MAIL_GREETING, OBJECTPOINT, 204),
   CURLOPT_LASTENTRY /* the last unused */
 } CURLoption;
 
diff --git a/lib/smtp.c b/lib/smtp.c
index 55e03d5..233e0cf 100644
--- a/lib/smtp.c
+++ b/lib/smtp.c
@@ -312,6 +312,9 @@ static CURLcode smtp_state_ehlo(struct connectdata *conn)
   smtpc->authmechs = 0;         /* No known authentication mechanisms yet. */
 
   /* send EHLO */
+  if(conn->data->set.str[STRING_MAIL_GREETING])
+    result = Curl_pp_sendf(&smtpc->pp, "EHLO %s", conn->data->set.str[STRING_MAIL_GREETING]);
+  else
   result = Curl_pp_sendf(&smtpc->pp, "EHLO %s", smtpc->domain);
 
   if(result)
@@ -327,7 +330,10 @@ static CURLcode smtp_state_helo(struct connectdata *conn)
   struct smtp_conn *smtpc = &conn->proto.smtpc;
 
   /* send HELO */
-  result = Curl_pp_sendf(&smtpc->pp, "HELO %s", smtpc->domain);
+  if(conn->data->set.str[STRING_MAIL_GREETING])
+    result = Curl_pp_sendf(&smtpc->pp, "HELO %s", conn->data->set.str[STRING_MAIL_GREETING]);
+  else
+    result = Curl_pp_sendf(&smtpc->pp, "HELO %s", smtpc->domain);
 
   if(result)
     return result;
diff --git a/lib/url.c b/lib/url.c
index e915c79..a157ff1 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -2385,6 +2385,11 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
     data->set.mail_rcpt = va_arg(param, struct curl_slist *);
     break;
 
+  case CURLOPT_MAIL_GREETING:
+    result = setstropt(&data->set.str[STRING_MAIL_GREETING],
+                       va_arg(param, char *));
+    break;
+
   case CURLOPT_RTSP_REQUEST:
     {
       /*
diff --git a/lib/urldata.h b/lib/urldata.h
index 93c2d40..f8ba736 100644
--- a/lib/urldata.h
+++ b/lib/urldata.h
@@ -1255,6 +1255,7 @@ enum dupstring {
   STRING_SOCKS5_GSSAPI_SERVICE,  /* GSSAPI service name */
 #endif
   STRING_MAIL_FROM,
+  STRING_MAIL_GREETING,
 
   /* -- end of strings -- */
   STRING_LAST /* not used, just an end-of-list marker */
diff --git a/src/main.c b/src/main.c
index 2f81ef4..afa8e71 100644
--- a/src/main.c
+++ b/src/main.c
@@ -508,6 +508,7 @@ struct Configurable {
   int proxyver;     /* set to CURLPROXY_HTTP* define */
   char *noproxy;
   char *mail_from;
+  char *mail_greeting;
   struct curl_slist *mail_rcpt;
   bool proxytunnel;
   bool ftp_append;         /* APPE on ftp */
@@ -4038,6 +4039,8 @@ static void free_config_fields(struct Configurable *config)
     free(config->hostpubmd5);
   if(config->mail_from)
     free(config->mail_from);
+  if(config->mail_greeting)
+    free(config->mail_greeting);
 #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
   if(config->socks5_gssapi_service)
     free(config->socks5_gssapi_service);
@@ -5430,6 +5433,9 @@ operate(struct Configurable *config, int argc, argv_item_t argv[])
         if(config->mail_rcpt)
           my_setopt(curl, CURLOPT_MAIL_RCPT, config->mail_rcpt);
 
+        if(config->mail_greeting)
+          my_setopt(curl, CURLOPT_MAIL_GREETING, config->mail_greeting);
+
         /* curl 7.20.x */
         if(config->ftp_pret)
           my_setopt(curl, CURLOPT_FTP_USE_PRET, TRUE);
-- 
1.5.4.3

