]> granicus.if.org Git - neomutt/commitdiff
Implement crypt_opportunistic_encrypt().
authorKevin McCarthy <kevin@8t8.us>
Mon, 30 Mar 2015 22:45:53 +0000 (15:45 -0700)
committerKevin McCarthy <kevin@8t8.us>
Mon, 30 Mar 2015 22:45:53 +0000 (15:45 -0700)
This function will be called to flip encryption on and off based on
message recipients.

crypt.c
mutt_crypt.h
send.c

diff --git a/crypt.c b/crypt.c
index 0d5f456c5eb9908c365db165cf4ec85dfe9abdd8..f02a316886d862f03b39524b26bdc9e8cec2eeef 100644 (file)
--- a/crypt.c
+++ b/crypt.c
@@ -707,7 +707,7 @@ void crypt_extract_keys_from_messages (HEADER * h)
 
 
 
-int crypt_get_keys (HEADER *msg, char **keylist)
+int crypt_get_keys (HEADER *msg, char **keylist, int oppenc_mode)
 {
   ADDRESS *adrlist = NULL, *last = NULL;
   const char *fqdn = mutt_fqdn (1);
@@ -732,12 +732,12 @@ int crypt_get_keys (HEADER *msg, char **keylist)
 
   *keylist = NULL;
 
-  if (msg->security & ENCRYPT)
+  if (oppenc_mode || (msg->security & ENCRYPT))
   {
      if ((WithCrypto & APPLICATION_PGP)
          && (msg->security & APPLICATION_PGP))
      {
-       if ((*keylist = crypt_pgp_findkeys (adrlist, 0)) == NULL)
+       if ((*keylist = crypt_pgp_findkeys (adrlist, oppenc_mode)) == NULL)
        {
            rfc822_free_address (&adrlist);
            return (-1);
@@ -747,7 +747,7 @@ int crypt_get_keys (HEADER *msg, char **keylist)
      if ((WithCrypto & APPLICATION_SMIME)
          && (msg->security & APPLICATION_SMIME))
      {
-       if ((*keylist = crypt_smime_findkeys (adrlist, 0)) == NULL)
+       if ((*keylist = crypt_smime_findkeys (adrlist, oppenc_mode)) == NULL)
        {
            rfc822_free_address (&adrlist);
            return (-1);
@@ -761,6 +761,32 @@ int crypt_get_keys (HEADER *msg, char **keylist)
 }
 
 
+/*
+ * Check if all recipients keys can be automatically determined.
+ * Enable encryption if they can, otherwise disable encryption.
+ */
+
+void crypt_opportunistic_encrypt(HEADER *msg)
+{
+  char *pgpkeylist = NULL;
+
+  /* crypt_autoencrypt should override crypt_opportunistic_encrypt */
+  if (option (OPTCRYPTAUTOENCRYPT))
+    return;
+
+  crypt_get_keys (msg, &pgpkeylist, 1);
+  if (pgpkeylist != NULL )
+  {
+    msg->security |= ENCRYPT;
+    FREE (&pgpkeylist);
+  }
+  else
+  {
+    msg->security &= ~ENCRYPT;
+  }
+}
+
+
 
 static void crypt_fetch_signatures (BODY ***signatures, BODY *a, int *n)
 {
index dc92ff3f03955acd0b75772a572373d39fe07426..7ef52e4b071e6a60aaf55b0601ad72345f7cb047 100644 (file)
@@ -140,8 +140,14 @@ void crypt_extract_keys_from_messages (HEADER *h);
 
 /* Do a quick check to make sure that we can find all of the
    encryption keys if the user has requested this service. 
-   Return the list of keys in KEYLIST. */
-int crypt_get_keys (HEADER *msg, char **keylist);
+   Return the list of keys in KEYLIST.
+   If oppenc_mode is true, only keys that can be determined without
+   prompting will be used.  */
+int crypt_get_keys (HEADER *msg, char **keylist, int oppenc_mode);
+
+/* Check if all recipients keys can be automatically determined.
+ * Enable encryption if they can, otherwise disable encryption.  */
+void crypt_opportunistic_encrypt(HEADER *msg);
 
 /* Forget a passphrase and display a message. */
 void crypt_forget_passphrase (void);
diff --git a/send.c b/send.c
index e28f267471cad0683f180a5877aa17fe8e7fa6c0..c74b89f05bc689b4bdf15314bd7ec7e87748ceb1 100644 (file)
--- a/send.c
+++ b/send.c
@@ -1668,7 +1668,7 @@ main_loop:
       /* save the decrypted attachments */
       clear_content = msg->content;
   
-      if ((crypt_get_keys (msg, &pgpkeylist) == -1) ||
+      if ((crypt_get_keys (msg, &pgpkeylist, 0) == -1) ||
           mutt_protect (msg, pgpkeylist) == -1)
       {
         msg->content = mutt_remove_multipart (msg->content);