From: Kevin McCarthy Date: Mon, 24 Dec 2018 00:23:02 +0000 (-0800) Subject: Add a new mode for mutt_write_rfc822_header(). X-Git-Tag: mutt-1-12-rel~166 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f1431b15ce8762929cbbe7010d54fd48687b4c2a;p=mutt Add a new mode for mutt_write_rfc822_header(). Convert the mode parameter to an enum, to make the code a bit more readable. --- diff --git a/headers.c b/headers.c index ceef1db1..e9cf4153 100644 --- a/headers.c +++ b/headers.c @@ -53,7 +53,7 @@ void mutt_edit_headers (const char *editor, } mutt_env_to_local (msg->env); - mutt_write_rfc822_header (ofp, msg->env, NULL, 1, 0); + mutt_write_rfc822_header (ofp, msg->env, NULL, MUTT_WRITE_HEADER_EDITHDRS, 0); fputc ('\n', ofp); /* tie off the header. */ /* now copy the body of the message. */ diff --git a/main.c b/main.c index 10fc5256..6f7b4a11 100644 --- a/main.c +++ b/main.c @@ -1227,7 +1227,8 @@ int main (int argc, char **argv, char **environ) mutt_env_to_intl (msg->env, NULL, NULL); } - mutt_write_rfc822_header (fout, msg->env, msg->content, -1, 0); + mutt_write_rfc822_header (fout, msg->env, msg->content, + MUTT_WRITE_HEADER_POSTPONE, 0); if (option (OPTRESUMEEDITEDDRAFTFILES)) fprintf (fout, "X-Mutt-Resume-Draft: 1\n"); fputc ('\n', fout); diff --git a/mutt.h b/mutt.h index d2a268c3..14e0f44e 100644 --- a/mutt.h +++ b/mutt.h @@ -156,6 +156,15 @@ typedef enum MUTT_FORMAT_NOFILTER = (1<<7) /* do not allow filtering on this pass */ } format_flag; +/* mode for mutt_write_rfc822_header() */ +typedef enum +{ + MUTT_WRITE_HEADER_NORMAL, + MUTT_WRITE_HEADER_POSTPONE, + MUTT_WRITE_HEADER_EDITHDRS, + MUTT_WRITE_HEADER_MIME +} mutt_write_header_mode; + /* types for mutt_add_hook() */ #define MUTT_FOLDERHOOK 1 #define MUTT_MBOXHOOK (1<<1) diff --git a/protos.h b/protos.h index 76d0650b..2e4d851f 100644 --- a/protos.h +++ b/protos.h @@ -389,7 +389,7 @@ int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int, char int mutt_write_mime_body (BODY *, FILE *); int mutt_write_mime_header (BODY *, FILE *); int mutt_write_one_header (FILE *fp, const char *tag, const char *value, const char *pfx, int wraplen, int flags); -int mutt_write_rfc822_header (FILE *, ENVELOPE *, BODY *, int, int); +int mutt_write_rfc822_header (FILE *, ENVELOPE *, BODY *, mutt_write_header_mode, int); void mutt_write_references (LIST *, FILE *, int); int mutt_yesorno (const char *, int); void mutt_set_header_color(CONTEXT *, HEADER *); diff --git a/send.c b/send.c index 610ef3a5..8d6b28a5 100644 --- a/send.c +++ b/send.c @@ -999,10 +999,12 @@ static int send_message (HEADER *msg) unset_option (OPTWRITEBCC); #endif #ifdef MIXMASTER - mutt_write_rfc822_header (tempfp, msg->env, msg->content, 0, msg->chain ? 1 : 0); + mutt_write_rfc822_header (tempfp, msg->env, msg->content, + MUTT_WRITE_HEADER_NORMAL, msg->chain ? 1 : 0); #endif #ifndef MIXMASTER - mutt_write_rfc822_header (tempfp, msg->env, msg->content, 0, 0); + mutt_write_rfc822_header (tempfp, msg->env, msg->content, + MUTT_WRITE_HEADER_NORMAL, 0); #endif #ifdef USE_SMTP if (old_write_bcc) diff --git a/sendlib.c b/sendlib.c index d1502978..f7f2fd9e 100644 --- a/sendlib.c +++ b/sendlib.c @@ -1956,9 +1956,10 @@ out: * * Likewise, all IDN processing should happen outside of this routine. * - * mode == 1 => "lite" mode (used for edit_hdrs) - * mode == 0 => normal mode. write full header + MIME headers - * mode == -1 => write just the envelope info (used for postponing messages) + * mode == MUTT_WRITE_HEADER_EDITHDRS => "lite" mode (used for edit_hdrs) + * mode == MUTT_WRITE_HEADER_NORMAL => normal mode. write full header + MIME headers + * mode == MUTT_WRITE_HEADER_POSTPONE => write just the envelope info + * mode == MUTT_WRITE_HEADER_MIME => for writing protected headers * * privacy != 0 => will omit any headers which may identify the user. * Output generated is suitable for being sent through @@ -1969,14 +1970,14 @@ out: int mutt_write_rfc822_header (FILE *fp, ENVELOPE *env, BODY *attach, - int mode, int privacy) + mutt_write_header_mode mode, int privacy) { char buffer[LONG_STRING]; char *p, *q; LIST *tmp = env->userhdrs; int has_agent = 0; /* user defined user-agent header field exists */ - if (mode == 0 && !privacy) + if (mode == MUTT_WRITE_HEADER_NORMAL && !privacy) fputs (mutt_make_date (buffer, sizeof(buffer)), fp); /* OPTUSEFROM is not consulted here so that we can still write a From: @@ -2001,7 +2002,7 @@ int mutt_write_rfc822_header (FILE *fp, ENVELOPE *env, BODY *attach, fputs ("To: ", fp); mutt_write_address_list (env->to, fp, 4, 0); } - else if (mode > 0) + else if (mode == MUTT_WRITE_HEADER_EDITHDRS) fputs ("To: \n", fp); if (env->cc) @@ -2009,23 +2010,25 @@ int mutt_write_rfc822_header (FILE *fp, ENVELOPE *env, BODY *attach, fputs ("Cc: ", fp); mutt_write_address_list (env->cc, fp, 4, 0); } - else if (mode > 0) + else if (mode == MUTT_WRITE_HEADER_EDITHDRS) fputs ("Cc: \n", fp); if (env->bcc) { - if(mode != 0 || option(OPTWRITEBCC)) + if (mode == MUTT_WRITE_HEADER_POSTPONE || + mode == MUTT_WRITE_HEADER_EDITHDRS || + (mode == MUTT_WRITE_HEADER_NORMAL && option(OPTWRITEBCC))) { fputs ("Bcc: ", fp); mutt_write_address_list (env->bcc, fp, 5, 0); } } - else if (mode > 0) + else if (mode == MUTT_WRITE_HEADER_EDITHDRS) fputs ("Bcc: \n", fp); if (env->subject) mutt_write_one_header (fp, "Subject", env->subject, NULL, 0, 0); - else if (mode == 1) + else if (mode == MUTT_WRITE_HEADER_EDITHDRS) fputs ("Subject: \n", fp); /* save message id if the user has set it */ @@ -2037,7 +2040,7 @@ int mutt_write_rfc822_header (FILE *fp, ENVELOPE *env, BODY *attach, fputs ("Reply-To: ", fp); mutt_write_address_list (env->reply_to, fp, 10, 0); } - else if (mode > 0) + else if (mode == MUTT_WRITE_HEADER_EDITHDRS) fputs ("Reply-To: \n", fp); if (env->mail_followup_to) @@ -2046,7 +2049,8 @@ int mutt_write_rfc822_header (FILE *fp, ENVELOPE *env, BODY *attach, mutt_write_address_list (env->mail_followup_to, fp, 18, 0); } - if (mode <= 0) + if (mode == MUTT_WRITE_HEADER_NORMAL || + mode == MUTT_WRITE_HEADER_POSTPONE) { if (env->references) { @@ -2099,7 +2103,8 @@ int mutt_write_rfc822_header (FILE *fp, ENVELOPE *env, BODY *attach, } } - if (mode == 0 && !privacy && option (OPTXMAILER) && !has_agent) + if (mode == MUTT_WRITE_HEADER_NORMAL && !privacy && + option (OPTXMAILER) && !has_agent) { /* Add a vanity header */ fprintf (fp, "User-Agent: Mutt/%s (%s)\n", MUTT_VERSION, ReleaseDate); @@ -2785,10 +2790,12 @@ int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int post, return (-1); } - /* post == 1 => postpone message. Set mode = -1 in mutt_write_rfc822_header() - * post == 0 => Normal mode. Set mode = 0 in mutt_write_rfc822_header() + /* post == 1 => postpone message. + * post == 0 => Normal mode. * */ - mutt_write_rfc822_header (msg->fp, hdr->env, hdr->content, post ? -post : 0, 0); + mutt_write_rfc822_header (msg->fp, hdr->env, hdr->content, + post ? MUTT_WRITE_HEADER_POSTPONE : MUTT_WRITE_HEADER_NORMAL, + 0); /* (postponment) if this was a reply of some sort, contains the * Message-ID: of message replied to. Save it using a special X-Mutt-