]> granicus.if.org Git - mutt/commitdiff
Finish protected header write support.
authorKevin McCarthy <kevin@8t8.us>
Mon, 24 Dec 2018 00:32:52 +0000 (16:32 -0800)
committerKevin McCarthy <kevin@8t8.us>
Tue, 25 Dec 2018 21:52:03 +0000 (13:52 -0800)
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.

crypt.c
headers.c
main.c
mutt_crypt.h
protos.h
send.c
sendlib.c

diff --git a/crypt.c b/crypt.c
index f68d4f5556265a3610b0ba1ed33a2b54a6aa044c..e1ab409e81bc0c3228fe10e59d4c2e35d7bf2a19 100644 (file)
--- a/crypt.c
+++ b/crypt.c
@@ -926,6 +926,17 @@ static void crypt_fetch_signatures (BODY ***signatures, BODY *a, int *n)
   }
 }
 
+int mutt_should_hide_protected_subject (HEADER *h)
+{
+  if (option (OPTCRYPTPROTHDRSWRITE) &&
+      (h->security & ENCRYPT) &&
+      !(h->security & INLINE) &&
+      ProtHdrSubject && *ProtHdrSubject)
+    return 1;
+
+  return 0;
+}
+
 int mutt_protected_headers_handler (BODY *a, STATE *s)
 {
   if (option (OPTCRYPTPROTHDRSREAD) && a->mime_headers)
index e9cf4153f7822302a4e7f05c571677bc10d65676..9b60023cf30a77d150daede185af3d54a44d9820 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, MUTT_WRITE_HEADER_EDITHDRS, 0);
+  mutt_write_rfc822_header (ofp, msg->env, NULL, MUTT_WRITE_HEADER_EDITHDRS, 0, 0);
   fputc ('\n', ofp);   /* tie off the header. */
 
   /* now copy the body of the message. */
diff --git a/main.c b/main.c
index 6f7b4a1122e71a86319de2291d44c80647dd5b1d..347521ea2126059c8f229e1f426a1dff36b9aa42 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1228,7 +1228,9 @@ int main (int argc, char **argv, char **environ)
         }
 
         mutt_write_rfc822_header (fout, msg->env, msg->content,
-                                  MUTT_WRITE_HEADER_POSTPONE, 0);
+                                  MUTT_WRITE_HEADER_POSTPONE, 0,
+                                  option (OPTCRYPTPROTHDRSREAD) &&
+                                  mutt_should_hide_protected_subject (msg));
         if (option (OPTRESUMEEDITEDDRAFTFILES))
           fprintf (fout, "X-Mutt-Resume-Draft: 1\n");
         fputc ('\n', fout);
index 1fa3f3590d147bc5217e84500f5453d6b2681a89..2a368d1a8ff83ab61cdbacf47fa00a8fac859a11 100644 (file)
@@ -122,6 +122,8 @@ int mutt_is_application_pgp (BODY *);
 
 int mutt_is_application_smime (BODY *);
 
+int mutt_should_hide_protected_subject (HEADER *);
+
 int mutt_protected_headers_handler (BODY *, STATE *);
 
 int mutt_signed_handler (BODY *, STATE *);
index 2e4d851f8845ccfa2ed24631bd2c3a295833f62f..b3a6e42621bf7cd362d416e6874896f7dab39a15 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 *, mutt_write_header_mode, int);
+int mutt_write_rfc822_header (FILE *, ENVELOPE *, BODY *, mutt_write_header_mode, int, 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 8d6b28a56b7226e7c22f0e4b2ff6810d63c7b206..16dad8d59ebf454be195fa3ce63c07bbff3fda9f 100644 (file)
--- a/send.c
+++ b/send.c
@@ -1000,11 +1000,13 @@ static int send_message (HEADER *msg)
 #endif
 #ifdef MIXMASTER
   mutt_write_rfc822_header (tempfp, msg->env, msg->content,
-                            MUTT_WRITE_HEADER_NORMAL, msg->chain ? 1 : 0);
+                            MUTT_WRITE_HEADER_NORMAL, msg->chain ? 1 : 0,
+                            mutt_should_hide_protected_subject (msg));
 #endif
 #ifndef MIXMASTER
   mutt_write_rfc822_header (tempfp, msg->env, msg->content,
-                            MUTT_WRITE_HEADER_NORMAL, 0);
+                            MUTT_WRITE_HEADER_NORMAL, 0,
+                            mutt_should_hide_protected_subject (msg));
 #endif
 #ifdef USE_SMTP
   if (old_write_bcc)
