On Sun, Feb 28, 2016 at 07:50:45PM -0800, Kevin J. McCarthy wrote:
> I'm attaching a patch for testing/feedback.  It adds $resume_draft_files
> (default is unset).  Note that this can be enabled via '-e set
> resume_draft_files' on the command line.  The patch is based on
> d11b6776532f which I just pushed.

Here is another idea, on top of the previous patch.  It adds another
option $resume_edited_draft_files (set by default).  When an edited (-E)
draft file is saved, it adds a header "X-Mutt-Resume-Draft: 1".  When
mutt sees this header (and the $resume_edited_draft_files is set), it
automatically enables $resume_draft_files.

The idea is to help by automatically tracking which draft files have
already been "processed" with a signature and user-headers, and thus not
do so again.

The patch is really raw, and only briefly documented.  If this is
interesting, I will clean it up.  Please let me know what you think.

-- 
Kevin J. McCarthy
GPG Fingerprint: 8975 A9B3 3AA3 7910 385C  5308 ADEF 7684 8031 6BDA
http://www.8t8.us/configs/gpg-key-transition-statement.txt
# HG changeset patch
# User Kevin McCarthy <[email protected]>
# Date 1456783458 28800
#      Mon Feb 29 14:04:18 2016 -0800
# Node ID de284c393380188a6289dad46e12476916a48a70
# Parent  c6e2213ab0301528491a4ff8ce0a63c33d12e4b4
Add $resume_edited_draft_files option.

This adds an extra header to saved draft files, so that the next time
they are edited, they are automatically "resumed" (by setting
$resume_draft_files).

diff --git a/init.h b/init.h
--- a/init.h
+++ b/init.h
@@ -2466,16 +2466,26 @@
   ** evaluated; no alias expansion takes place; user-defined headers
   ** and signatures are not added to the message.
   ** .pp
   ** This option may be useful when the \fC-E\fP command line argument
   ** is used, to avoid a signature and user-defined headers being
   ** added to the message multiple times.  It can be enabled on the
   ** command line using \fC-e 'set resume_draft_files'\fP.
   */
+  { "resume_edited_draft_files", DT_BOOL, R_NONE, OPTRESUMEEDITEDDRAFTFILES, 1 
},
+  /*
+  ** .pp
+  ** If \fIset\fP, draft files previously edited (via \fC-E -H\fP on the 
command
+  ** line) will have $$resume_draft_files automatically set when they are used
+  ** as a draft file again.
+  ** .pp
+  ** This is accomplished via an extra header, X-Mutt-Resume-Draft, added the 
first
+  ** time a draft file is re-saved.
+  */
   { "reverse_alias",   DT_BOOL, R_BOTH, OPTREVALIAS, 0 },
   /*
   ** .pp
   ** This variable controls whether or not Mutt will display the ``personal''
   ** name from your aliases in the index menu if it finds an alias that
   ** matches the message's sender.  For example, if you have the following
   ** alias:
   ** .ts
diff --git a/main.c b/main.c
--- a/main.c
+++ b/main.c
@@ -992,30 +992,56 @@
        * Set SENDDRAFTFILE so ci_send_message doesn't overwrite
        * our msg->content.
        */
       if (draftFile)
       {
         HEADER *context_hdr = NULL;
         ENVELOPE *opts_env = msg->env;
         struct stat st;
+        LIST *tmp, *next, *last = NULL;
 
         sendflags |= SENDDRAFTFILE;
 
         /* Set up a "context" header with just enough information so that
          * mutt_prepare_template() can parse the message in fin.
          */
         context_hdr = mutt_new_header ();
         context_hdr->offset = 0;
         context_hdr->content = mutt_new_body ();
         fstat (fileno (fin), &st);
         context_hdr->content->length = st.st_size;
 
         mutt_prepare_template (fin, NULL, msg, context_hdr, 0);
 
+        /* Scan for mutt header to set OPTRESUMEDRAFTFILES */
+        for (tmp = msg->env->userhdrs; tmp; )
+        {
+          if (ascii_strncasecmp ("X-Mutt-Resume-Draft:", tmp->data, 20) == 0)
+          {
+            if (option (OPTRESUMEEDITEDDRAFTFILES))
+              set_option (OPTRESUMEDRAFTFILES);
+
+            /* Remove the X-Mutt-Resume-Draft: header field. */
+            next = tmp->next;
+            if (last)
+              last->next = tmp->next;
+            else
+              msg->env->userhdrs = tmp->next;
+            tmp->next = NULL;
+            mutt_free_list (&tmp);
+            tmp = next;
+          }
+          else
+          {
+            last = tmp;
+            tmp = tmp->next;
+          }
+        }
+
         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);
         mutt_free_header (&context_hdr);
@@ -1097,16 +1123,18 @@
           if (msg->content->next)
             msg->content = mutt_make_multipart (msg->content);
           mutt_encode_descriptions (msg->content, 1);
           mutt_prepare_envelope (msg->env, 0);
           mutt_env_to_intl (msg->env, NULL, NULL);
         }
 
         mutt_write_rfc822_header (fout, msg->env, msg->content, -1, 0);
+        if (option (OPTRESUMEEDITEDDRAFTFILES))
+          fprintf (fout, "X-Mutt-Resume-Draft: 1\n");
         fputc ('\n', fout);
         if ((mutt_write_mime_body (msg->content, fout) == -1))
         {
           if (!option (OPTNOCURSES))
             mutt_endwin (NULL);
           safe_fclose (&fout);
           exit (1);
         }
diff --git a/mutt.h b/mutt.h
--- a/mutt.h
+++ b/mutt.h
@@ -414,16 +414,17 @@
   OPTPRINTSPLIT,
   OPTPROMPTAFTER,
   OPTREADONLY,
   OPTREFLOWSPACEQUOTES,
   OPTREFLOWTEXT,
   OPTREPLYSELF,
   OPTRESOLVE,
   OPTRESUMEDRAFTFILES,
+  OPTRESUMEEDITEDDRAFTFILES,
   OPTREVALIAS,
   OPTREVNAME,
   OPTREVREAL,
   OPTRFC2047PARAMS,
   OPTSAVEADDRESS,
   OPTSAVEEMPTY,
   OPTSAVENAME,
   OPTSCORE,

Attachment: signature.asc
Description: PGP signature

Reply via email to