]> granicus.if.org Git - neomutt/commitdiff
Finish protected header write support
authorKevin McCarthy <kevin@8t8.us>
Mon, 24 Dec 2018 00:32:52 +0000 (16:32 -0800)
committerRichard Russon <rich@flatcap.org>
Mon, 7 Jan 2019 15:09:41 +0000 (15:09 +0000)
Write out the protected headers when writing the mime header part.

Hide protected subjects with $crypt_protected_headers_subject, for
outgoing, postponed, and fcc'ed messages.

Don't hide in postponed and fcc'ed if $crypt_protected_headers_read
isn't set.

Add a few missing cases where mime_headers needed to be cleaned up on
error.

Remove the protected headers for $fcc_clear.

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

diff --git a/main.c b/main.c
index b909879c80555c38f8a15b097680475f9a306602..09e0f1eef9e8fde79ef86c27a2b6727def36616a 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1094,8 +1094,9 @@ 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,
-                                 MUTT_WRITE_HEADER_POSTPONE, false);
+        mutt_rfc822_write_header(
+            fout, msg->env, msg->content, MUTT_WRITE_HEADER_POSTPONE, false,
+            CryptProtectedHeadersRead && mutt_should_hide_protected_subject(msg));
         if (ResumeEditedDraftFiles)
           fprintf(fout, "X-Mutt-Resume-Draft: 1\n");
         fputc('\n', fout);
index 097969b97ea71b269b4bc853d723b863d0e30aaf..01b45323e1875ec13846bf106c2a15e6854f4805 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, MUTT_WRITE_HEADER_EDITHDRS, false);
+  mutt_rfc822_write_header(ofp, msg->env, NULL, MUTT_WRITE_HEADER_EDITHDRS, false, false);
   fputc('\n', ofp); /* tie off the header. */
 
   /* now copy the body of the message. */
index 417501700e74aaa8b1fb40e223a06da7fd737412..0995cd0f8eeb8f7683382a74d4bce015b21eef11 100644 (file)
@@ -1083,6 +1083,17 @@ static void crypt_fetch_signatures(struct Body ***signatures, struct Body *a, in
   }
 }
 
+bool mutt_should_hide_protected_subject(struct Email *e)
+{
+  if (CryptProtectedHeadersWrite && (e->security & ENCRYPT) && !(e->security & INLINE) &&
+      CryptProtectedHeadersSubject && *CryptProtectedHeadersSubject)
+  {
+    return true;
+  }
+
+  return false;
+}
+
 /**
  * mutt_protected_headers_handler - Process a protected header - Implements ::handler_t
  */
index 9657a9e635f59b03d7a2e902f3e412ff634ab826..cf45f27a812fd52e935776d12164c3641d64a151 100644 (file)
@@ -192,6 +192,7 @@ int          mutt_is_multipart_signed(struct Body *b);
 int          mutt_is_valid_multipart_pgp_encrypted(struct Body *b);
 int          mutt_protect(struct Email *msg, char *keylist);
 int          mutt_protected_headers_handler(struct Body *m, struct State *s);
+bool         mutt_should_hide_protected_subject(struct Email *e);
 int          mutt_signed_handler(struct Body *a, struct State *s);
 
 /* cryptglue.c */
diff --git a/send.c b/send.c
index b21677e4e7d5e524e2b1f751c1b85b153569c4e7..026ad138d1a51e467f83506da164aa2b2e3121f1 100644 (file)
--- a/send.c
+++ b/send.c
@@ -1273,10 +1273,12 @@ static int send_message(struct Email *msg)
 #endif
 #ifdef MIXMASTER
   mutt_rfc822_write_header(tempfp, msg->env, msg->content,
-                           MUTT_WRITE_HEADER_NORMAL, !STAILQ_EMPTY(&msg->chain));
+                           MUTT_WRITE_HEADER_NORMAL, !STAILQ_EMPTY(&msg->chain),
+                           mutt_should_hide_protected_subject(msg));
 #endif
 #ifndef MIXMASTER
-  mutt_rfc822_write_header(tempfp, msg->env, msg->content, MUTT_WRITE_HEADER_NORMAL, false);
+  mutt_rfc822_write_header(tempfp, msg->env, msg->content, MUTT_WRITE_HEADER_NORMAL,
+                           false, mutt_should_hide_protected_subject(msg));
 #endif
 #ifdef USE_SMTP
   if (old_write_bcc)
