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 B76706DE02CD for ; Thu, 17 Nov 2016 12:54:51 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.062 X-Spam-Level: X-Spam-Status: No, score=0.062 tagged_above=-999 required=5 tests=[AWL=-0.068, 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 vUE96WmU7DLD for ; Thu, 17 Nov 2016 12:54:51 -0800 (PST) Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by arlo.cworth.org (Postfix) with ESMTPS id CC8D16DE00EB for ; Thu, 17 Nov 2016 12:54:50 -0800 (PST) Received: by mail-wm0-f68.google.com with SMTP id g23so25045512wme.1 for ; Thu, 17 Nov 2016 12:54:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=vV8L/G8gCoBGbNImkqVNPEsyKkk3ZUbi/yi1vidGhu4=; b=rz7eBQeb2AghiFNQDfn0jwsZtE57WIwAgHidoSlZT1a/c6X9S29xP7LEiRGRjH44Fc /Kb/4tZmNobB8V/hzCPsh55H0HlDQ5taaftKwTsCJoLLKHnrIElKalysLxEhqeGScDkr 5V+NqHg36t1b60NVwc13j/ygmxUKpxwAUHRNEfYHV8RXt9FJp3unaRYKL4J2yUykN9z/ E50OwPKdj47ipw1oPsYTnBT1f4kdRnRNZRbt2T9lrpFSvrsLnzSj2AYAeIMbqHJQ6Mkx bDhvbAJxAHtncT6lLm1KwiQrAZIL8mgOYkUhtmC4SI34uR3VHRDxvl0i1owklD/qySTv bwhQ== 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=vV8L/G8gCoBGbNImkqVNPEsyKkk3ZUbi/yi1vidGhu4=; b=edezZz1AH06hXtaCGErE6Rk3Jpr5ehPmrzAcwYLpS5nY530Re2g6srdk7BL3kwvJ6+ GJ5U684lCtmJhzYKRFXxzgEEkO1FYSzJ2NdB6+Rl7Q7BcDCBv4ui+pdKwadEWIVZsZH+ 0QSBWGL2Ot0yJytySlddB09Zvnc5tN24fE9mLqeujbkWV23MZLVjC9r2ekGHaYLJxdgn ExEqBxXqtNx2eLLebZkN5bpupBUOO/n7Mh5quyU9Q2IlJugfcIiMCz46NHPr7TRyyBI7 KUnZSd9S1ZW39iQjI4jcnIFLennOJx/GkNSO9gnFDBvXC0+ZOzrL/CZjHqC5lk3IW84L Dmtw== X-Gm-Message-State: AKaTC02gL9np7Gaaa+PUxDT9vz3g33wtc2XR5bEL6a6hoJkr9toIVKAw6wdX/SD6Azdnng== X-Received: by 10.28.73.135 with SMTP id w129mr6084489wma.42.1479416088904; Thu, 17 Nov 2016 12:54:48 -0800 (PST) Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162]) by smtp.gmail.com with ESMTPSA id z6sm5165695wjt.24.2016.11.17.12.54.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Nov 2016 12:54:48 -0800 (PST) From: Mark Walters To: notmuch@notmuchmail.org Subject: [PATCH] emacs: remove use of message-send-hook Date: Thu, 17 Nov 2016 20:54:39 +0000 Message-Id: <1479416079-6319-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: Thu, 17 Nov 2016 20:54:51 -0000 We use message-send-hook for two things -- tagging drafts deleted, and tagging replied the parent message of a reply. We should not use message-send-hook as that will affect gnus etc too. Moreover, message-send-hook is run before the message is sent, even before the user confirms they want to send it (if message-confirm-send is set). This means the user can do C-c C-c to send, then cancel, and the parent is still tagged replied. Now we have our own send function it is natural to put these functions there rather than in the hook. We also fix the bug mentioned above. This is slightly tricky as message-send-and-exit kills the compose buffer, so we need to store the tagging commands ready to be run after the send is successful. --- As mentioned in the commit message, we need to remove our use of message-send-hook and fix the bug of erroneously tagging messages "replied" or "deleted". This approach might be a little overkill (a dolist for a list of two elements), but it avoids breaking the api (for notmuch-message-mark-replied) and is easily extendable if we need to add more post send tagging operations later. Also, it seemed easiest to tweak the require orders, but maybe we should just move the two things in notmuch-message into notmuch-mua. Best wishes Mark emacs/notmuch-draft.el | 12 ++++++------ emacs/notmuch-message.el | 12 +++++++----- emacs/notmuch-mua.el | 19 +++++++++++++++---- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/emacs/notmuch-draft.el b/emacs/notmuch-draft.el index fb7f4f5..738628b 100644 --- a/emacs/notmuch-draft.el +++ b/emacs/notmuch-draft.el @@ -91,12 +91,15 @@ postponing and resuming a message." "Message-id of the most recent saved draft of this message") (make-variable-buffer-local 'notmuch-draft-id) -(defun notmuch-draft--mark-deleted () +(defun notmuch-draft--mark-deleted (&optional dry-run) "Tag the last saved draft deleted. -Used when a new version is saved, or the message is sent." +Used when a new version is saved, or the message is sent. If +DRY-RUN is set, then just return a list of the arguments for +`notmuch-tag' rather than doing the tagging." (when notmuch-draft-id - (notmuch-tag notmuch-draft-id '("+deleted")))) + (funcall (if dry-run #'list #'notmuch-tag) + notmuch-draft-id '("+deleted")))) (defun notmuch-draft-quote-some-mml () "Quote the mml tags in `notmuch-draft-quoted-tags`." @@ -259,9 +262,6 @@ applied to newly inserted messages)." (setq notmuch-draft-id (when draft id))))) -(add-hook 'message-send-hook 'notmuch-draft--mark-deleted) - - (provide 'notmuch-draft) ;;; notmuch-draft.el ends here diff --git a/emacs/notmuch-message.el b/emacs/notmuch-message.el index 55e4cfe..373d38c 100644 --- a/emacs/notmuch-message.el +++ b/emacs/notmuch-message.el @@ -23,7 +23,6 @@ (require 'message) (require 'notmuch-tag) -(require 'notmuch-mua) (defcustom notmuch-message-replied-tags '("+replied") "List of tag changes to apply to a message when it has been replied to. @@ -38,15 +37,18 @@ the \"inbox\" and \"todo\" tags, you would set: :type '(repeat string) :group 'notmuch-send) -(defun notmuch-message-mark-replied () +(defun notmuch-message-mark-replied (&optional dry-run) + "Tag the parent message replied. + +If DRY-RUN is set, then just return a list of the arguments for +`notmuch-tag' rather than doing the tagging." ;; get the in-reply-to header and parse it for the message id. (let ((rep (mail-header-parse-addresses (message-field-value "In-Reply-To")))) (when (and notmuch-message-replied-tags rep) - (notmuch-tag (notmuch-id-to-query (car (car rep))) + (funcall (if dry-run #'list #'notmuch-tag) + (notmuch-id-to-query (car (car rep))) (notmuch-tag-change-list notmuch-message-replied-tags))))) -(add-hook 'message-send-hook 'notmuch-message-mark-replied) - (provide 'notmuch-message) ;;; notmuch-message.el ends here diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el index 93747b1..07be69a 100644 --- a/emacs/notmuch-mua.el +++ b/emacs/notmuch-mua.el @@ -28,6 +28,7 @@ (require 'notmuch-lib) (require 'notmuch-address) (require 'notmuch-draft) +(require 'notmuch-message) (eval-when-compile (require 'cl)) @@ -545,10 +546,20 @@ unencrypted. Really send? ")))) (interactive "P") (when (and (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 - (message-send-and-exit arg) - (message-send arg))))) + (let (tag-change + post-send-tag-changes) + ;; post-send-tag-changes are tag-changes to apply after sending, + ;; but we need to store them now as the compose buffer is + ;; typically killed before message-send-and-exit returns. + (push (notmuch-message-mark-replied t) post-send-tag-changes) + (push (notmuch-draft--mark-deleted t) post-send-tag-changes) + (letf (((symbol-function 'message-do-fcc) #'notmuch-maildir-message-do-fcc)) + (if exit + (message-send-and-exit arg) + (message-send arg))) + (dolist (tag-change post-send-tag-changes) + (when tag-change + (apply #'notmuch-tag tag-change)))))) (defun notmuch-mua-send-and-exit (&optional arg) (interactive "P") -- 2.1.4