[PATCH] Allow setting message security in send2-hook
send.c | 141 ++++++++++++++++++++++++++++++++++------------------------------
1 files changed, 74 insertions(+), 67 deletions(-)
# HG changeset patch
# User Michael Elkins <me@xxxxxxxx>
# Date 1271256016 25200
# Branch HEAD
# Node ID 407f5ba3f6dd1a3adfe6d2ee2ea86e180e9d2ea6
# Parent de870968fd38a3afaee1831bd0432bd2f4a4b722
Allow setting message security in send2-hook
This patch delays checking the message security options until after the user
has an initial chance to edit the message. This allows the security options to
be set in a send2-hook when using $edit_headers. Without this patch, the user
has no way of automatically setting security based on recipients since the
to/cc prompts are bypassed.
The other change in behavior is if the user happened to use a send2-hook to see
if the message had security applied *prior* to editing the message, that no
longer works.
diff --git a/send.c b/send.c
--- a/send.c
+++ b/send.c
@@ -1332,73 +1332,6 @@
if (!option (OPTSIGONTOP) && ! (flags & (SENDMAILX|SENDKEY|SENDBATCH))
&& Editor && mutt_strcmp (Editor, "builtin") != 0)
append_signature (tempfp);
-
- /*
- * this wants to be done _after_ generate_body, so message-hooks
- * can take effect.
- */
-
- if (WithCrypto && !(flags & (SENDMAILX|SENDBATCH)))
- {
- if (option (OPTCRYPTAUTOSIGN))
- msg->security |= SIGN;
- if (option (OPTCRYPTAUTOENCRYPT))
- msg->security |= ENCRYPT;
- if (option (OPTCRYPTREPLYENCRYPT) && cur && (cur->security & ENCRYPT))
- msg->security |= ENCRYPT;
- if (option (OPTCRYPTREPLYSIGN) && cur && (cur->security & SIGN))
- msg->security |= SIGN;
- if (option (OPTCRYPTREPLYSIGNENCRYPTED) && cur && (cur->security &
ENCRYPT))
- msg->security |= SIGN;
- if (WithCrypto & APPLICATION_PGP && (msg->security & (ENCRYPT | SIGN)))
- {
- if (option (OPTPGPAUTOINLINE))
- msg->security |= INLINE;
- if (option (OPTPGPREPLYINLINE) && cur && (cur->security & INLINE))
- msg->security |= INLINE;
- }
- }
-
- if (WithCrypto && msg->security)
- {
- /*
- * When replying / forwarding, use the original message's
- * crypto system. According to the documentation,
- * smime_is_default should be disregarded here.
- *
- * Problem: At least with forwarding, this doesn't really
- * make much sense. Should we have an option to completely
- * disable individual mechanisms at run-time?
- */
- if (cur)
- {
- if ((WithCrypto & APPLICATION_PGP) && option (OPTCRYPTAUTOPGP)
- && (cur->security & APPLICATION_PGP))
- msg->security |= APPLICATION_PGP;
- else if ((WithCrypto & APPLICATION_SMIME) && option (OPTCRYPTAUTOSMIME)
- && (cur->security & APPLICATION_SMIME))
- msg->security |= APPLICATION_SMIME;
- }
-
- /*
- * No crypto mechanism selected? Use availability + smime_is_default
- * for the decision.
- */
- if (!(msg->security & (APPLICATION_SMIME | APPLICATION_PGP)))
- {
- if ((WithCrypto & APPLICATION_SMIME) && option (OPTCRYPTAUTOSMIME)
- && option (OPTSMIMEISDEFAULT))
- msg->security |= APPLICATION_SMIME;
- else if ((WithCrypto & APPLICATION_PGP) && option (OPTCRYPTAUTOPGP))
- msg->security |= APPLICATION_PGP;
- else if ((WithCrypto & APPLICATION_SMIME) && option (OPTCRYPTAUTOSMIME))
- msg->security |= APPLICATION_SMIME;
- }
- }
-
- /* No permissible mechanisms found. Don't sign or encrypt. */
- if (!(msg->security & (APPLICATION_SMIME|APPLICATION_PGP)))
- msg->security = 0;
}
/*
@@ -1493,6 +1426,80 @@
}
}
+ /*
+ * Set the message security unless:
+ * 1) crypto support is not enabled (WithCrypto==0)
+ * 2) pgp: header field was present during message editing with
$edit_headers (msg->security != 0)
+ * 3) we are resending a message
+ * 4) we are recalling a postponed message (don't override the user's saved
settings)
+ * 5) we are in mailx mode
+ * 6) we are in batch mode
+ *
+ * This is done after allowing the user to edit the message so that security
+ * settings can be configured with send2-hook and $edit_headers.
+ */
+ if (WithCrypto && (msg->security == 0) && !(flags & (SENDBATCH | SENDMAILX |
SENDPOSTPONED | SENDRESEND)))
+ {
+ if (option (OPTCRYPTAUTOSIGN))
+ msg->security |= SIGN;
+ if (option (OPTCRYPTAUTOENCRYPT))
+ msg->security |= ENCRYPT;
+ if (option (OPTCRYPTREPLYENCRYPT) && cur && (cur->security & ENCRYPT))
+ msg->security |= ENCRYPT;
+ if (option (OPTCRYPTREPLYSIGN) && cur && (cur->security & SIGN))
+ msg->security |= SIGN;
+ if (option (OPTCRYPTREPLYSIGNENCRYPTED) && cur && (cur->security &
ENCRYPT))
+ msg->security |= SIGN;
+ if (WithCrypto & APPLICATION_PGP && (msg->security & (ENCRYPT | SIGN)))
+ {
+ if (option (OPTPGPAUTOINLINE))
+ msg->security |= INLINE;
+ if (option (OPTPGPREPLYINLINE) && cur && (cur->security & INLINE))
+ msg->security |= INLINE;
+ }
+
+ if (msg->security)
+ {
+ /*
+ * When replying / forwarding, use the original message's
+ * crypto system. According to the documentation,
+ * smime_is_default should be disregarded here.
+ *
+ * Problem: At least with forwarding, this doesn't really
+ * make much sense. Should we have an option to completely
+ * disable individual mechanisms at run-time?
+ */
+ if (cur)
+ {
+ if ((WithCrypto & APPLICATION_PGP) && option (OPTCRYPTAUTOPGP)
+ && (cur->security & APPLICATION_PGP))
+ msg->security |= APPLICATION_PGP;
+ else if ((WithCrypto & APPLICATION_SMIME) && option (OPTCRYPTAUTOSMIME)
+ && (cur->security & APPLICATION_SMIME))
+ msg->security |= APPLICATION_SMIME;
+ }
+
+ /*
+ * No crypto mechanism selected? Use availability + smime_is_default
+ * for the decision.
+ */
+ if (!(msg->security & (APPLICATION_SMIME | APPLICATION_PGP)))
+ {
+ if ((WithCrypto & APPLICATION_SMIME) && option (OPTCRYPTAUTOSMIME)
+ && option (OPTSMIMEISDEFAULT))
+ msg->security |= APPLICATION_SMIME;
+ else if ((WithCrypto & APPLICATION_PGP) && option (OPTCRYPTAUTOPGP))
+ msg->security |= APPLICATION_PGP;
+ else if ((WithCrypto & APPLICATION_SMIME) && option (OPTCRYPTAUTOSMIME))
+ msg->security |= APPLICATION_SMIME;
+ }
+ }
+
+ /* No permissible mechanisms found. Don't sign or encrypt. */
+ if (!(msg->security & (APPLICATION_SMIME|APPLICATION_PGP)))
+ msg->security = 0;
+ }
+
/* specify a default fcc. if we are in batchmode, only save a copy of
* the message if the value of $copy is yes or ask-yes */