From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 5D6996DE0159 for ; Fri, 4 Nov 2016 11:00:45 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.393 X-Spam-Level: X-Spam-Status: No, score=-0.393 tagged_above=-999 required=5 tests=[AWL=-0.523, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kI2bVgahkwaN for ; Fri, 4 Nov 2016 11:00:41 -0700 (PDT) Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by arlo.cworth.org (Postfix) with ESMTPS id 6D3B06DE00D3 for ; Fri, 4 Nov 2016 11:00:41 -0700 (PDT) Received: by mail-wm0-f65.google.com with SMTP id 68so5033566wmz.2 for ; Fri, 04 Nov 2016 11:00:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=eXB+HkS9KX/I2lbo+bYbv6Nn7Ff/1XnOcSmceN4sF2o=; b=XH65mOmh3YokEVUUhopXHnRh/h/ExDdkY+18w06KyIxI4lzEDfWCkCLkYhmGCkYatQ wH3Z7wmwuh3XdTG9F+R3il1axJN806/Sm1s7yt76GPe5GRr7jsxcMYO6ybXji5hTV+Ra aUUEoAEjdys8p53Wzo5lukzsOviItMgRdo7xc110OvRc4lcRBiZRMkOJdhy/mgc0SvHP mEYmRPsT13bx3I5gm+Vkg7v5rVddZse1ks4QHWaf8zvGM6W5w8v1Ayp51nQ3UvLIvSWe fdx3Tmm/O3d5OVSJgnQ4QFrRkRbX2LR2BXdrP73M3a2Xo3HQh0yiu757dWuXvWjAdUIt ts+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=eXB+HkS9KX/I2lbo+bYbv6Nn7Ff/1XnOcSmceN4sF2o=; b=U/9kiBJs7uT10HatGsB78+XBJ0QS0TPav7/4KNWDbP4m36XfjXYifNlghioVwUhtcn vubUH6vMcYCcKlMKs5Slk8gqjGjYa1jc23pinL0PPinK4kOGorMS3UFJ/DWjH1g87S+j fZYZooPD5q2bQAvML8gtUdnJ8+UkdzXcxq6UKwkBGNr7GNTW4Eeh34PMJEnM2MJxE3Yc 5V4oAvvgg8xmxmYHswn6yOORIPUrl8KGJkT6UjJdoammEQZwRWLngfe1x0zwhxf1d9xT psv5bc3D72lJxo4Adlb6Q6NzVJmhIhtI0wG7ESfweAIOSQSpOJhCE/WYKfdsKyPTmq9F 42vQ== X-Gm-Message-State: ABUngvfJvy69Eli+o771pV1x77WDxYTxGtTfNSa9ZqTx4/JHUFKxzR6ZBe8ySbF1WzNIXQ== X-Received: by 10.194.2.198 with SMTP id 6mr15246184wjw.51.1478282438954; Fri, 04 Nov 2016 11:00:38 -0700 (PDT) Received: from localhost (188.29.212.87.threembb.co.uk. [188.29.212.87]) by smtp.gmail.com with ESMTPSA id 63sm9399048wmv.1.2016.11.04.11.00.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Nov 2016 11:00:38 -0700 (PDT) From: Mark Walters To: notmuch@notmuchmail.org Subject: [PATCH] emacs: mua: add a pre-send-check-hook Date: Fri, 4 Nov 2016 18:00:19 +0000 Message-Id: <1478282419-2771-1-git-send-email-markwalters1009@gmail.com> X-Mailer: git-send-email 2.1.4 X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Nov 2016 18:00:45 -0000 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