]> granicus.if.org Git - neomutt/commitdiff
Add the crypt_opportunistic_encrypt option and calls.
authorKevin McCarthy <kevin@8t8.us>
Mon, 30 Mar 2015 22:45:54 +0000 (15:45 -0700)
committerKevin McCarthy <kevin@8t8.us>
Mon, 30 Mar 2015 22:45:54 +0000 (15:45 -0700)
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).

compose.c
crypt.c
init.h
mutt.h
send.c

index 9cfa2d404257e2ecaa652cd7e8cf17144117b3db..021540f4b5c1caa2a91a24583a58a9efc5bb59a4 100644 (file)
--- 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 f02a316886d862f03b39524b26bdc9e8cec2eeef..c3bba9739baa1c900c0e734b757e31d83a980626 100644 (file)
--- 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 8453c76b1ab94c09de8d32b56d9f47f943b69a69..92ede4811a3e156e15b4941bc5cd421796fe842a 100644 (file)
--- 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 4fd6627e6df41c10c90dbff36516d981505d8275..04238a02d6345ec14b9f048678592d0103eccae3 100644 (file)
--- 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 c74b89f05bc689b4bdf15314bd7ec7e87748ceb1..16db62bc9621d4806090ebeb62cee1b5b4108fd1 100644 (file)
--- 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;