]> granicus.if.org Git - mutt/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)
committerKevin McCarthy <kevin@8t8.us>
Tue, 25 Dec 2018 21:52:03 +0000 (13:52 -0800)
Convert the mode parameter to an enum, to make the code a bit more readable.

headers.c
main.c
mutt.h
protos.h
send.c
sendlib.c

index ceef1db10c6032cd2d5e01e88607b3122482d323..e9cf4153f7822302a4e7f05c571677bc10d65676 100644 (file)
--- 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 10fc5256aad54e7de9202b4835f9e59e00115e57..6f7b4a1122e71a86319de2291d44c80647dd5b1d 100644 (file)
--- 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 d2a268c37766d0bb086040830eb6ca9adc7bf001..14e0f44e775961371c890594d5712b62b8a691d7 100644 (file)
--- 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)
index 76d0650b8ba2d4f1e7e8552c0e4be41af031ff4d..2e4d851f8845ccfa2ed24631bd2c3a295833f62f 100644 (file)
--- 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 610ef3a5a0a24c871109a3386390728b07925cfd..8d6b28a56b7226e7c22f0e4b2ff6810d63c7b206 100644 (file)
--- 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)
index d1502978e7af79f294a068494d3b8eec437b63c3..f7f2fd9ed78a7cbbf19f3b3d21cb1948e6162581 100644 (file)
--- 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, <msgid> contains the
    * Message-ID: of message replied to.  Save it using a special X-Mutt-