From: Thomas Roessler Date: Mon, 14 Apr 2003 09:09:53 +0000 (+0000) Subject: Fix the PGP / S/MIME selection mess in send.c. This patch adds two X-Git-Tag: pre-type-punning-patch~89 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=04c7eb0ebc79b25a4db023ca4c640c1b8cc40a74;p=mutt Fix the PGP / S/MIME selection mess in send.c. This patch adds two 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.) --- diff --git a/init.h b/init.h index 10e66ab9..cf73f6bd 100644 --- 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 9d6629c9..6494f39c 100644 --- 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 c73e5576..0ff54ac4 100644 --- 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 */