aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo <sourcehut@relevant-information.com>2021-12-16 20:32:33 +0100
committerKyle Meyer <kyle@kyleam.com>2021-12-17 00:10:17 -0500
commit3e5535304519c31453ec12037fcd33a4b4095a51 (patch)
treea9309c1372aa20123b2f9968ab7b539fca82c818
parenta005bc153ea93df1885d15bc1e0f65865bea520a (diff)
downloadpiem-3e5535304519c31453ec12037fcd33a4b4095a51.tar.gz
Support preparing am-ready mbox via notmuch-extract-patch
notmuch-extract-patch is a command line tool from the elpa-mailscripts package that extracts patches from a thread. It's a useful way to extract the latest patch series from an email thread and filter out the replies and reviews. Message-Id: <20211216193234.25745-1-sourcehut@relevant-information.com>
-rw-r--r--piem-notmuch.el32
1 files changed, 32 insertions, 0 deletions
diff --git a/piem-notmuch.el b/piem-notmuch.el
index 8b2a353..b48cf70 100644
--- a/piem-notmuch.el
+++ b/piem-notmuch.el
@@ -1,6 +1,7 @@
;;; piem-notmuch.el --- Notmuch integration for piem -*- lexical-binding: t; -*-
;; Copyright (C) 2020-2021 all contributors <piem@inbox.kyleam.com>
+;; Copyright (C) 2019 Sean Whitton <spwhitton@spwhitton.name>
;; Author: Kyle Meyer <kyle@kyleam.com>
;; Keywords: vc, tools
@@ -106,6 +107,37 @@ message itself if it looks like a patch."
(insert patch)))
"mbox"))))))
+(defun piem-notmuch-extract-patch-am-ready-mbox ()
+ "Return a function that inserts an am-ready mbox.
+Use the message itself if it looks like a patch using
+notmuch-extract-patch to get the latest patch series from the
+notmuch thread."
+ (when (and (derived-mode-p 'notmuch-show-mode)
+ (string-match-p piem-patch-subject-re
+ (notmuch-show-get-subject))
+ (= (notmuch-count-attachments
+ (piem-notmuch--with-current-message
+ (mm-dissect-buffer))) 0))
+ (let ((thread-id notmuch-show-thread-id))
+ (lambda ()
+ (if-let ((cmd (executable-find "notmuch-extract-patch"))
+ (tid
+ ;; Copied from mailscripts.el
+ ;;
+ ;; If `notmuch-show' was called with a notmuch query rather
+ ;; than a thread ID, as `org-notmuch-follow-link' in
+ ;; org-notmuch.el does, then `notmuch-show-thread-id' might
+ ;; be an arbitrary notmuch query instead of a thread ID. We
+ ;; need to wrap such a query in thread:{} before passing it
+ ;; to notmuch-extract-patch(1), or we might not get a whole
+ ;; thread extracted (e.g. if the query is just id:foo)
+ (if (string= (substring thread-id 0 7) "thread:")
+ thread-id
+ (concat "thread:{" thread-id "}"))))
+ (call-process cmd nil t nil
+ tid)
+ (user-error "The executable notmuch-extract-patch was not found"))))))
+
(defun piem-notmuch-show-get-public-inbox-link (mid)
"Given the message-id MID, return the public-inbox url.
This will lookup the url in the inboxes returned by