]> granicus.if.org Git - mutt/commitdiff
Change $postpone_encrypt to use self-encrypt variables first.
authorKevin McCarthy <kevin@8t8.us>
Mon, 29 May 2017 18:48:43 +0000 (11:48 -0700)
committerKevin McCarthy <kevin@8t8.us>
Mon, 29 May 2017 18:48:43 +0000 (11:48 -0700)
The concept of postpone encryption is similar to self-encrypting on
send.  The problem is the $postpone_encrypt_as option doesn't take
into account whether PGP or S/MIME is being used.

Since we need to add the new options for self-encryption, modify
$postpone_encrypt to use them by default instead, falling back to
$postpone_encrypt_as if they are unset.  Note $postpone_encrypt_as is
deprecated in the documentation.

init.h
send.c

diff --git a/init.h b/init.h
index 9150642de9a3ab2ee8548a0b9694732d1af82ca3..61c3bba4185c8dca3d51f7408b8bb8e31731f9ea 100644 (file)
--- a/init.h
+++ b/init.h
@@ -2070,7 +2070,8 @@ struct option_t MuttVars[] = {
   /*
   ** .pp
   ** This is an additional key used to encrypt messages when $$pgp_self_encrypt
-  ** is \fIset\fP.  It should be in keyid or fingerprint form (e.g. 0x00112233).
+  ** is \fIset\fP.  It is also used to specify the key for $$postpone_encrypt.
+  ** It should be in keyid or fingerprint form (e.g. 0x00112233).
   ** (PGP only)
   */
   { "pgp_show_unusable", DT_BOOL, R_NONE, OPTPGPSHOWUNUSABLE, 1 },
@@ -2292,15 +2293,16 @@ struct option_t MuttVars[] = {
   /*
   ** .pp
   ** When \fIset\fP, postponed messages that are marked for encryption will be
-  ** encrypted using the key in $$postpone_encrypt_as before saving.
+  ** self-encrypted.  Mutt will first try to encrypt using the value specified
+  ** in $$pgp_self_encrypt_as or $$smime_self_encrypt_as.  If those are not
+  ** set, it will try the deprecated $$postpone_encrypt_as.
   ** (Crypto only)
   */
   { "postpone_encrypt_as", DT_STR,  R_NONE, UL &PostponeEncryptAs, 0 },
   /*
   ** .pp
-  ** This is the key used to encrypt postponed messages.  It should be in
-  ** keyid or fingerprint form (e.g. 0x00112233 for PGP or the
-  ** hash-value that OpenSSL generates for S/MIME).
+  ** This is a deprecated fall-back variable for $$postpone_encrypt.
+  ** Please use $$pgp_self_encrypt_as or $$smime_self_encrypt_as.
   ** (Crypto only)
   */
 #ifdef USE_SOCKET
@@ -3121,8 +3123,9 @@ struct option_t MuttVars[] = {
   /*
   ** .pp
   ** This is an additional certificate used to encrypt messages when
-  ** $$smime_self_encrypt is \fIset\fP.  It should be the
-  ** hash-value that OpenSSL generates.
+  ** $$smime_self_encrypt is \fIset\fP.  It is also used to specify the
+  ** certficate for $$postpone_encrypt.  It should be the hash-value that
+  ** OpenSSL generates.
   ** (S/MIME only)
   */
   { "smime_sign_command",      DT_STR, R_NONE, UL &SmimeSignCommand, 0},
diff --git a/send.c b/send.c
index acf27e854e8304504bd5387fe23e987c0bd47077..535b8dceb6ddbf90a59aaa5f022db0b15c7b9b4b 100644 (file)
--- a/send.c
+++ b/send.c
@@ -1599,26 +1599,37 @@ main_loop:
       if (msg->content->next)
        msg->content = mutt_make_multipart (msg->content);
 
-      if (WithCrypto && option (OPTPOSTPONEENCRYPT) && PostponeEncryptAs
-          && (msg->security & ENCRYPT))
+      if (WithCrypto && option (OPTPOSTPONEENCRYPT) && (msg->security & ENCRYPT))
       {
-        int is_signed = msg->security & SIGN;
-        if (is_signed)
-          msg->security &= ~SIGN;
+        char *encrypt_as = NULL;
 
-        pgpkeylist = safe_strdup (PostponeEncryptAs);
-        if (mutt_protect (msg, pgpkeylist) == -1)
+        if ((WithCrypto & APPLICATION_PGP) && (msg->security & APPLICATION_PGP))
+          encrypt_as = PgpSelfEncryptAs;
+        else if ((WithCrypto & APPLICATION_SMIME) && (msg->security & APPLICATION_SMIME))
+          encrypt_as = SmimeSelfEncryptAs;
+        if (!(encrypt_as && *encrypt_as))
+          encrypt_as = PostponeEncryptAs;
+
+        if (encrypt_as && *encrypt_as)
         {
+          int is_signed = msg->security & SIGN;
+          if (is_signed)
+            msg->security &= ~SIGN;
+
+          pgpkeylist = safe_strdup (encrypt_as);
+          if (mutt_protect (msg, pgpkeylist) == -1)
+          {
+            if (is_signed)
+              msg->security |= SIGN;
+            FREE (&pgpkeylist);
+            msg->content = mutt_remove_multipart (msg->content);
+            goto main_loop;
+          }
+
           if (is_signed)
             msg->security |= SIGN;
           FREE (&pgpkeylist);
-          msg->content = mutt_remove_multipart (msg->content);
-          goto main_loop;
         }
-
-        if (is_signed)
-          msg->security |= SIGN;
-        FREE (&pgpkeylist);
       }
 
       /*