From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms12 with LMTPS id aMiWBrNrQV++KAAAsNZ9tg (envelope-from ) for ; Sat, 22 Aug 2020 19:02:11 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id 8JFnArNrQV/vbgAAbx9fmQ (envelope-from ) for ; Sat, 22 Aug 2020 19:02:11 +0000 Received: from pb-smtp21.pobox.com (pb-smtp21.pobox.com [173.228.157.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id A19F49402C2 for ; Sat, 22 Aug 2020 19:02:10 +0000 (UTC) Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 5BBA7EA00E; Sat, 22 Aug 2020 15:02:09 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=1WjmArGDGYekKvZQHktA/qIFH B0=; b=Hpn4rQL5T6pCj8VwWOXjksffBKoge3g0ReQl6gmx+OQ+LTr+rYXzqeZ1G fZWUsHJJ3DxvPhJrqfjChNugYyf1y2v1XzqcA6J0nki2k98N70ctvndsWEivXdid NTsWx/YihImgONqqwdeA/kWQnMeZyUS424St9DU/i7OQ321Ets= Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 4FD7EEA00D; Sat, 22 Aug 2020 15:02:09 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=kyleam.com; h=from:to:subject:date:message-id:in-reply-to:references:mime-version:content-transfer-encoding; s=mesmtp; bh=nx/ejeJBFxlQ/rWZFEBne1etNIn4DX/Ctcge7ZXhM5Q=; b=2nYkm2f6hW73HpkyvWTW0giQAHbGH15j83FqW9/7Nv4u6Hi60ECtT4TD3tm85QpEmtsrTjkSvSnb5/kwUOf2i8uyxrjPX6Ecy3KuAqkopQjJ7Pto4lm3gjyYtvxvnRzQ6tEjPoV8DhBtu+hywjq+fYRnIp+iIbiKgaCHFVeXf3U= Received: from localhost (unknown [45.33.91.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp21.pobox.com (Postfix) with ESMTPSA id 87E4AEA00C; Sat, 22 Aug 2020 15:02:06 -0400 (EDT) (envelope-from kyle@kyleam.com) From: Kyle Meyer To: piem@inbox.kyleam.com Subject: [PATCH 3/3] notmuch: Extract "known message?" logic to function Date: Sat, 22 Aug 2020 15:01:30 -0400 Message-Id: <20200822190130.20397-4-kyle@kyleam.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200822190130.20397-1-kyle@kyleam.com> References: <20200822190130.20397-1-kyle@kyleam.com> MIME-Version: 1.0 X-Pobox-Relay-ID: F8F6AA86-E4A9-11EA-9D1E-843F439F7C89-24757444!pb-smtp21.pobox.com Content-Transfer-Encoding: quoted-printable X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=pobox.com header.s=sasl header.b=Hpn4rQL5; dkim=fail (body hash did not verify) header.d=kyleam.com header.s=mesmtp header.b=2nYkm2f6; dmarc=none; spf=pass (aspmx1.migadu.com: domain of kyle@kyleam.com designates 173.228.157.53 as permitted sender) smtp.mailfrom=kyle@kyleam.com X-Spam-Score: 2.50 X-TUID: ng6AGWKESWe0 Notmuch users can set piem-mail-injection-skipif-predicate to the new function. --- piem-notmuch.el | 32 +++++++++++++++++++------------- piem.el | 5 ++++- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/piem-notmuch.el b/piem-notmuch.el index 29f4d27..5bf5b09 100644 --- a/piem-notmuch.el +++ b/piem-notmuch.el @@ -47,21 +47,27 @@ (defun piem-notmuch-get-mid () "Return the message ID of a `notmuch-show-mode' buffer." (notmuch-show-get-message-id 'bare)) =20 +(defun piem-notmuch-known-mid-p (mid) + "Return non-nil if MID is known to Notmuch. +The message ID should not include Notmuch's \"id:\" prefix or +have surrounding brackets." + (let ((query (concat "id:" mid))) + (equal query + (string-trim-right + (with-output-to-string + (with-current-buffer standard-output + (call-process notmuch-command + nil '(t nil) nil + "search" "--output=3Dmessages" query))))))= ) + (defun piem-notmuch-mid-to-thread (mid) "Return a function that inserts an mbox for MID's thread." - (let ((query (concat "id:" mid))) - (when (equal query - (string-trim-right - (with-output-to-string - (with-current-buffer standard-output - (call-process notmuch-command - nil '(t nil) nil - "search" "--output=3Dmessages" query= ))))) - (lambda () - (call-process notmuch-command - nil '(t nil) nil - "show" "--format=3Dmbox" "--entire-thread=3Dtrue" - query))))) + (when (piem-notmuch-known-mid-p mid) + (lambda () + (call-process notmuch-command + nil '(t nil) nil + "show" "--format=3Dmbox" "--entire-thread=3Dtrue" + (concat "id:" mid))))) =20 (defun piem-notmuch-am-ready-mbox () "Return a function that inserts an am-ready mbox. diff --git a/piem.el b/piem.el index aa0ec0c..5bc86d5 100644 --- a/piem.el +++ b/piem.el @@ -152,7 +152,10 @@ (defcustom piem-mail-injection-skipif-predicate nil brackets) within a buffer that is narrowed to the message. The function does not need to worry about saving point. A non-nil return value signals that `piem-inject-thread-into-maildir' -should skip the message." +should skip the message. + +Notmuch users can use `piem-notmuch-known-mid-p' as the predicate +to skip messages that are already in the Notmuch database." :type 'function) =20 (defcustom piem-after-mail-injection-functions nil --=20 2.28.0