@@ -1517,7 +1519,11 @@ static int save_fcc(struct Email *msg, char *fcc, size_t fcc_len, struct Body *c
   struct Body *save_parts = NULL;
 
   if ((WithCrypto != 0) && (msg->security & (ENCRYPT | SIGN)) && FccClear)
+  {
     msg->content = clear_content;
+    msg->security &= ~(ENCRYPT | SIGN);
+    mutt_env_free(&msg->content->mime_headers);
+  }
 
   /* check to see if the user wants copies of all attachments */
   if (msg->content->type == TYPE_MULTIPART)
@@ -1715,6 +1721,7 @@ static int postpone_message(struct Email *msg, struct Email *cur, char *fcc, int
       mutt_body_free(&msg->content);
       msg->content = clear_content;
     }
+    mutt_env_free(&msg->content->mime_headers); /* protected headers */
     msg->content = mutt_remove_multipart(msg->content);
     decode_descriptions(msg->content);
     mutt_unprepare_envelope(msg->env);
@@ -2438,6 +2445,7 @@ int ci_send_message(int flags, struct Email *msg, const char *tempfile,
         msg->content = mutt_remove_multipart(msg->content);
       }
 
+      mutt_env_free(&msg->content->mime_headers); /* protected headers */
       msg->content = mutt_remove_multipart(msg->content);
       decode_descriptions(msg->content);
       mutt_unprepare_envelope(msg->env);
@@ -2464,7 +2472,7 @@ int ci_send_message(int flags, struct Email *msg, const char *tempfile,
 #endif
   }
 
-  if ((WithCrypto != 0) && (msg->security & ENCRYPT))
+  if (WithCrypto)
     FREE(&pgpkeylist);
 
   if ((WithCrypto != 0) && free_clear_content)
index 7d3dd993c8527f2c9360b84a811b58588a7b3ef1..9d19a3ead6e28255b2048a93d48d1c307cee4257 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -463,6 +463,9 @@ int mutt_write_mime_header(struct Body *a, FILE *f)
   if (a->encoding != ENC_7BIT)
     fprintf(f, "Content-Transfer-Encoding: %s\n", ENCODING(a->encoding));
 
+  if (CryptProtectedHeadersWrite && a->mime_headers)
+    mutt_rfc822_write_header(f, a->mime_headers, NULL, MUTT_WRITE_HEADER_MIME, false, false);
+
   /* Do NOT add the terminator here!!! */
   return ferror(f) ? -1 : 0;
 }
@@ -2204,9 +2207,13 @@ out:
  * privacy true => will omit any headers which may identify the user.
  *               Output generated is suitable for being sent through
  *               anonymous remailer chains.
+ *
+ * hide_protected_subject: replaces the Subject header with
+ * $crypt_protected_headers_subject in NORMAL or POSTPONE mode.
  */
-int mutt_rfc822_write_header(FILE *fp, struct Envelope *env, struct Body *attach,
-                             enum MuttWriteHeaderMode mode, bool privacy)
+int mutt_rfc822_write_header(FILE *fp, struct Envelope *env,
+                             struct Body *attach, enum MuttWriteHeaderMode mode,
+                             bool privacy, bool hide_protected_subject)
 {
   char buf[LONG_STRING];
   char *p = NULL, *q = NULL;
@@ -2287,7 +2294,13 @@ int mutt_rfc822_write_header(FILE *fp, struct Envelope *env, struct Body *attach
 #endif
 
   if (env->subject)
-    mutt_write_one_header(fp, "Subject", env->subject, NULL, 0, 0);
+  {
+    if (hide_protected_subject &&
+        (mode == MUTT_WRITE_HEADER_NORMAL || mode == MUTT_WRITE_HEADER_POSTPONE))
+      mutt_write_one_header(fp, "Subject", CryptProtectedHeadersSubject, NULL, 0, 0);
+    else
+      mutt_write_one_header(fp, "Subject", env->subject, NULL, 0, 0);
+  }
   else if (mode == MUTT_WRITE_HEADER_EDITHDRS)
     fputs("Subject:\n", fp);
 
@@ -3201,9 +3214,9 @@ int mutt_write_fcc(const char *path, struct Email *e, const char *msgid,
   /* post == 1 => postpone message.
    * post == 0 => Normal mode.
    */
-  mutt_rfc822_write_header(msg->fp, e->env, e->content,
-                           post ? MUTT_WRITE_HEADER_POSTPONE : MUTT_WRITE_HEADER_NORMAL,
-                           false);
+  mutt_rfc822_write_header(
+      msg->fp, e->env, e->content, post ? MUTT_WRITE_HEADER_POSTPONE : MUTT_WRITE_HEADER_NORMAL,
+      false, CryptProtectedHeadersRead && mutt_should_hide_protected_subject(e));
 
   /* (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 a37d020292677b08b2e9bd05c834c9ca15cbfca5..b598a0c54705f1491a661ff362d5712349df61e5 100644 (file)
--- a/sendlib.h
+++ b/sendlib.h
@@ -78,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, enum MuttWriteHeaderMode mode, bool privacy);
+int             mutt_rfc822_write_header(FILE *fp, struct Envelope *env, struct Body *attach, enum MuttWriteHeaderMode mode, bool privacy, bool hide_protected_subject);
 void            mutt_stamp_attachment(struct Body *a);
 void            mutt_unprepare_envelope(struct Envelope *env);
 void            mutt_update_encoding(struct Body *a);