From: Kevin McCarthy Date: Mon, 29 May 2017 18:48:43 +0000 (-0700) Subject: Change $postpone_encrypt to use self-encrypt variables first. X-Git-Tag: neomutt-20170602~2^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=554d5d5600f312e82dbcf925caf6fa600f4476d7;p=neomutt Change $postpone_encrypt to use self-encrypt variables first. The concept of postpone encryption is similar to self-encrypting on send. The problem is the $postpone_encrypt_as option doesn't take into account whether PGP or S/MIME is being used. Since we need to add the new options for self-encryption, modify $postpone_encrypt to use them by default instead, falling back to $postpone_encrypt_as if they are unset. Note $postpone_encrypt_as is deprecated in the documentation. --- diff --git a/init.h b/init.h index 07742dece..f53e4e156 100644 --- a/init.h +++ b/init.h @@ -2459,7 +2459,8 @@ struct Option MuttVars[] = { /* ** .pp ** This is an additional key used to encrypt messages when $$pgp_self_encrypt - ** is \fIset\fP. It should be in keyid or fingerprint form (e.g. 0x00112233). + ** is \fIset\fP. It is also used to specify the key for $$postpone_encrypt. + ** It should be in keyid or fingerprint form (e.g. 0x00112233). ** (PGP only) */ { "pgp_show_unusable", DT_BOOL, R_NONE, OPTPGPSHOWUNUSABLE, 1 }, @@ -2691,15 +2692,16 @@ struct Option MuttVars[] = { /* ** .pp ** When \fIset\fP, postponed messages that are marked for encryption will be - ** encrypted using the key in $$postpone_encrypt_as before saving. + ** self-encrypted. Mutt will first try to encrypt using the value specified + ** in $$pgp_self_encrypt_as or $$smime_self_encrypt_as. If those are not + ** set, it will try the deprecated $$postpone_encrypt_as. ** (Crypto only) */ { "postpone_encrypt_as", DT_STR, R_NONE, UL &PostponeEncryptAs, 0 }, /* ** .pp - ** This is the key used to encrypt postponed messages. It should be in - ** keyid or fingerprint form (e.g. 0x00112233 for PGP or the - ** hash-value that OpenSSL generates for S/MIME). + ** This is a deprecated fall-back variable for $$postpone_encrypt. + ** Please use $$pgp_self_encrypt_as or $$smime_self_encrypt_as. ** (Crypto only) */ #ifdef USE_SOCKET @@ -3567,8 +3569,9 @@ struct Option MuttVars[] = { /* ** .pp ** This is an additional certificate used to encrypt messages when - ** $$smime_self_encrypt is \fIset\fP. It should be the - ** hash-value that OpenSSL generates. + ** $$smime_self_encrypt is \fIset\fP. It is also used to specify the + ** certficate for $$postpone_encrypt. It should be the hash-value that + ** OpenSSL generates. ** (S/MIME only) */ { "smime_sign_command", DT_STR, R_NONE, UL &SmimeSignCommand, 0 }, diff --git a/send.c b/send.c index c8702648b..453c9bb87 100644 --- a/send.c +++ b/send.c @@ -1828,26 +1828,37 @@ int ci_send_message(int flags, /* send mode */ if (msg->content->next) msg->content = mutt_make_multipart(msg->content); - if (WithCrypto && option(OPTPOSTPONEENCRYPT) && PostponeEncryptAs && - (msg->security & ENCRYPT)) + if (WithCrypto && option(OPTPOSTPONEENCRYPT) && (msg->security & ENCRYPT)) { - int is_signed = msg->security & SIGN; - if (is_signed) - msg->security &= ~SIGN; + char *encrypt_as = NULL; - pgpkeylist = safe_strdup(PostponeEncryptAs); - if (mutt_protect(msg, pgpkeylist) == -1) + if ((WithCrypto & APPLICATION_PGP) && (msg->security & APPLICATION_PGP)) + encrypt_as = PgpSelfEncryptAs; + else if ((WithCrypto & APPLICATION_SMIME) && (msg->security & APPLICATION_SMIME)) + encrypt_as = SmimeSelfEncryptAs; + if (!(encrypt_as && *encrypt_as)) + encrypt_as = PostponeEncryptAs; + + if (encrypt_as && *encrypt_as) { + int is_signed = msg->security & SIGN; + if (is_signed) + msg->security &= ~SIGN; + + pgpkeylist = safe_strdup(encrypt_as); + if (mutt_protect(msg, pgpkeylist) == -1) + { + if (is_signed) + msg->security |= SIGN; + FREE(&pgpkeylist); + msg->content = mutt_remove_multipart(msg->content); + goto main_loop; + } + if (is_signed) msg->security |= SIGN; FREE(&pgpkeylist); - msg->content = mutt_remove_multipart(msg->content); - goto main_loop; } - - if (is_signed) - msg->security |= SIGN; - FREE(&pgpkeylist); } /*