changeset: 6379:4909bd9c9149
user:      Kevin McCarthy <[email protected]>
date:      Sat Nov 02 20:12:41 2013 -0700
link:      http://dev.mutt.org/hg/mutt/rev/4909bd9c9149

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.

diffs (123 lines):

diff -r daf61444d454 -r 4909bd9c9149 main.c
--- a/main.c    Sat Jun 21 13:51:38 2014 -0700
+++ b/main.c    Sat Nov 02 20:12:41 2013 -0700
@@ -866,44 +866,40 @@
 
     if (!msg)
       msg = mutt_new_header ();
+    if (!msg->env)
+      msg->env = mutt_new_envelope ();
+
+    for (i = optind; i < argc; i++)
+    {
+      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 (!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 (draftFile)
       infile = draftFile;
-    else
-    {
-      if (!msg->env)
-       msg->env = mutt_new_envelope ();
-
-      for (i = optind; i < argc; i++)
-      {
-       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 (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 (includeFile)
-       infile = includeFile;
-    }
+    else if (includeFile)
+      infile = includeFile;
 
     if (infile || bodytext)
     {
@@ -925,16 +921,25 @@
            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 @@
        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);

Reply via email to