From: Mark Walters <markwalters1009@gmail.com>
To: notmuch@notmuchmail.org
Subject: [PATCH] emacs: mua: add a pre-send-check-hook
Date: Fri, 4 Nov 2016 18:00:19 +0000 [thread overview]
Message-ID: <1478282419-2771-1-git-send-email-markwalters1009@gmail.com> (raw)
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
next reply other threads:[~2016-11-04 18:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-04 18:00 Mark Walters [this message]
2016-11-07 21:12 ` [PATCH] emacs: mua: add a pre-send-check-hook Matt Armstrong
2016-11-13 7:36 ` Mark Walters
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1478282419-2771-1-git-send-email-markwalters1009@gmail.com \
--to=markwalters1009@gmail.com \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).