-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);
*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);
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);
}
+/*
+ * 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)
{
/* 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);
/* 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);