From 0b511912860ce04ed674682ef9d141e899089ac6 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Fri, 27 Oct 2017 23:47:14 -0400 Subject: Add custom notmuch-show-stash-git-send-email variant --- init.el | 2 ++ lisp/km-mail.el | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/init.el b/init.el index 38c3ce6..d47e508 100644 --- a/init.el +++ b/init.el @@ -2197,6 +2197,8 @@ #'km/notmuch-show-pipe-part-to-project) (define-key notmuch-show-mode-map [remap notmuch-show-pipe-message] #'km/notmuch-show-pipe-message-to-project) + (define-key notmuch-show-stash-map [remap notmuch-show-stash-git-send-email] + #'km/notmuch-show-stash-git-send-email-debbugs) (define-key notmuch-show-mode-map [remap notmuch-tree-from-show-current-query] #'km/notmuch-tree-from-show-current-query) diff --git a/lisp/km-mail.el b/lisp/km-mail.el index 19e1a2d..5f39c21 100644 --- a/lisp/km-mail.el +++ b/lisp/km-mail.el @@ -132,6 +132,52 @@ in the remote's \".git/config\" entry." (magit-call-git "fetch" remote)) (magit-log (list (concat base-ref ".." local-ref))))) +(defmacro km/notmuch-with-raw-message (msg-id &rest body) + "Evaluate BODY with temporary buffer containing text for MSG-ID. +MSG-ID is evaluated before entering the temporary buffer. See +also `with-current-notmuch-show-message'." + (declare (indent 1) (debug t)) + (let ((id (make-symbol "id"))) + `(let ((,id ,msg-id)) + (with-temp-buffer + (let ((coding-system-for-read 'no-conversion)) + (call-process notmuch-command nil t nil "show" "--format=raw" ,id) + (goto-char (point-min)) + ,@body))))) + +(defun km/notmuch-show-debbugs-ack-info () + (km/notmuch-with-raw-message (notmuch-show-get-message-id) + (when (save-excursion (re-search-forward "^X-Gnu-PR-Message: ack" nil t)) + (list + (and (re-search-forward "^References: <\\([^>\n]+\\)>" nil t) + (match-string 1)) + (and (re-search-forward "^Reply-To: \\([0-9]+@debbugs\\.gnu\\.org\\)" + nil t) + (match-string 1)))))) + +;;;###autoload +(defun km/notmuch-show-stash-git-send-email-debbugs () + "Debbugs-aware variant of `notmuch-show-stash-git-send-email'. +If the current message is an acknowledgement from the GNU bug +Tracking System, set '--in-reply-to' to the initial report and +'--to' to the newly assigned address. Otherwise, call +`notmuch-show-stash-git-send-email'." + (interactive) + (pcase-let ((`(,root-id ,bug-address) (km/notmuch-show-debbugs-ack-info))) + (if (not (and root-id bug-address)) + (call-interactively #'notmuch-show-stash-git-send-email) + (notmuch-common-do-stash + (string-join + (list (notmuch-show-stash-git-helper (list bug-address) "--to=") + (notmuch-show-stash-git-helper + (message-tokenize-header + (km/notmuch-with-raw-message (concat "id:" root-id) + (and (re-search-forward "^Cc: \\(.+\\)" nil t) + (match-string 1)))) + "--cc=") + (notmuch-show-stash-git-helper (list root-id) "--in-reply-to=")) + " "))))) + ;;; Mail sync -- cgit v1.2.3