]> granicus.if.org Git - neomutt/commitdiff
Add a new mode for mutt_write_rfc822_header()
authorKevin McCarthy <kevin@8t8.us>
Mon, 24 Dec 2018 00:23:02 +0000 (16:23 -0800)
committerRichard Russon <rich@flatcap.org>
Mon, 7 Jan 2019 15:09:41 +0000 (15:09 +0000)
Convert the mode parameter to an enum, to make the code a bit more readable.

Co-authored-by: Richard Russon <rich@flatcap.org>
main.c
mutt_header.c
send.c
sendlib.c
sendlib.h

diff --git a/main.c b/main.c
index a0208e05b4fc82701567eecc3f8d58db1f32f307..b909879c80555c38f8a15b097680475f9a306602 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1094,7 +1094,8 @@ int main(int argc, char *argv[], char *envp[])
           mutt_env_to_intl(msg->env, NULL, NULL);
         }
 
-        mutt_rfc822_write_header(fout, msg->env, msg->content, -1, false);
+        mutt_rfc822_write_header(fout, msg->env, msg->content,
+                                 MUTT_WRITE_HEADER_POSTPONE, false);
         if (ResumeEditedDraftFiles)
           fprintf(fout, "X-Mutt-Resume-Draft: 1\n");
         fputc('\n', fout);
index 0523be4371a8f889c7209d8335d6a66487e0a820..097969b97ea71b269b4bc853d723b863d0e30aaf 100644 (file)
@@ -203,7 +203,7 @@ void mutt_edit_headers(const char *editor, const char *body, struct Email *msg,
   }
 
   mutt_env_to_local(msg->env);
-  mutt_rfc822_write_header(ofp, msg->env, NULL, 1, false);
+  mutt_rfc822_write_header(ofp, msg->env, NULL, MUTT_WRITE_HEADER_EDITHDRS, false);
   fputc('\n', ofp); /* tie off the header. */
 
   /* now copy the body of the message. */
diff --git a/send.c b/send.c
index ff2911a378fb7a859e7ec7a55866a7c207539e2e..b21677e4e7d5e524e2b1f751c1b85b153569c4e7 100644 (file)
--- a/send.c
+++ b/send.c
@@ -1272,10 +1272,11 @@ static int send_message(struct Email *msg)
     WriteBcc = false;
 #endif
 #ifdef MIXMASTER
-  mutt_rfc822_write_header(tempfp, msg->env, msg->content, 0, !STAILQ_EMPTY(&msg->chain));
+  mutt_rfc822_write_header(tempfp, msg->env, msg->content,
+                           MUTT_WRITE_HEADER_NORMAL, !STAILQ_EMPTY(&msg->chain));
 #endif
 #ifndef MIXMASTER
-  mutt_rfc822_write_header(tempfp, msg->env, msg->content, 0, false);
+  mutt_rfc822_write_header(tempfp, msg->env, msg->content, MUTT_WRITE_HEADER_NORMAL, false);
 #endif
 #ifdef USE_SMTP
   if (old_write_bcc)
index 4a3b182b7275df6b20b72d550abf1a5b0d87491a..7d3dd993c8527f2c9360b84a811b58588a7b3ef1 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -2190,7 +2190,7 @@ out:
  * @param fp      File to write to
  * @param env     Envelope of email
  * @param attach  Attachment
- * @param mode    Mode, see notes below
+ * @param mode    Mode, see #MuttWriteHeaderMode
  * @param privacy If true, remove headers that might identify the user
  * @retval  0 Success
  * @retval -1 Failure
@@ -2201,22 +2201,18 @@ out:
  *
  * Likewise, all IDN processing should happen outside of this routine.
  *
- * mode == 1  => "light" mode (used for edit_headers)
- * mode == 0  => normal mode.  write full header + MIME headers
- * mode == -1 => write just the envelope info (used for postponing messages)
- *
  * privacy true => will omit any headers which may identify the user.
  *               Output generated is suitable for being sent through
  *               anonymous remailer chains.
  */
