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. globals.h | 1 + init.h | 15 +++++++++++++++ mutt.h | 1 + send.c | 22 ++++++++++++++++++++++ 4 files changed, 39 insertions(+), 0 deletions(-)
# HG changeset patch # User Kevin McCarthy <[email protected]> # Date 1383772024 28800 # Wed Nov 06 13:07:04 2013 -0800 # Node ID 69a5326cbccd3c745e864fa068ea0ff086224bf1 # Parent 3306cb186f49e83edf15aac91c51f4c6131ef8fe 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 --- a/globals.h +++ b/globals.h @@ -103,16 +103,17 @@ WHERE char *PopAuthenticators INITVAL (NULL); WHERE short PopCheckTimeout; WHERE char *PopHost; WHERE char *PopPass INITVAL (NULL); WHERE char *PopUser INITVAL (NULL); #endif WHERE char *PostIndentString; WHERE char *Postponed; +WHERE char *PostponeEncryptAs; WHERE char *Prefix; WHERE char *PrintCmd; WHERE char *QueryCmd; WHERE char *QueryFormat; WHERE char *Realname; WHERE short SearchContext; WHERE char *SendCharset; WHERE char *Sendmail; diff --git a/init.h b/init.h --- a/init.h +++ b/init.h @@ -2116,16 +2116,31 @@ /* ** .pp ** Mutt allows you to indefinitely ``$postpone sending a message'' which ** you are editing. When you choose to postpone a message, Mutt saves it ** in the mailbox specified by this variable. ** .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}, /* ** .pp ** If \fIset\fP, a shell command to be executed if mutt fails to establish ** a connection to the server. This is useful for setting up secure ** connections, e.g. with \fCssh(1)\fP. If the command returns a nonzero ** status, mutt gives up opening the server. Example: diff --git a/mutt.h b/mutt.h --- a/mutt.h +++ b/mutt.h @@ -401,16 +401,17 @@ OPTNARROWTREE, OPTPAGERSTOP, OPTPIPEDECODE, OPTPIPESPLIT, #ifdef USE_POP OPTPOPAUTHTRYALL, OPTPOPLAST, #endif + OPTPOSTPONEENCRYPT, OPTPRINTDECODE, OPTPRINTSPLIT, OPTPROMPTAFTER, OPTREADONLY, OPTREFLOWTEXT, OPTREPLYSELF, OPTRESOLVE, OPTREVALIAS, diff --git a/send.c b/send.c --- a/send.c +++ b/send.c @@ -1550,16 +1550,38 @@ goto cleanup; } else if (i == 1) { /* postpone the message until later. */ 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. */ msg->read = 0; msg->old = 0; encode_descriptions (msg->content, 1); mutt_prepare_envelope (msg->env, 0);
