From 2778d834b49cb315091549a439178b794aad86a1 Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Wed, 12 Oct 2016 18:10:35 -0700 Subject: [PATCH] Handle presence of '--' delimiter in $sendmail. (closes #3168) 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 | 5 ++++- sendlib.c | 26 +++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/init.h b/init.h index 461bc6cd5..d6c8be68b 100644 --- a/init.h +++ b/init.h @@ -2987,7 +2987,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 }, /* diff --git a/sendlib.c b/sendlib.c index cbc546a6c..5441fa513 100644 --- a/sendlib.c +++ b/sendlib.c @@ -2404,6 +2404,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; #ifdef USE_NNTP @@ -2438,7 +2440,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); @@ -2457,6 +2463,21 @@ mutt_invoke_sendmail (ADDRESS *from, /* the sender */ if (!option (OPTNEWSSEND)) { #endif + /* 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"); @@ -2485,6 +2506,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); @@ -2501,7 +2524,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)); @@ -2521,6 +2544,7 @@ mutt_invoke_sendmail (ADDRESS *from, /* the sender */ FREE (&path); FREE (&s); FREE (&args); + FREE (&extra_args); if (i == (EX_OK & 0xff)) i = 0; -- 2.40.0