From: Kevin McCarthy Date: Mon, 30 Mar 2015 22:45:54 +0000 (-0700) Subject: Add the crypt_opportunistic_encrypt option and calls. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=462e5df48915331bedbefc493df34d6a2f854f4b;p=neomutt Add the crypt_opportunistic_encrypt option and calls. This patch creates the OPTCRYPTOPPORTUNISTICENCRYPT option and documentation. It also adds calls to crypt_opportunistic_encrypt() during initial message composition, after updating to, cc, or bcc, and after editing the message (if edit_headers is enabled). --- diff --git a/compose.c b/compose.c index 9cfa2d404..021540f4b 100644 --- a/compose.c +++ b/compose.c @@ -526,14 +526,29 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ break; case OP_COMPOSE_EDIT_TO: menu->redraw = edit_address_list (HDR_TO, &msg->env->to); + if (option (OPTCRYPTOPPORTUNISTICENCRYPT)) + { + crypt_opportunistic_encrypt (msg); + redraw_crypt_lines (msg); + } mutt_message_hook (NULL, msg, M_SEND2HOOK); break; case OP_COMPOSE_EDIT_BCC: menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc); + if (option (OPTCRYPTOPPORTUNISTICENCRYPT)) + { + crypt_opportunistic_encrypt (msg); + redraw_crypt_lines (msg); + } mutt_message_hook (NULL, msg, M_SEND2HOOK); break; case OP_COMPOSE_EDIT_CC: menu->redraw = edit_address_list (HDR_CC, &msg->env->cc); + if (option (OPTCRYPTOPPORTUNISTICENCRYPT)) + { + crypt_opportunistic_encrypt (msg); + redraw_crypt_lines (msg); + } mutt_message_hook (NULL, msg, M_SEND2HOOK); break; case OP_COMPOSE_EDIT_SUBJECT: @@ -593,6 +608,8 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err); FREE (&err); } + if (option (OPTCRYPTOPPORTUNISTICENCRYPT)) + crypt_opportunistic_encrypt (msg); } else { diff --git a/crypt.c b/crypt.c index f02a31688..c3bba9739 100644 --- a/crypt.c +++ b/crypt.c @@ -770,6 +770,9 @@ void crypt_opportunistic_encrypt(HEADER *msg) { char *pgpkeylist = NULL; + if (!WithCrypto) + return; + /* crypt_autoencrypt should override crypt_opportunistic_encrypt */ if (option (OPTCRYPTAUTOENCRYPT)) return; diff --git a/init.h b/init.h index 8453c76b1..92ede4811 100644 --- a/init.h +++ b/init.h @@ -491,6 +491,27 @@ struct option_t MuttVars[] = { ** $$crypt_replyencrypt, ** $$crypt_autosign, $$crypt_replysign and $$smime_is_default. */ + { "crypt_opportunistic_encrypt", DT_BOOL, R_NONE, OPTCRYPTOPPORTUNISTICENCRYPT, 0 }, + /* + ** .pp + ** Setting this variable will cause Mutt to automatically enable and + ** disable encryption, based on whether all message recipient keys + ** can be located by mutt. + ** .pp + ** When this option is enabled, mutt will determine the encryption + ** setting each time the TO, CC, and BCC lists are edited. If + ** $$edit_headers is set, mutt will also do so each time the message + ** is edited. + ** .pp + ** While this is set, encryption settings can't be manually changed. + ** The pgp or smime menus provide an option to disable the option for + ** a particular message. + ** .pp + ** If $$crypt_autoencrypt or $$crypt_replyencrypt enable encryption for + ** a message, this option will be disabled for the message. It can + ** be manually re-enabled in the pgp or smime menus. + ** (Crypto only) + */ { "pgp_replyencrypt", DT_SYN, R_NONE, UL "crypt_replyencrypt", 1 }, { "crypt_replyencrypt", DT_BOOL, R_NONE, OPTCRYPTREPLYENCRYPT, 1 }, /* diff --git a/mutt.h b/mutt.h index 4fd6627e6..04238a02d 100644 --- a/mutt.h +++ b/mutt.h @@ -461,6 +461,7 @@ enum OPTCRYPTAUTOENCRYPT, OPTCRYPTAUTOPGP, OPTCRYPTAUTOSMIME, + OPTCRYPTOPPORTUNISTICENCRYPT, OPTCRYPTREPLYENCRYPT, OPTCRYPTREPLYSIGN, OPTCRYPTREPLYSIGNENCRYPTED, diff --git a/send.c b/send.c index c74b89f05..16db62bc9 100644 --- a/send.c +++ b/send.c @@ -1477,7 +1477,7 @@ ci_send_message (int flags, /* send mode */ msg->security |= INLINE; } - if (msg->security) + if (msg->security || option (OPTCRYPTOPPORTUNISTICENCRYPT)) { /* * When replying / forwarding, use the original message's @@ -1514,6 +1514,12 @@ ci_send_message (int flags, /* send mode */ } } + /* opportunistic encrypt relys on SMIME or PGP already being selected */ + if (option (OPTCRYPTOPPORTUNISTICENCRYPT)) + { + crypt_opportunistic_encrypt(msg); + } + /* No permissible mechanisms found. Don't sign or encrypt. */ if (!(msg->security & (APPLICATION_SMIME|APPLICATION_PGP))) msg->security = 0;