discussion and development of piem
 help / color / mirror / code / Atom feed
From: Kyle Meyer <kyle@kyleam.com>
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	[thread overview]
Message-ID: <20200822190130.20397-4-kyle@kyleam.com> (raw)
In-Reply-To: <20200822190130.20397-1-kyle@kyleam.com>

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))
 
+(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=messages" 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=messages" query)))))
-      (lambda ()
-        (call-process notmuch-command
-                      nil '(t nil) nil
-                      "show" "--format=mbox" "--entire-thread=true"
-                      query)))))
+  (when (piem-notmuch-known-mid-p mid)
+    (lambda ()
+      (call-process notmuch-command
+                    nil '(t nil) nil
+                    "show" "--format=mbox" "--entire-thread=true"
+                    (concat "id:" mid)))))
 
 (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)
 
 (defcustom piem-after-mail-injection-functions nil
-- 
2.28.0


      parent reply	other threads:[~2020-08-22 19:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-22 19:01 [PATCH 0/3] inject: Add support for skipping messages Kyle Meyer
2020-08-22 19:01 ` [PATCH 1/3] inject: Abbreviate piem-maildir-directory in message Kyle Meyer
2020-08-22 19:01 ` [PATCH 2/3] inject: Support skipping messages Kyle Meyer
2020-08-22 19:01 ` Kyle Meyer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://git.kyleam.com/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200822190130.20397-4-kyle@kyleam.com \
    --to=kyle@kyleam.com \
    --cc=piem@inbox.kyleam.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.kyleam.com/piem/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).