From e000459d0ef85a2cc470cd6a9b1abf407f335918 Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Tue, 8 Mar 2016 15:57:55 -0800 Subject: [PATCH] Add $resume_edited_draft_files option. This adds an extra header when saving edited draft files (-E -H on the command line). With this header, the next time they are edited, they are automatically "resumed" (by setting $resume_draft_files). The idea is to prevent multiple user-defined headers and signatures from being added to the draft message by avoiding processing it as a brand new message after the first time. --- init.h | 16 ++++++++++++++++ main.c | 26 +++++++++++++++++++++++++- mutt.h | 1 + 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/init.h b/init.h index f610fffa6..52cbbf01e 100644 --- a/init.h +++ b/init.h @@ -2470,6 +2470,22 @@ struct option_t MuttVars[] = { ** evaluated; no alias expansion takes place; user-defined headers ** and signatures are not added to the message. */ + { "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 + ** The first time a draft file is saved, mutt will add a header, + ** X-Mutt-Resume-Draft to the saved file. The next time the draft + ** file is read in, if mutt sees the header, it will set + ** $$resume_draft_files. + ** .pp + ** This option is designed to prevent multiple signatures, + ** user-defined headers, and other processing effects from being + ** made multiple times to the draft file. + */ { "reverse_alias", DT_BOOL, R_BOTH, OPTREVALIAS, 0 }, /* ** .pp diff --git a/main.c b/main.c index 83cca786d..d0a11281d 100644 --- a/main.c +++ b/main.c @@ -997,6 +997,7 @@ int main (int argc, char **argv) HEADER *context_hdr = NULL; ENVELOPE *opts_env = msg->env; struct stat st; + LIST *uh, **last_uhp; sendflags |= SENDDRAFTFILE; @@ -1006,11 +1007,32 @@ int main (int argc, char **argv) context_hdr = mutt_new_header (); context_hdr->offset = 0; context_hdr->content = mutt_new_body (); - fstat (fileno (fin), &st); + if (fstat (fileno (fin), &st)) + { + perror (draftFile); + exit (1); + } context_hdr->content->length = st.st_size; mutt_prepare_template (fin, NULL, msg, context_hdr, 0); + /* Scan for mutt header to set OPTRESUMEDRAFTFILES */ + for (last_uhp = &msg->env->userhdrs, uh = *last_uhp; + uh; uh = *last_uhp) + { + if (ascii_strncasecmp ("X-Mutt-Resume-Draft:", uh->data, 20) == 0) + { + if (option (OPTRESUMEEDITEDDRAFTFILES)) + set_option (OPTRESUMEDRAFTFILES); + + *last_uhp = uh->next; + uh->next = NULL; + mutt_free_list (&uh); + } + else + last_uhp = &uh->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); @@ -1102,6 +1124,8 @@ int main (int argc, char **argv) } 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)) { diff --git a/mutt.h b/mutt.h index a290fa64e..de26fd842 100644 --- a/mutt.h +++ b/mutt.h @@ -419,6 +419,7 @@ enum OPTREPLYSELF, OPTRESOLVE, OPTRESUMEDRAFTFILES, + OPTRESUMEEDITEDDRAFTFILES, OPTREVALIAS, OPTREVNAME, OPTREVREAL, -- 2.40.0