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 eNnUH/VqsmGwUAAAsNZ9tg (envelope-from ) for ; Thu, 09 Dec 2021 20:45:41 +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 0NWJG/VqsmFBdAAAbx9fmQ (envelope-from ) for ; Thu, 09 Dec 2021 20:45:41 +0000 Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [IPv6:2001:67c:2050::465:102]) (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 F3CD42596F for ; Thu, 9 Dec 2021 21:45:40 +0100 (CET) Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:105:465:1:2: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 4J95dv4BpWzQkk1; Thu, 9 Dec 2021 21:45:39 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de From: sourcehut@relevant-information.com To: piem@inbox.kyleam.com Cc: Leo Subject: [PATCH 1/1] Use notmuch-extract-patch if available Date: Thu, 9 Dec 2021 21:43:19 +0100 Message-Id: <20211209204319.168897-2-sourcehut@relevant-information.com> In-Reply-To: <20211209204319.168897-1-sourcehut@relevant-information.com> References: <20211209204319.168897-1-sourcehut@relevant-information.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=kyleam.com; s=key1; t=1639082741; 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: in-reply-to:in-reply-to:references:references; bh=0Zrm1FnsCL/rMyabQQvEtSl8vbwXR1PqQ554Qdpj7iQ=; b=QxuOqnqAUc62AfEVumxgOqKvaO5tWjW8mDIO2Crzr7LCyaTtnScFODhLVa2LwRmzySWQ15 SHXYqXFO7VqoioWTRBUousf1Zg1JAQSHbrvGg9VpVcd/UFYl0LzYfK4G8BfIiU6J2oMJjM VpQWz2u3i8fyS3y41oFCtKs1C3GPvyqmMiFwRspce+YUfZrUTiOo8Av2b0vEREWML824ym 6jR0qa8ZhHVF8LiFUyjx7Gy0cbp5/tUFkq5welNbPbvGULi6nDNChg39yFEPwIEVpmNour TiCoBilV/D/GrQ7EXst1ODoB5o9aTZn+6oSbIHwhFy2grm+0xy908wQX4uuw2g== ARC-Seal: i=1; s=key1; d=kyleam.com; t=1639082741; a=rsa-sha256; cv=none; b=CX9kkGHK3cEmaiYcS7CUWUuwnyuPvnlo6xeeZd6smtxbWYc3q/mk/wso4q2Picpsnd+Nol byvA3ukBtBejAEXNvSRl/UibpELf60pdFDN8W3Xpj2qcFn7SasG0CAFbraHibkpoKT4r0u Vs4jYaepWZMXlW5+kp6UaPzb9LBNxZEs7eT6uU/LJZfOPCN88Zw6uqK1v3AdY5uHks9gRT V0JxCkJup7wl6TEzVwYPIqBc0zWqqXHKf1p4F0gCINIDAeH0uEU684bkYy1nhUH++vhg5y STz1ekTmvYiPhQk9uRUrB4oE+HC8wOUyec5H0BbEqZrdWZbWIV8z69i4DsEZgw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of sourcehut@relevant-information.com designates 2001:67c:2050::465:102 as permitted sender) smtp.mailfrom=sourcehut@relevant-information.com X-Migadu-Spam-Score: -0.34 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of sourcehut@relevant-information.com designates 2001:67c:2050::465:102 as permitted sender) smtp.mailfrom=sourcehut@relevant-information.com X-Migadu-Queue-Id: F3CD42596F X-Spam-Score: -0.34 X-Migadu-Scanner: scn1.migadu.com X-TUID: IfILUNcUsOQt 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. --- piem-notmuch.el | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/piem-notmuch.el b/piem-notmuch.el index 8b2a353..05c03ab 100644 --- a/piem-notmuch.el +++ b/piem-notmuch.el @@ -81,7 +81,9 @@ (defun piem-notmuch-am-ready-mbox () "Return a function that inserts an am-ready mbox. If the buffer has any MIME parts that look like a patch, use those parts' contents (in order) as the mbox. Otherwise, use the -message itself if it looks like a patch." +message itself if it looks like a patch. If the executable +notmuch-extract-patch exists on the path, use that 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))) @@ -90,10 +92,25 @@ (defun piem-notmuch-am-ready-mbox () (if (= n-attachments 0) (when (string-match-p piem-patch-subject-re (notmuch-show-get-subject)) - (let ((id (notmuch-show-get-message-id))) + (let ((id (notmuch-show-get-message-id)) + (thread-id notmuch-show-thread-id)) (lambda () - (call-process notmuch-command nil t nil - "show" "--format=mbox" id)))) + (if-let ((cmd (executable-find "notmuch-extract-patch")) + (tid + ;; 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) + (call-process notmuch-command nil t nil + "show" "--format=mbox" id))))) (notmuch-foreach-mime-part (lambda (p) (when-let ((patch (piem-am-extract-attached-patch p))) -- 2.31.0