From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms12 with LMTPS id kMMfFOazuGHxFgAAsNZ9tg (envelope-from ) for ; Tue, 14 Dec 2021 15:10:30 +0000 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id qMENEOazuGEuIwAAbx9fmQ (envelope-from ) for ; Tue, 14 Dec 2021 15:10:30 +0000 Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 9212C28A58 for ; Tue, 14 Dec 2021 16:10:26 +0100 (CET) Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:105:465:1:3:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4JD1yn0F8yzQl17; Tue, 14 Dec 2021 16:10:25 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de From: leo@relevant-information.com To: piem@inbox.kyleam.com Cc: Leo Subject: [PATCH v2] Use notmuch-extract-patch if available Date: Tue, 14 Dec 2021 16:09:59 +0100 Message-Id: <20211214150959.624-1-leo@relevant-information.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_IN X-Migadu-Country: DE ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=kyleam.com; s=key1; t=1639494630; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=9KBEUyJZCWaduwscWVVNUtY7aMgmzrMafT1o8UzKQxg=; b=uZ6LNBjNy922Qw+CgDFlB6J5yRFkLHO2OiXywKVatsvN+Lcgif4NkuCcOiyj4bH4jkSnYB 2xYXeIW8L1gZQhE3Jf5uu/sgPRdPgNd3OXlsUaiqjkfgVXoZO/RiYrnFcN5yy13NMH1Eid EHe+2DnrEKUfEsHUAO4S4J0QgKPivlPAqGFWxpb/Cb0v5BKmubUsuem0vRyUHxPpmkiZvV laH6ZsehsboEKhHE7DZ/Wwaytf/uQee6LJ9MPBvMvbW6PDs/tHjeLAyE3coIzjyqE2sxcQ VTIlmsVCgZ5TyPpdpViEtjMUm3RKu7YLlvV9q4wNgcDYPt2JdyD+wHP/DTbqYA== ARC-Seal: i=1; s=key1; d=kyleam.com; t=1639494630; a=rsa-sha256; cv=none; b=RHTell8jmoFFwnRZ9hcE/fQhRYwgjzNuoELG3G73AmGgxAMNGTkXw+cERZAQdUalZKZHQg ecoxkb7uuHyuGtJJy/J9ENZNvs4amKf7u8AQDTiriMC4XGpGMH/vtrOEKFwOKhBBaoANAf QySPXZnXKP5i/kgkAQsVn0yT1XYrLF/07kAufNQ0USVPC8AFvYlRLm+F4UOHBmHPvDHqSv VNJiYNx65LP8JyyLsD8jmDYWVihlQvzybT5R5fqBwnFz/DZhWUaBhCl9Sm6So6vHKhMBPs V8gXtplAfZ1EvWP5eK2x3ALkdpBj+luNBPgzWSsHPKcRsL2aA1FSpPKbSZ2mwA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of leo@relevant-information.com designates 80.241.56.152 as permitted sender) smtp.mailfrom=leo@relevant-information.com X-Migadu-Spam-Score: -0.29 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of leo@relevant-information.com designates 80.241.56.152 as permitted sender) smtp.mailfrom=leo@relevant-information.com X-Migadu-Queue-Id: 9212C28A58 X-Spam-Score: -0.29 X-Migadu-Scanner: scn1.migadu.com X-TUID: mjBWbtR4PTbB From: Leo 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. --- I've extracted the functionality into its own function as requested, and added clarification on where the copied comment came from. I'm not sure how the copyright notice should be formatted though. piem-notmuch.el | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/piem-notmuch.el b/piem-notmuch.el index 8b2a353..27a7d7c 100644 --- a/piem-notmuch.el +++ b/piem-notmuch.el @@ -1,6 +1,6 @@ ;;; piem-notmuch.el --- Notmuch integration for piem -*- lexical-binding: t; -*- -;; Copyright (C) 2020-2021 all contributors +;; Copyright (C) 2020-2021 all contributors (C) 2019 Sean Whitton ;; Author: Kyle Meyer ;; Keywords: vc, tools @@ -106,6 +106,40 @@ (defun piem-notmuch-am-ready-mbox () (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 (derived-mode-p 'notmuch-show-mode) + (let* ((handle (piem-notmuch--with-current-message + (mm-dissect-buffer))) + (n-attachments (notmuch-count-attachments handle)) + patches) + (when (= n-attachments 0) + (when (string-match-p piem-patch-subject-re + (notmuch-show-get-subject)) + (let ((id (notmuch-show-get-message-id)) + (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 base-commit: e519aa44d148d5b8f22d7fe8844dc566046b04c2 -- 2.34.1