From 5dd689ad500fc8453c0e50cf590d110c2c777996 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= <git@myname.nl>
Date: Tue, 12 Apr 2011 15:51:25 +0200
Subject: [PATCH] Add --mail-ehlo to set ehlo hostname.

---
 include/curl/curl.h          |    3 +++
 include/curl/typecheck-gcc.h |    1 +
 lib/smtp.c                   |    7 ++++++-
 lib/url.c                    |    5 +++++
 lib/urldata.h                |    1 +
 src/main.c                   |   11 +++++++++++
 6 files changed, 27 insertions(+), 1 deletions(-)

diff --git a/include/curl/curl.h b/include/curl/curl.h
index 1a7ba76..583489c 100644
--- a/include/curl/curl.h
+++ b/include/curl/curl.h
@@ -1462,6 +1462,9 @@ typedef enum {
   /* Set authentication type for authenticated TLS */
   CINIT(TLSAUTH_TYPE, OBJECTPOINT, 206),
 
+  /* Set EHLO hostname for SMTP */
+  CINIT(MAIL_EHLO, OBJECTPOINT, 207),
+
   CURLOPT_LASTENTRY /* the last unused */
 } CURLoption;
 
diff --git a/include/curl/typecheck-gcc.h b/include/curl/typecheck-gcc.h
index e6f74a9..df972e4 100644
--- a/include/curl/typecheck-gcc.h
+++ b/include/curl/typecheck-gcc.h
@@ -259,6 +259,7 @@ _CURL_WARNING(_curl_easy_getinfo_err_curl_slist,
    (option) == CURLOPT_RTSP_SESSION_ID ||                                     \
    (option) == CURLOPT_RTSP_STREAM_URI ||                                     \
    (option) == CURLOPT_RTSP_TRANSPORT ||                                      \
+   (option) == CURLOPT_MAIL_EHLO ||                                           \
    0)
 
 /* evaluates to true if option takes a curl_write_callback argument */
diff --git a/lib/smtp.c b/lib/smtp.c
index 1680a82..4925d6a 100644
--- a/lib/smtp.c
+++ b/lib/smtp.c
@@ -316,11 +316,16 @@ static CURLcode smtp_state_ehlo(struct connectdata *conn)
 {
   CURLcode result;
   struct smtp_conn *smtpc = &conn->proto.smtpc;
+  struct SessionHandle *data = conn->data;
 
   smtpc->authmechs = 0;         /* No known authentication mechanisms yet. */
 
   /* send EHLO */
-  result = Curl_pp_sendf(&smtpc->pp, "EHLO %s", smtpc->domain);
+  if (strlen(data->set.str[STRING_MAIL_EHLO]) > 0) {
+    result = Curl_pp_sendf(&smtpc->pp, "EHLO %s", data->set.str[STRING_MAIL_EHLO]);
+  } else {
+    result = Curl_pp_sendf(&smtpc->pp, "EHLO %s", smtpc->domain);
+  }
 
   if(result)
     return result;
diff --git a/lib/url.c b/lib/url.c
index c7fcdfe..bb72f53 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -2363,6 +2363,11 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
     result = setstropt(&data->set.str[STRING_MAIL_FROM],
                        va_arg(param, char *));
     break;
+  
+  case CURLOPT_MAIL_EHLO:
+    result = setstropt(&data->set.str[STRING_MAIL_EHLO],
+                       va_arg(param, char *));
+    break;
 
   case CURLOPT_MAIL_RCPT:
     /* get a list of mail recipients */
diff --git a/lib/urldata.h b/lib/urldata.h
index d1718a9..b4afe91 100644
--- a/lib/urldata.h
+++ b/lib/urldata.h
@@ -1317,6 +1317,7 @@ enum dupstring {
   STRING_SOCKS5_GSSAPI_SERVICE,  /* GSSAPI service name */
 #endif
   STRING_MAIL_FROM,
+  STRING_MAIL_EHLO,
 
 #ifdef USE_TLS_SRP
   STRING_TLSAUTH_USERNAME,     /* TLS auth <username> */
diff --git a/src/main.c b/src/main.c
index 307070f..bcab7f5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -511,6 +511,7 @@ struct Configurable {
   int proxyver;     /* set to CURLPROXY_HTTP* define */
   char *noproxy;
   char *mail_from;
+  char *mail_ehlo;
   struct curl_slist *mail_rcpt;
   bool proxytunnel;
   bool ftp_append;         /* APPE on ftp */
@@ -837,6 +838,7 @@ static void help(void)
     " -M/--manual        Display the full manual",
     "    --mail-from <from> Mail from this address",
     "    --mail-rcpt <to> Mail to this receiver(s)",
+    "    --mail-ehlo <hostname> EHLO hostname",
     "    --max-filesize <bytes> Maximum file size to download (H/F)",
     "    --max-redirs <num> Maximum number of redirects allowed (H)",
     " -m/--max-time <seconds> Maximum time allowed for the transfer",
@@ -1899,6 +1901,7 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */
     {"$D", "proto",      TRUE},
     {"$E", "proto-redir", TRUE},
     {"$F", "resolve",    TRUE},
+    {"$G", "mail-ehlo",  TRUE},
     {"0", "http1.0",     FALSE},
     {"1", "tlsv1",       FALSE},
     {"2", "sslv2",       FALSE},
@@ -2469,6 +2472,9 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */
         if(err)
           return err;
         break;
+      case 'G': /* --mail-ehlo */
+        GetStr(&config->mail_ehlo, nextarg);
+        break;
       }
       break;
     case '#': /* --progress-bar */
@@ -4091,6 +4097,8 @@ static void free_config_fields(struct Configurable *config)
     free(config->hostpubmd5);
   if(config->mail_from)
     free(config->mail_from);
+  if(config->mail_ehlo)
+    free(config->mail_ehlo);
 #ifdef USE_TLS_SRP
   if(config->tls_authtype)
     free(config->tls_authtype);
@@ -5520,6 +5528,9 @@ operate(struct Configurable *config, int argc, argv_item_t argv[])
         curl_easy_setopt(curl, CURLOPT_TLSAUTH_USERNAME, config->tls_username);
         curl_easy_setopt(curl, CURLOPT_TLSAUTH_PASSWORD, config->tls_password);
 
+	if(config->mail_ehlo)
+	  my_setopt_str(curl, CURLOPT_MAIL_EHLO, config->mail_ehlo);
+
         retry_numretries = config->req_retry;
 
         retrystart = cutil_tvnow();
-- 
1.7.1

