unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] emacs: mua: add a pre-send-check-hook
@ 2016-11-04 18:00 Mark Walters
  2016-11-07 21:12 ` Matt Armstrong
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Walters @ 2016-11-04 18:00 UTC (permalink / raw)
  To: notmuch

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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-11-13  7:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-04 18:00 [PATCH] emacs: mua: add a pre-send-check-hook Mark Walters
2016-11-07 21:12 ` Matt Armstrong
2016-11-13  7:36   ` Mark Walters

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).