]> granicus.if.org Git - neomutt/commitdiff
Add option to encrypt postponed messages. (closes #3665)
authorKevin McCarthy <kevin@8t8.us>
Wed, 6 Nov 2013 21:07:04 +0000 (13:07 -0800)
committerKevin McCarthy <kevin@8t8.us>
Wed, 6 Nov 2013 21:07:04 +0000 (13:07 -0800)
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
init.h
mutt.h
send.c

index 6685c1253ed44f1c354d893f275100a567c8cf76..c43cef7fd07f5e6864461734a834c070b0c46f44 100644 (file)
--- 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 f1f46c3dc58535ee9718ac1f36467ce16a3b3941..cbd707513ca9159e2f4226ec09714379ec981183 100644 (file)
--- 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 9dc123ad3679860edc368f1380ba04806345dbc9..4fd6627e6df41c10c90dbff36516d981505d8275 100644 (file)
--- 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 fce003c03e502aca777b79964ac987a648ac98d3..3f81dc7dc954b502e974b87666d1b0e58c4d5aea 100644 (file)
--- 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.