]> granicus.if.org Git - mutt/commitdiff
Handle presence of '--' delimiter in $sendmail. (closes #3168)
authorKevin McCarthy <kevin@8t8.us>
Thu, 13 Oct 2016 01:10:35 +0000 (18:10 -0700)
committerKevin McCarthy <kevin@8t8.us>
Thu, 13 Oct 2016 01:10:35 +0000 (18:10 -0700)
If the delimiter exists, additional sendmail flags will be inserted
before the delimiter.  Any arguments after the delimiter will be
preserved as recipients.

init.h
sendlib.c

diff --git a/init.h b/init.h
index ae3ccaaa90dac15af7cf4301d932c6b363e450ec..782cf8ea4fea9a9cb0884656de368306d156a115 100644 (file)
--- a/init.h
+++ b/init.h
@@ -2673,7 +2673,10 @@ struct option_t MuttVars[] = {
   ** .pp
   ** Specifies the program and arguments used to deliver mail sent by Mutt.
   ** Mutt expects that the specified program interprets additional
-  ** arguments as recipient addresses.
+  ** arguments as recipient addresses.  Mutt appends all recipients after
+  ** adding a \fC--\fP delimiter (if not already present).  Additional
+  ** flags, such as for $$use_8bitmime, $$use_envelope_from,
+  ** $$dsn_notify, or $$dsn_return will be added before the delimiter.
   */
   { "sendmail_wait",   DT_NUM,  R_NONE, UL &SendmailWait, 0 },
   /*
index 771eae2d6287488f5b26a5f26faef41325215988..625af34386f9fa77c772215fb43068df9887335c 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -2352,6 +2352,8 @@ mutt_invoke_sendmail (ADDRESS *from,      /* the sender */
   char *ps = NULL, *path = NULL, *s = safe_strdup (Sendmail), *childout = NULL;
   char **args = NULL;
   size_t argslen = 0, argsmax = 0;
+  char **extra_args = NULL;
+  size_t extra_argslen = 0, extra_argsmax = 0;
   int i;
 
   /* ensure that $sendmail is set to avoid a crash. http://dev.mutt.org/trac/ticket/3548 */
@@ -2369,7 +2371,11 @@ mutt_invoke_sendmail (ADDRESS *from,     /* the sender */
       safe_realloc (&args, sizeof (char *) * (argsmax += 5));
 
     if (i)
+    {
+      if (!mutt_strcmp (ps, "--"))
+        break;
       args[argslen++] = ps;
+    }
     else
     {
       path = safe_strdup (ps);
@@ -2384,6 +2390,21 @@ mutt_invoke_sendmail (ADDRESS *from,     /* the sender */
     i++;
   }
 
+  /* If Sendmail contained a "--", we save the recipients to append to
+   * args after other possible options added below. */
+  if (ps)
+  {
+    ps = NULL;
+    while ((ps = strtok (ps, " ")))
+    {
+      if (extra_argslen == extra_argsmax)
+        safe_realloc (&extra_args, sizeof (char *) * (extra_argsmax += 5));
+
+      extra_args[extra_argslen++] = ps;
+      ps = NULL;
+    }
+  }
+
   if (eightbit && option (OPTUSE8BITMIME))
     args = add_option (args, &argslen, &argsmax, "-B8BITMIME");
 
@@ -2412,6 +2433,8 @@ mutt_invoke_sendmail (ADDRESS *from,      /* the sender */
     args = add_option (args, &argslen, &argsmax, DsnReturn);
   }
   args = add_option (args, &argslen, &argsmax, "--");
+  for (i = 0; i < extra_argslen; i++)
+    args = add_option (args, &argslen, &argsmax, extra_args[i]);
   args = add_args (args, &argslen, &argsmax, to);
   args = add_args (args, &argslen, &argsmax, cc);
   args = add_args (args, &argslen, &argsmax, bcc);
@@ -2425,7 +2448,7 @@ mutt_invoke_sendmail (ADDRESS *from,      /* the sender */
   {
     if (i != S_BKG)
     {
-      const char *e = mutt_strsysexit (i);
+      const char *e;
 
       e = mutt_strsysexit (i);
       mutt_error (_("Error sending message, child exited %d (%s)."), i, NONULL (e));
@@ -2445,6 +2468,7 @@ mutt_invoke_sendmail (ADDRESS *from,      /* the sender */
   FREE (&path);
   FREE (&s);
   FREE (&args);
+  FREE (&extra_args);
 
   if (i == (EX_OK & 0xff))
     i = 0;