]> granicus.if.org Git - mutt/commitdiff
Add $crypt_protected_headers_save.
authorKevin McCarthy <kevin@8t8.us>
Thu, 27 Dec 2018 20:05:43 +0000 (12:05 -0800)
committerKevin McCarthy <kevin@8t8.us>
Sat, 29 Dec 2018 22:12:07 +0000 (14:12 -0800)
Setting this option will save the protected header back into the
clear-text message headers.  This improves
usability (searching/limiting/replying) when reopening a mailbox
without header cache.  However, it is a security trade-off, so
defaults off and strongly warns about what it is doing in the documentation.

commands.c
copy.c
copy.h
init.h
mutt.h

index bd09a485da1b0bdecb8cecd7e12e8beebcd9269d..5ec15888b5eb0db6d211da0af34f42ee1a716c09 100644 (file)
@@ -121,6 +121,14 @@ static void update_protected_headers (HEADER *cur)
       hash_insert (Context->subj_hash, cur->env->real_subj, cur);
 
     mx_save_to_header_cache (Context, cur);
+
+    /* Also persist back to the message headers if this is set */
+    if (option (OPTCRYPTPROTHDRSSAVE))
+    {
+      cur->env->changed |= MUTT_ENV_CHANGED_SUBJECT;
+      cur->changed = 1;
+      Context->changed = 1;
+    }
   }
 }
 
diff --git a/copy.c b/copy.c
index fa1240abae02d3736de0c21c92e450156cbe507b..2b0df8a604df497fd8e0817d6a3a8309756b287c 100644 (file)
--- a/copy.c
+++ b/copy.c
@@ -111,6 +111,9 @@ mutt_copy_hdr (FILE *in, FILE *out, LOFF_T off_start, LOFF_T off_end, int flags,
         if ((flags & CH_UPDATE_LABEL) &&
             ascii_strncasecmp ("X-Label:", buf, 8) == 0)
           continue;
+        if ((flags & CH_UPDATE_SUBJECT) &&
+            ascii_strncasecmp ("Subject:", buf, 8) == 0)
+          continue;
 
        ignore = 0;
       }
@@ -221,6 +224,9 @@ mutt_copy_hdr (FILE *in, FILE *out, LOFF_T off_start, LOFF_T off_end, int flags,
       if ((flags & CH_UPDATE_LABEL) &&
           ascii_strncasecmp ("X-Label:", buf, 8) == 0)
         continue;
+      if ((flags & CH_UPDATE_SUBJECT) &&
+          ascii_strncasecmp ("Subject:", buf, 8) == 0)
+        continue;
 
       /* Find x -- the array entry where this header is to be saved */
       if (flags & CH_REORDER)
@@ -357,7 +363,8 @@ mutt_copy_header (FILE *in, HEADER *h, FILE *out, int flags, const char *prefix)
   if (h->env)
     flags |= ((h->env->changed & MUTT_ENV_CHANGED_IRT) ? CH_UPDATE_IRT : 0)
       | ((h->env->changed & MUTT_ENV_CHANGED_REFS) ? CH_UPDATE_REFS : 0)
-      | ((h->env->changed & MUTT_ENV_CHANGED_XLABEL) ? CH_UPDATE_LABEL : 0);
+      | ((h->env->changed & MUTT_ENV_CHANGED_XLABEL) ? CH_UPDATE_LABEL : 0)
+      | ((h->env->changed & MUTT_ENV_CHANGED_SUBJECT) ? CH_UPDATE_SUBJECT : 0);
 
   if (mutt_copy_hdr (in, out, h->offset, h->content->offset, flags, prefix) == -1)
     return -1;
@@ -444,6 +451,25 @@ mutt_copy_header (FILE *in, HEADER *h, FILE *out, int flags, const char *prefix)
       FREE (&temp_hdr);
   }
 
