]> granicus.if.org Git - neomutt/commitdiff
Fix the PGP / S/MIME selection mess in send.c. This patch adds two
authorThomas Roessler <roessler@does-not-exist.org>
Mon, 14 Apr 2003 09:09:53 +0000 (09:09 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Mon, 14 Apr 2003 09:09:53 +0000 (09:09 +0000)
new configuration variables, $crypt_autopgp and $crypt_autsmime.
Both are set to "yes" by default.  By turning them off, you can
disable the automatic selection of one or both mechanisms.  (Useful
when your mutt is PGP- and S/MIME enabled, but you only use, say
S/MIME.)

init.h
mutt.h
send.c

diff --git a/init.h b/init.h
index 10e66ab9ef423a1d68b7f71540c9df546fdfaa79..cf73f6bd2f8ce9b1739fb5d1b2e40d411fb623a5 100644 (file)
--- a/init.h
+++ b/init.h
@@ -359,6 +359,22 @@ struct option_t MuttVars[] = {
   ** will be saved for later references.  Also see ``$$record'',
   ** ``$$save_name'', ``$$force_name'' and ``$fcc-hook''.
   */
+  { "crypt_autopgp",   DT_BOOL, R_NONE, OPTCRYPTAUTOPGP, 1 },
+  /*
+  ** .pp
+  ** This variable controls whether or not mutt may automatically enable
+  ** PGP encryption/signing for messages.  See also ``$$crypt_autoencrypt'',
+  ** ``$$crypt_replyencrypt'',
+  ** ``$$crypt_autosign'', ``$$crypt_replysign'' and ``$$smime_is_default''.
+  */
+  { "crypt_autosmime", DT_BOOL, R_NONE, OPTCRYPTAUTOSMIME, 1 },
+  /*
+  ** .pp
+  ** This variable controls whether or not mutt may automatically enable
+  ** S/MIME encryption/signing for messages. See also ``$$crypt_autoencrypt'',
+  ** ``$$crypt_replyencrypt'',
+  ** ``$$crypt_autosign'', ``$$crypt_replysign'' and ``$$smime_is_default''.
+  */
   { "date_format",     DT_STR,  R_BOTH, UL &DateFmt, UL "!%a, %b %d, %Y at %I:%M:%S%p %Z" },
   /*
   ** .pp
@@ -1199,7 +1215,7 @@ struct option_t MuttVars[] = {
   ** Setting this variable will cause Mutt to always attempt to
   ** cryptographically sign outgoing messages.  This can be overridden
   ** by use of the \fIpgp-menu\fP, when signing is not required or
-  ** encryption is requested as well. IF ``$$smime_is_default'' is set,
+  ** encryption is requested as well. If ``$$smime_is_default'' is set,
   ** then OpenSSL is used instead to create S/MIME messages and settings can
   ** be overridden by use of the \fIsmime-menu\fP.
   ** (Crypto only)
@@ -1287,7 +1303,7 @@ struct option_t MuttVars[] = {
   ** operations. To override and to use OpenSSL instead this must be set.
   ** However, this has no effect while replying, since mutt will automatically 
   ** select the same application that was used to sign/encrypt the original
-  ** message.
+  ** message.  (Note that this variable can be overridden by unsetting $$crypt_autosmime.)
   ** (S/MIME only)
   */
   { "smime_ask_cert_label",    DT_BOOL, R_NONE, OPTASKCERTLABEL, 1 },
diff --git a/mutt.h b/mutt.h
index 9d6629c9c7e0a1422411a4a91b2d52cd372f474f..6494f39cbea0728a0973c563de2855ac7e54d9c3 100644 (file)
--- a/mutt.h
+++ b/mutt.h
@@ -427,6 +427,8 @@ enum
   
   OPTCRYPTAUTOSIGN,
   OPTCRYPTAUTOENCRYPT,
+  OPTCRYPTAUTOPGP,
+  OPTCRYPTAUTOSMIME,
   OPTCRYPTREPLYENCRYPT,
   OPTCRYPTREPLYSIGN,
   OPTCRYPTREPLYSIGNENCRYPTED,
diff --git a/send.c b/send.c
index c73e5576f31079d2e62ee4c2e8820ff3d2b5f0d3..0ff54ac4054aa7bcc952f32289faa98fb1481282 100644 (file)
--- a/send.c
+++ b/send.c
@@ -1250,36 +1250,50 @@ ci_send_message (int flags,             /* send mode */
        msg->security |= ENCRYPT;
       if (option (OPTCRYPTREPLYSIGN) && cur && (cur->security & SIGN))
        msg->security |= SIGN;
-      if (option (OPTCRYPTREPLYSIGNENCRYPTED) && cur && cur->security & ENCRYPT)
+      if (option (OPTCRYPTREPLYSIGNENCRYPTED) && cur && (cur->security & ENCRYPT))
        msg->security |= SIGN;
     }      
 
-    if (WithCrypto && msg->security && cur)
+    if (WithCrypto && msg->security)
     {
-      if ((WithCrypto & APPLICATION_SMIME)
-          && ((cur->security & APPLICATION_SMIME)
-              || option (OPTSMIMEISDEFAULT)))
-        msg->security |= APPLICATION_SMIME;
-
-      if ((WithCrypto & APPLICATION_PGP) && (cur->security & APPLICATION_PGP))
+      /* 
+       * When reypling / forwarding, use the original message's
+       * crypto system.  According to the documentation,
+       * smime_is_default should be disregarded here.
+       * 
+       * Problem: At least with forwarding, this doesn't really
+       * make much sense. Should we have an option to completely
+       * disable individual mechanisms at run-time?
+       */
+      if (cur)
       {
-       msg->security &= ~APPLICATION_SMIME;
-        msg->security |= APPLICATION_PGP;
+       if ((WithCrypto & APPLICATION_PGP) && option (OPTCRYPTAUTOPGP) 
+           && (cur->security & APPLICATION_PGP))
+         msg->security |= APPLICATION_PGP;
+       else if ((WithCrypto & APPLICATION_SMIME) && option (OPTCRYPTAUTOSMIME)
+                && (cur->security & APPLICATION_SMIME))
+         msg->security |= APPLICATION_SMIME;
       }
-      if ((WithCrypto & APPLICATION_SMIME)
-          && !(cur->security & (APPLICATION_PGP|APPLICATION_SMIME)))
-       msg->security |= APPLICATION_PGP;
-    }
-    else if ((WithCrypto & APPLICATION_PGP) && msg->security)
-    {
-      msg->security |= APPLICATION_PGP;
-      if ((WithCrypto & APPLICATION_SMIME) && option (OPTSMIMEISDEFAULT))
+      
+      /*
+       * No crypto mechanism selected? Use availability + smime_is_default
+       * for the decision. 
+       */
+      if (!(msg->security & (APPLICATION_SMIME | APPLICATION_PGP)))
       {
-        msg->security |= APPLICATION_SMIME;
-        msg->security &= ~APPLICATION_PGP;
+       if ((WithCrypto & APPLICATION_SMIME) && option (OPTCRYPTAUTOSMIME) 
+           && option (OPTSMIMEISDEFAULT))
+         msg->security |= APPLICATION_SMIME;
+       else if ((WithCrypto & APPLICATION_PGP) && option (OPTCRYPTAUTOPGP))
+         msg->security |= APPLICATION_PGP;
+       else if ((WithCrypto & APPLICATION_SMIME) && option (OPTCRYPTAUTOSMIME))
+         msg->security |= APPLICATION_SMIME;
       }
     }
-
+    
+    /* No permissible mechanisms found.  Don't sign or encrypt. */
+    if (!(msg->security & (APPLICATION_SMIME|APPLICATION_PGP)))
+      msg->security = 0;
   }
   /* wait until now to set the real name portion of our return address so
      that $realname can be set in a send-hook */