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 475DF6DE035A for ; Mon, 7 Nov 2016 13:12:26 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.449 X-Spam-Level: X-Spam-Status: No, score=-0.449 tagged_above=-999 required=5 tests=[AWL=-0.127, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.211, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] 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 TcuSpZBu78n4 for ; Mon, 7 Nov 2016 13:12:24 -0800 (PST) Received: from mail-pf0-f171.google.com (mail-pf0-f171.google.com [209.85.192.171]) by arlo.cworth.org (Postfix) with ESMTPS id C62C36DE00AC for ; Mon, 7 Nov 2016 13:12:24 -0800 (PST) Received: by mail-pf0-f171.google.com with SMTP id d2so96026203pfd.0 for ; Mon, 07 Nov 2016 13:12:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:subject:in-reply-to:references:date:message-id:mime-version :content-transfer-encoding; bh=k2BSo3U7o8ucBaAQFaddWRKZP8HmU53OTFXtcGmWsbk=; b=prlH1x+AUlysc+0YZBi1YQ2j/tQDv/H4TLVv0fiMMr9IHYlzHTWXz+8z+9EUn+N+cq +30sYCiLjIHmxyTbf2d1DugQqGtEHwLZ0XdYQaJ0sdIRZCctfE6ESjd/+NpZiHEB2GSy uWKeGMrf/gyJMLhl9CqZwy7R+8/0Mcg7LqD8cBnAPkWYMjcBJeISzAyIVcAQ3kW2g3o4 SNX7JO/gWw0+SEUsUPBm86qqXnnBkbovLzJI2HBBDn/aJcdJaPudh2cOSEf5/4V3dKkw 2tXP4997Jr6uoSJYzilfe21o2orytk1oLETrL75DSeO41Kxf+QYnQY6CZbWxOegmi1lM u6pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:in-reply-to:references:date :message-id:mime-version:content-transfer-encoding; bh=k2BSo3U7o8ucBaAQFaddWRKZP8HmU53OTFXtcGmWsbk=; b=d6F9ZbIIzVA4Zj2xXJ+H/Z8cgtsfkvLkPRhWahnPBgBPu6FjZeMPBBb8jgFG8++1Ny 1yq2pXfmP73FTxdiALzYDG8+I6tymCe8jiF7AJ++QTt6T94t26EsplHXTmi3WjqEiOBh XEIlS7GXa61n7aGM4DpkgevoX/wO1BQcdvFlbqpOIXwD6wnDpY3luiVSLUvhfPqGbR19 C5Y72aRIgk3Iski4/+SotIcYcE3osRIiExBizDoUpdTdjqDuiom0KUshb/7/vBUbCwbq BIZWLcHjIYqGWAtN1XsJFdKk43kDEIXk8LFWPL3PpHhpUJPc3b3uCyb/JKCtwKfAbcsr hwRQ== X-Gm-Message-State: ABUngvdfDEAhW5AJjVCOQaezTSFBgP5ieF6NsEWmeySNKmgrPaKOf56oW0N5+wsIOi19BZRR X-Received: by 10.99.5.21 with SMTP id 21mr1577442pgf.32.1478553144174; Mon, 07 Nov 2016 13:12:24 -0800 (PST) Received: from marmstrong-linux.kir.corp.google.com ([2620:0:1008:11:94d1:c42:e587:5e5d]) by smtp.gmail.com with ESMTPSA id c2sm20402238pfl.66.2016.11.07.13.12.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Nov 2016 13:12:23 -0800 (PST) From: Matt Armstrong To: Mark Walters , notmuch@notmuchmail.org Subject: Re: [PATCH] emacs: mua: add a pre-send-check-hook In-Reply-To: <1478282419-2771-1-git-send-email-markwalters1009@gmail.com> References: <1478282419-2771-1-git-send-email-markwalters1009@gmail.com> Date: Mon, 07 Nov 2016 13:12:22 -0800 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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: Mon, 07 Nov 2016 21:12:26 -0000 Hey Mark, For consistency with Emacs' own elisp, perhaps rename notmuch-mua-pre-send-check-hooks to notmuch-mua-pre-send-check-functions? This patch reminded me of a recent discussion on emacs-devel about the definition of "hook" in Emacs code and documentation. There is the broad meaning of "arbitrary extension point", and the narrow meaning of "list of functions run by `run-hook'". This is "hook" in the former sense. >From the Elisp manual's Modes > Hooks section: If the hook variable=E2=80=99s name does not end with =E2=80=98-hook=E2= =80=99, that indicates it is probably an "abnormal hook". That means the hook functions are called with arguments, or their return values are used in some way. The hook=E2=80=99s documentation says how the functions are called. You can use =E2=80=98add-hook=E2=80=99 to add a function to an abnormal hook, but you m= ust write the function to follow the hook=E2=80=99s calling convention. By convention, abnormal hook names end in =E2=80=98-functions=E2=80=99. [...] -- Function: run-hook-with-args-until-failure hook &rest args This function runs an abnormal hook by calling each hook function in turn, stopping if one of them fails by returning =E2=80=98nil=E2=80= =99. Each hook function is passed the arguments ARGS. If this function stops because one of the hook functions fails, it returns =E2=80=98nil=E2=80= =99; otherwise it returns a non-=E2=80=98nil=E2=80=99 value. When calling hooks by run-hook-with-args-until-failure/-success, Emacs' own elisp code follows the -functions convention for the most part. Mark Walters writes: > 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=3D 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 @@ >=20=20 > ;; >=20=20 > +(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? ")))) >=20=20 > (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-che= ck-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 > --=20 > 2.1.4 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > https://notmuchmail.org/mailman/listinfo/notmuch