+  if ((flags & CH_UPDATE_SUBJECT) && h->env->subject)
+  {
+    temp_hdr = h->env->subject;
+    /* env->subject is directly referenced in Context->subj_hash, so we
+     * have to be careful not to encode (and thus free) that memory. */
+    if (!(flags & CH_DECODE))
+    {
+      temp_hdr = safe_strdup (temp_hdr);
+      rfc2047_encode_string (&temp_hdr);
+    }
+    if (mutt_write_one_header (out, "Subject", temp_hdr,
+                               flags & CH_PREFIX ? prefix : 0,
+                               mutt_window_wrap_cols (MuttIndexWindow, Wrap),
+                               flags) == -1)
+      return -1;
+    if (!(flags & CH_DECODE))
+      FREE (&temp_hdr);
+  }
+
   if ((flags & CH_NONEWLINE) == 0)
   {
     if (flags & CH_PREFIX)
diff --git a/copy.h b/copy.h
index 2ba54143fc856dcdb44b676eec7ec1133b064196..11ade3819e2dddc9d4b5fb752aa5db899c58f345 100644 (file)
--- a/copy.h
+++ b/copy.h
@@ -54,6 +54,7 @@
 #define CH_UPDATE_REFS    (1<<17) /* update References: */
 #define CH_DISPLAY        (1<<18) /* display result to user */
 #define CH_UPDATE_LABEL   (1<<19) /* update X-Label: from hdr->env->x_label? */
+#define CH_UPDATE_SUBJECT (1<<20) /* update Subject: protected header update */
 
 
 int mutt_copy_hdr (FILE *, FILE *, LOFF_T, LOFF_T, int, const char *);
diff --git a/init.h b/init.h
index a3deea71e551476d2f3ebcaf1474b74c4bfe4297..35c1ec759398400cdfeb83a94684df6f4b088a26 100644 (file)
--- a/init.h
+++ b/init.h
@@ -605,6 +605,30 @@ struct option_t MuttVars[] = {
   ** message is opened, i.e. via the \fC<display-message>\fP function.
   ** If you reply to a message before opening it, Mutt will end up using
   ** the dummy Subject header, so be sure to open such a message first.
+  ** (Crypto only)
+   */
+  { "crypt_protected_headers_save", DT_BOOL, R_NONE, OPTCRYPTPROTHDRSSAVE, 0 },
+  /*
+  ** .pp
+  ** When $$crypt_protected_headers_read is set, and a message with a
+  ** protected Subject is opened, Mutt will save the updated Subject
+  ** into the header cache by default.  This allows searching/limiting
+  ** based on the protected Subject header if the mailbox is
+  ** re-opened, without having to re-open the message each time.
+  ** However, for mbox/mh mailbox types, or if header caching is not
+  ** set up, you would need to re-open the message each time the
+  ** mailbox was reopened before you could see or search/limit on the
+  ** protected subject again.
+  ** .pp
+  ** When this variable is set, Mutt additionally saves the protected
+  ** Subject back \fBin the clear-text message headers\fP.  This
+  ** provides better usability, but with the tradeoff of reduced
+  ** security.  The protected Subject header, which may have
+  ** previously been encrypted, is now stored in clear-text in the
+  ** message headers.  Copying the message elsewhere, via Mutt or
+  ** external tools, could expose this previously encrypted data.
+  ** Please make sure you understand the consequences of this before
+  ** you enable this variable.
   ** (Crypto only)
    */
   { "crypt_protected_headers_write", DT_BOOL, R_NONE, OPTCRYPTPROTHDRSWRITE, 0 },
diff --git a/mutt.h b/mutt.h
index 3457156f1670e223859df413b6b89c3fde4fb60b..91c3b67b33b7fb6b44bf16b1d241d8e440d64dc1 100644 (file)
--- a/mutt.h
+++ b/mutt.h
@@ -542,6 +542,7 @@ enum
   OPTCRYPTCONFIRMHOOK,
   OPTCRYPTOPPORTUNISTICENCRYPT,
   OPTCRYPTPROTHDRSREAD,
+  OPTCRYPTPROTHDRSSAVE,
   OPTCRYPTPROTHDRSWRITE,
   OPTCRYPTREPLYENCRYPT,
   OPTCRYPTREPLYSIGN,
@@ -659,6 +660,7 @@ typedef struct alias
 #define MUTT_ENV_CHANGED_IRT     (1<<0)  /* In-Reply-To changed to link/break threads */
 #define MUTT_ENV_CHANGED_REFS    (1<<1)  /* References changed to break thread */
 #define MUTT_ENV_CHANGED_XLABEL  (1<<2)  /* X-Label edited */
+#define MUTT_ENV_CHANGED_SUBJECT (1<<3)  /* Protected header update */
 
 typedef struct envelope
 {