From 156784cc2fda068885f55f5d2e37227a5f3c50eb Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Sat, 2 Nov 2013 20:12:41 -0700 Subject: [PATCH] Override draft headers with arguments. (closes #3580) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Currently, if the -H option is used, it is not possible to redefine the recipient addresses with positional argument. This patch fixes it as well as CC, Bcc, and Subject headers. This patch is based on the patch by Petr Písař at http://dev.mutt.org/trac/attachment/ticket/3580/override_draft_headers_with_arguments.patch This version of the patch merges the To, Cc, and Bcc commandline arguments into the template, and fixes a few small problems with the previous patch. This patch also moves the fin close outside the "if (tempfile)" block, since it is opened outside that block. --- main.c | 82 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 44 insertions(+), 38 deletions(-) diff --git a/main.c b/main.c index 204a5ca6..0d709f43 100644 --- a/main.c +++ b/main.c @@ -866,44 +866,40 @@ int main (int argc, char **argv) if (!msg) msg = mutt_new_header (); + if (!msg->env) + msg->env = mutt_new_envelope (); - if (draftFile) - infile = draftFile; - else + for (i = optind; i < argc; i++) { - if (!msg->env) - msg->env = mutt_new_envelope (); - - for (i = optind; i < argc; i++) + if (url_check_scheme (argv[i]) == U_MAILTO) { - if (url_check_scheme (argv[i]) == U_MAILTO) - { - if (url_parse_mailto (msg->env, &bodytext, argv[i]) < 0) - { - if (!option (OPTNOCURSES)) - mutt_endwin (NULL); - fputs (_("Failed to parse mailto: link\n"), stderr); - exit (1); - } - } - else - msg->env->to = rfc822_parse_adrlist (msg->env->to, argv[i]); + if (url_parse_mailto (msg->env, &bodytext, argv[i]) < 0) + { + if (!option (OPTNOCURSES)) + mutt_endwin (NULL); + fputs (_("Failed to parse mailto: link\n"), stderr); + exit (1); + } } + else + msg->env->to = rfc822_parse_adrlist (msg->env->to, argv[i]); + } - if (option (OPTAUTOEDIT) && !msg->env->to && !msg->env->cc) - { - if (!option (OPTNOCURSES)) - mutt_endwin (NULL); - fputs (_("No recipients specified.\n"), stderr); - exit (1); - } + if (!draftFile && option (OPTAUTOEDIT) && !msg->env->to && !msg->env->cc) + { + if (!option (OPTNOCURSES)) + mutt_endwin (NULL); + fputs (_("No recipients specified.\n"), stderr); + exit (1); + } - if (subject) - msg->env->subject = safe_strdup (subject); + if (subject) + msg->env->subject = safe_strdup (subject); - if (includeFile) - infile = includeFile; - } + if (draftFile) + infile = draftFile; + else if (includeFile) + infile = includeFile; if (infile || bodytext) { @@ -925,16 +921,25 @@ int main (int argc, char **argv) exit (1); } } + + if (draftFile) + { + ENVELOPE *opts_env = msg->env; + msg->env = mutt_read_rfc822_header (fin, NULL, 1, 0); + + rfc822_append (&msg->env->to, opts_env->to, 0); + rfc822_append (&msg->env->cc, opts_env->cc, 0); + rfc822_append (&msg->env->bcc, opts_env->bcc, 0); + if (opts_env->subject) + mutt_str_replace (&msg->env->subject, opts_env->subject); + + mutt_free_envelope (&opts_env); + } } - else - fin = NULL; mutt_mktemp (buf, sizeof (buf)); tempfile = safe_strdup (buf); - if (draftFile) - msg->env = mutt_read_rfc822_header (fin, NULL, 1, 0); - /* is the following if still needed? */ if (tempfile) @@ -955,9 +960,10 @@ int main (int argc, char **argv) else if (bodytext) fputs (bodytext, fout); safe_fclose (&fout); - if (fin && fin != stdin) - safe_fclose (&fin); } + + if (fin && fin != stdin) + safe_fclose (&fin); } FREE (&bodytext); -- 2.40.0