summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/km-mail.el46
1 files changed, 46 insertions, 0 deletions
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