Óscar Pereira wrote:
> The subject seems pretty self-explanatory. Use case, you're writing
> an email, which is already marked as to be sent encrypted, but you
> have to postpone it. In the meantime offlineimap runs and syncs you
> mailboxes, and thus your mail which is to be sent encrypted ends up
> in (say) Gmail's remote folder -- UNencrypted.
> 
> Googling yielded only a question with no answer [1]. The only
> work-around I have to this is to disabled sync'ing the drafts folder
> altogether. Is there another way?

Sorry to resurrect an old (and somewhat heated) thread, but I'd like
some feedback on the interface for a patch I'd like to push (attached,
or see ticket #3665).  The patch was based off the one submitted by
Christian Brabandt, so thank you Christian!

The patch adds two options: postpone_encrypt (boolean) and
postpone_encrypt_as (string).

If postpone_encrypt is set, and the message has the encryption
flag set, mutt will encrypt the message using the key specified in
postpone_encrypt_as.  Currently, the interface is as simple as that.

I'm wondering if that is sufficient for people interested in the patch,
or whether a quadoption for postpone_encrypt would be more useful.  For
a quadoption, I would keep the behaviour the same: the quadoption would
only be consulted if the message encryption flag was set.

Would it be useful to be able to encrypt, even if the message encryption
flag is not set?  If so, I could use some opinions, because defining the
interface for that starts to get complicated.

Thanks,

-Kevin
# HG changeset patch
# User Kevin McCarthy <ke...@8t8.us>
# Date 1383772024 28800
#      Wed Nov 06 13:07:04 2013 -0800
# Node ID 4d4cee6396e31f67324b23d05054b55f5c5a8ed8
# Parent  cd57f8893b43a1d62e6cbf2488d399e97a66a0b2
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);

Attachment: signature.asc
Description: PGP signature

Reply via email to