changeset: 6564:24b4f14e9538 user: Kevin McCarthy <ke...@8t8.us> date: Tue Mar 08 15:57:50 2016 -0800 link: http://dev.mutt.org/hg/mutt/rev/24b4f14e9538
Add $resume_draft_files option. When set, draft files are processed the same as when resuming postponed messages. One use of this option is to avoid multiple user-defined headers and signatures being added to the message. (e.g. when -E is used repeatedly on the draft files). changeset: 6565:d07d2e9f1e34 user: Kevin McCarthy <ke...@8t8.us> date: Tue Mar 08 15:57:55 2016 -0800 link: http://dev.mutt.org/hg/mutt/rev/d07d2e9f1e34 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. diffs (114 lines): diff -r ce71d168c819 -r d07d2e9f1e34 init.h --- a/init.h Tue Mar 08 13:12:02 2016 -0800 +++ b/init.h Tue Mar 08 15:57:55 2016 -0800 @@ -2461,6 +2461,31 @@ ** (possibly undeleted) message whenever a command that modifies the ** current message is executed. */ + { "resume_draft_files", DT_BOOL, R_NONE, OPTRESUMEDRAFTFILES, 0 }, + /* + ** .pp + ** If \fIset\fP, draft files (specified by \fC-H\fP on the command + ** line) are processed similarly to when resuming a postponed + ** message. Recipients are not prompted for; send-hooks are not + ** 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 -r ce71d168c819 -r d07d2e9f1e34 main.c --- a/main.c Tue Mar 08 13:12:02 2016 -0800 +++ b/main.c Tue Mar 08 15:57:55 2016 -0800 @@ -997,6 +997,7 @@ HEADER *context_hdr = NULL; ENVELOPE *opts_env = msg->env; struct stat st; + LIST *uh, **last_uhp; sendflags |= SENDDRAFTFILE; @@ -1006,11 +1007,32 @@ 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 @@ } 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 -r ce71d168c819 -r d07d2e9f1e34 mutt.h --- a/mutt.h Tue Mar 08 13:12:02 2016 -0800 +++ b/mutt.h Tue Mar 08 15:57:55 2016 -0800 @@ -418,6 +418,8 @@ OPTREFLOWTEXT, OPTREPLYSELF, OPTRESOLVE, + OPTRESUMEDRAFTFILES, + OPTRESUMEEDITEDDRAFTFILES, OPTREVALIAS, OPTREVNAME, OPTREVREAL, diff -r ce71d168c819 -r d07d2e9f1e34 send.c --- a/send.c Tue Mar 08 13:12:02 2016 -0800 +++ b/send.c Tue Mar 08 15:57:55 2016 -0800 @@ -1287,7 +1287,8 @@ msg->env->from = set_reverse_name (cur->env); } - if (! (flags & (SENDPOSTPONED|SENDRESEND))) + if (! (flags & (SENDPOSTPONED|SENDRESEND)) && + ! ((flags & SENDDRAFTFILE) && option (OPTRESUMEDRAFTFILES))) { if ((flags & (SENDREPLY | SENDFORWARD)) && ctx && envelope_defaults (msg->env, ctx, cur, flags) == -1)