From: Kevin McCarthy Date: Wed, 6 Nov 2013 21:07:04 +0000 (-0800) Subject: Add option to encrypt postponed messages. (closes #3665) X-Git-Tag: neomutt-20160307~109 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=88f7077913885b7e07fdbc423d50dee69f932821;p=neomutt Add option to encrypt postponed messages. (closes #3665) This patch is based on Christian Brabandt's patch sent to mutt-users. Add two new configuration variables: $postpone_encrypt and $postpone_encrypt_as. When $postpone_encrypt is set and a message is marked for encryption, the message will be encrypted using the key specified in $postpone_encrypt_as before saving the message. In this patch, $postpone_encrypt_as must be specified. I experimented with passing safe_strdup( NONULL (PostponeEncryptAs)) when unspecified, but although gpg.conf has a default-key setting, I could not get it to work properly. (pgpclassic gave an error message and gpgme sefaulted.) Although not necessary, this patch turns off signing during encryption of the postponed message (and turns it back on before saving), since there is no need to sign the message yet. --- diff --git a/globals.h b/globals.h index 6685c1253..c43cef7fd 100644 --- a/globals.h +++ b/globals.h @@ -108,6 +108,7 @@ WHERE char *PopUser INITVAL (NULL); #endif WHERE char *PostIndentString; WHERE char *Postponed; +WHERE char *PostponeEncryptAs; WHERE char *Prefix; WHERE char *PrintCmd; WHERE char *QueryCmd; diff --git a/init.h b/init.h index f1f46c3dc..cbd707513 100644 --- a/init.h +++ b/init.h @@ -2121,6 +2121,21 @@ struct option_t MuttVars[] = { ** .pp ** Also see the $$postpone variable. */ + { "postpone_encrypt", DT_BOOL, R_NONE, OPTPOSTPONEENCRYPT, 0 }, + /* + ** .pp + ** When \fIset\fP, postponed messages that are marked for encryption will be + ** encrypted using the key in $$postpone_encrypt_as before saving. + ** (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 form (e.g. 0x00112233 for PGP or the hash-value that OpenSSL + ** generates for S/MIME). + ** (Crypto only) + */ #ifdef USE_SOCKET { "preconnect", DT_STR, R_NONE, UL &Preconnect, UL 0}, /* diff --git a/mutt.h b/mutt.h index 9dc123ad3..4fd6627e6 100644 --- a/mutt.h +++ b/mutt.h @@ -406,6 +406,7 @@ enum OPTPOPAUTHTRYALL, OPTPOPLAST, #endif + OPTPOSTPONEENCRYPT, OPTPRINTDECODE, OPTPRINTSPLIT, OPTPROMPTAFTER, diff --git a/send.c b/send.c index fce003c03..3f81dc7dc 100644 --- a/send.c +++ b/send.c @@ -1555,6 +1555,28 @@ main_loop: if (msg->content->next) msg->content = mutt_make_multipart (msg->content); + if (WithCrypto && option (OPTPOSTPONEENCRYPT) && PostponeEncryptAs + && (msg->security & ENCRYPT)) + { + int is_signed = msg->security & SIGN; + if (is_signed) + msg->security &= ~SIGN; + + pgpkeylist = safe_strdup (PostponeEncryptAs); + 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); + } + /* * make sure the message is written to the right part of a maildir * postponed folder.