From: Kevin McCarthy Date: Sun, 3 Nov 2013 03:12:41 +0000 (-0700) Subject: Override draft headers with arguments. (closes #3580) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4282ce891e6edb8947858a58763b6380a3f11c38;p=neomutt Override draft headers with arguments. (closes #3580) 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. --- diff --git a/main.c b/main.c index 204a5ca63..0d709f43e 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);