-int mutt_rfc822_write_header(FILE *fp, struct Envelope *env,
-                             struct Body *attach, int mode, bool privacy)
+int mutt_rfc822_write_header(FILE *fp, struct Envelope *env, struct Body *attach,
+                             enum MuttWriteHeaderMode mode, bool privacy)
 {
   char buf[LONG_STRING];
   char *p = NULL, *q = NULL;
   bool has_agent = false; /* user defined user-agent header field exists */
 
-  if (mode == 0 && !privacy)
+  if (mode == MUTT_WRITE_HEADER_NORMAL && !privacy)
     fputs(mutt_date_make_date(buf, sizeof(buf)), fp);
 
   /* UseFrom is not consulted here so that we can still write a From:
@@ -2241,7 +2237,7 @@ int mutt_rfc822_write_header(FILE *fp, struct Envelope *env,
     fputs("To: ", fp);
     mutt_write_address_list(env->to, fp, 4, 0);
   }
-  else if (mode > 0)
+  else if (mode == MUTT_WRITE_HEADER_EDITHDRS)
 #ifdef USE_NNTP
     if (!OptNewsSend)
 #endif
@@ -2252,7 +2248,7 @@ int mutt_rfc822_write_header(FILE *fp, struct Envelope *env,
     fputs("Cc: ", fp);
     mutt_write_address_list(env->cc, fp, 4, 0);
   }
-  else if (mode > 0)
+  else if (mode == MUTT_WRITE_HEADER_EDITHDRS)
 #ifdef USE_NNTP
     if (!OptNewsSend)
 #endif
@@ -2260,13 +2256,14 @@ int mutt_rfc822_write_header(FILE *fp, struct Envelope *env,
 
   if (env->bcc)
   {
-    if (mode != 0 || WriteBcc)
+    if (mode == MUTT_WRITE_HEADER_POSTPONE || mode == MUTT_WRITE_HEADER_EDITHDRS ||
+        (mode == MUTT_WRITE_HEADER_NORMAL && WriteBcc))
     {
       fputs("Bcc: ", fp);
       mutt_write_address_list(env->bcc, fp, 5, 0);
     }
   }
-  else if (mode > 0)
+  else if (mode == MUTT_WRITE_HEADER_EDITHDRS)
 #ifdef USE_NNTP
     if (!OptNewsSend)
 #endif
@@ -2275,23 +2272,23 @@ int mutt_rfc822_write_header(FILE *fp, struct Envelope *env,
 #ifdef USE_NNTP
   if (env->newsgroups)
     fprintf(fp, "Newsgroups: %s\n", env->newsgroups);
-  else if (mode == 1 && OptNewsSend)
+  else if (mode == MUTT_WRITE_HEADER_EDITHDRS && OptNewsSend)
     fputs("Newsgroups:\n", fp);
 
   if (env->followup_to)
     fprintf(fp, "Followup-To: %s\n", env->followup_to);
-  else if (mode == 1 && OptNewsSend)
+  else if (mode == MUTT_WRITE_HEADER_EDITHDRS && OptNewsSend)
     fputs("Followup-To:\n", fp);
 
   if (env->x_comment_to)
     fprintf(fp, "X-Comment-To: %s\n", env->x_comment_to);
-  else if (mode == 1 && OptNewsSend && XCommentTo)
+  else if (mode == MUTT_WRITE_HEADER_EDITHDRS && OptNewsSend && XCommentTo)
     fputs("X-Comment-To:\n", fp);
 #endif
 
   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 */
@@ -2303,7 +2300,7 @@ int mutt_rfc822_write_header(FILE *fp, struct Envelope *env,
     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)
@@ -2315,7 +2312,7 @@ int mutt_rfc822_write_header(FILE *fp, struct Envelope *env,
       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 (!STAILQ_EMPTY(&env->references))
     {
@@ -2370,7 +2367,7 @@ int mutt_rfc822_write_header(FILE *fp, struct Envelope *env,
     }
   }
 
-  if (mode == 0 && !privacy && UserAgent && !has_agent)
+  if (mode == MUTT_WRITE_HEADER_NORMAL && !privacy && UserAgent && !has_agent)
   {
     /* Add a vanity header */
     fprintf(fp, "User-Agent: NeoMutt/%s%s\n", PACKAGE_VERSION, GitVer);
@@ -3201,10 +3198,12 @@ int mutt_write_fcc(const char *path, struct Email *e, const char *msgid,
     goto done;
   }
 
-  /* post == 1 => postpone message. Set mode = -1 in mutt_rfc822_write_header()
-   * post == 0 => Normal mode. Set mode = 0 in mutt_rfc822_write_header()
+  /* post == 1 => postpone message.
+   * post == 0 => Normal mode.
    */
-  mutt_rfc822_write_header(msg->fp, e->env, e->content, post ? -1 : 0, false);
+  mutt_rfc822_write_header(msg->fp, e->env, e->content,
+                           post ? MUTT_WRITE_HEADER_POSTPONE : MUTT_WRITE_HEADER_NORMAL,
+                           false);
 
   /* (postponement) if this was a reply of some sort, <msgid> contains the
    * Message-ID: of message replied to.  Save it using a special X-Mutt-
index 119c997d2573a586a49a49d212a9b0ab88e4d324..a37d020292677b08b2e9bd05c834c9ca15cbfca5 100644 (file)
--- a/sendlib.h
+++ b/sendlib.h
@@ -53,6 +53,17 @@ extern bool  UseEnvelopeFrom;
 extern bool  UserAgent;
 extern short WrapHeaders;
 
+/**
+ * enum MuttWriteHeaderMode - Modes for mutt_rfc822_write_header()
+ */
+enum MuttWriteHeaderMode
+{
+  MUTT_WRITE_HEADER_NORMAL,   ///< A normal Email, write full header + MIME headers
+  MUTT_WRITE_HEADER_POSTPONE, ///< A postponed Email, just the envelope info
+  MUTT_WRITE_HEADER_EDITHDRS, ///< "light" mode (used for edit_hdrs)
+  MUTT_WRITE_HEADER_MIME,     ///< Write protected headers
+};
+
 char *          mutt_body_get_charset(struct Body *b, char *buf, size_t buflen);
 int             mutt_bounce_message(FILE *fp, struct Email *e, struct Address *to);
 const char *    mutt_fqdn(bool may_hide_host);
@@ -67,7 +78,7 @@ void            mutt_message_to_7bit(struct Body *a, FILE *fp);
 void            mutt_prepare_envelope(struct Envelope *env, bool final);
 struct Address *mutt_addrlist_dedupe(struct Address *addr);
 struct Body *   mutt_remove_multipart(struct Body *b);
-int             mutt_rfc822_write_header(FILE *fp, struct Envelope *env, struct Body *attach, int mode, bool privacy);
+int             mutt_rfc822_write_header(FILE *fp, struct Envelope *env, struct Body *attach, enum MuttWriteHeaderMode mode, bool privacy);
 void            mutt_stamp_attachment(struct Body *a);
 void            mutt_unprepare_envelope(struct Envelope *env);
 void            mutt_update_encoding(struct Body *a);