[PATCH] emacs: mua: add a pre-send-check-hook
Mark Walters
markwalters1009 at gmail.com
Fri Nov 4 11:00:19 PDT 2016
This add a pre-send hook for any checks the user wants to run before
sending the message. If any function in the hook returns nil then the
send will abort.
One use would be to check that the from address is appropriate for the
recipients (i.e., test From: based on To: and Cc:), but many other
uses are possible: checking spelling, checking that the message is set
to be encrypted etc.
---
bremner and I were discussing the address-completion-hook on irc, and
before he implemented that I suggested an alternative of adding a
pre-send-check-hook. The idea is that functions in this hook can force
abort sending (or at least get confirmation from the user) based on
the message.
For example I would be quite likely to use something like the
following in the hook.
(lambda ()
(save-excursion
(save-restriction
(let ((to (message-fetch-field "To"))
(from (message-fetch-field "From"))
(case-fold-search t))
(or (not (string-match "work-domain-address" to))
(string= from "my-work-address")
(yes-or-no-p "Message to work but not from work address. Really send? "))))))
I think this is reasonably orthogonal to the
notmuch-address-completion-hook. Setting the from address based on the
to addresses makes a lot of sense, but checking on send also does --
if the from is correct then the check is silent, and if the user types
in the To: without using completion then the check will catch it.
Best wishes
Mark
emacs/notmuch-mua.el | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index f333655..78130e6 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -36,6 +36,15 @@
;;
+(defcustom notmuch-mua-pre-send-check-hook nil
+ "Hook of checks run before sending messages.
+
+If any of the functions in the hook return nil then the send will
+be aborted."
+ :type 'hook
+ :group 'notmuch-send
+ :group 'notmuch-hooks)
+
(defcustom notmuch-mua-send-hook '(notmuch-mua-message-send-hook)
"Hook run before sending messages."
:type 'hook
@@ -538,7 +547,8 @@ unencrypted. Really send? "))))
(defun notmuch-mua-send-common (arg &optional exit)
(interactive "P")
- (when (and (notmuch-mua-check-no-misplaced-secure-tag)
+ (when (and (run-hook-with-args-until-failure 'notmuch-mua-pre-send-check-hook)
+ (notmuch-mua-check-no-misplaced-secure-tag)
(notmuch-mua-check-secure-tag-has-newline))
(letf (((symbol-function 'message-do-fcc) #'notmuch-maildir-message-do-fcc))
(if exit
--
2.1.4
More information about the notmuch
mailing list