@@ -1079,7 +1081,11 @@ static int save_fcc (HEADER *msg, char *fcc, size_t fcc_len,
     return rc;
 
   if (WithCrypto && (msg->security & (ENCRYPT | SIGN)) && option (OPTFCCCLEAR))
+  {
     msg->content = clear_content;
+    msg->security &= ~(ENCRYPT | SIGN);
+    mutt_free_envelope (&msg->content->mime_headers);
+  }
 
   /* check to see if the user wants copies of all attachments */
   if (query_quadoption (OPT_FCCATTACH, _("Save attachments in Fcc?")) != MUTT_YES &&
@@ -1391,6 +1397,7 @@ static int postpone_message (HEADER *msg, HEADER *cur, char *fcc, int flags)
       mutt_free_body (&msg->content);
       msg->content = clear_content;
     }
+    mutt_free_envelope (&msg->content->mime_headers);  /* protected headers */
     msg->content = mutt_remove_multipart (msg->content);
     decode_descriptions (msg->content);
     mutt_unprepare_envelope (msg->env);
@@ -2033,6 +2040,7 @@ main_loop:
        msg->content = mutt_remove_multipart (msg->content); 
       }
 
+      mutt_free_envelope (&msg->content->mime_headers);  /* protected headers */
       msg->content = mutt_remove_multipart (msg->content);
       decode_descriptions (msg->content);
       mutt_unprepare_envelope (msg->env);
@@ -2051,9 +2059,9 @@ main_loop:
     mutt_message (i == 0 ? _("Mail sent.") : _("Sending in background."));
 
 
-  if (WithCrypto && (msg->security & ENCRYPT))
+  if (WithCrypto)
     FREE (&pgpkeylist);
-  
+
   if (WithCrypto && free_clear_content)
     mutt_free_body (&clear_content);
 
index f7f2fd9ed78a7cbbf19f3b3d21cb1948e6162581..9e0cc65c429f22aeecdb10abdd9204e80822abf0 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -400,6 +400,9 @@ int mutt_write_mime_header (BODY *a, FILE *f)
   if (a->encoding != ENC7BIT)
     fprintf(f, "Content-Transfer-Encoding: %s\n", ENCODING (a->encoding));
 
+  if (option (OPTCRYPTPROTHDRSWRITE) && a->mime_headers)
+    mutt_write_rfc822_header (f, a->mime_headers, NULL, MUTT_WRITE_HEADER_MIME, 0, 0);
+
   /* Do NOT add the terminator here!!! */
   return (ferror (f) ? -1 : 0);
 }
@@ -1965,12 +1968,13 @@ out:
  *               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_write_rfc822_header (FILE *fp, ENVELOPE *env, BODY *attach,
-                             mutt_write_header_mode mode, int privacy)
+                             mutt_write_header_mode mode, int privacy,
+                              int hide_protected_subject)
 {
   char buffer[LONG_STRING];
   char *p, *q;
@@ -2027,7 +2031,14 @@ int mutt_write_rfc822_header (FILE *fp, ENVELOPE *env, BODY *attach,
     fputs ("Bcc: \n", fp);
 
   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", ProtHdrSubject, 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);
 
@@ -2795,7 +2806,9 @@ int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int post,
    * */
   mutt_write_rfc822_header (msg->fp, hdr->env, hdr->content,
                             post ? MUTT_WRITE_HEADER_POSTPONE : MUTT_WRITE_HEADER_NORMAL,
-                            0);
+                            0,
+                            option (OPTCRYPTPROTHDRSREAD) &&
+                            mutt_should_hide_protected_subject (hdr));
 
   /* (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-