From 3e5535304519c31453ec12037fcd33a4b4095a51 Mon Sep 17 00:00:00 2001 From: Leo Date: Thu, 16 Dec 2021 20:32:33 +0100 Subject: 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> --- piem-notmuch.el | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) 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 +;; Copyright (C) 2019 Sean Whitton ;; Author: Kyle Meyer ;; 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 -- cgit v1.2.3