summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2020-08-22 15:01:30 -0400
committerKyle Meyer <kyle@kyleam.com>2020-08-23 20:36:58 -0400
commitb5d12075db5966a51ff6e0f7838796f682f20fd0 (patch)
tree8aba728bb9965b6ba8ff68556fe9e57c0dcdacff
parentc91bc52770ac697f0a2fb0069257c3af27962e3c (diff)
downloadpiem-b5d12075db5966a51ff6e0f7838796f682f20fd0.tar.gz
notmuch: Extract "known message?" logic to function
Notmuch users can set piem-mail-injection-skipif-predicate to the new function. Message-Id: <20200822190130.20397-4-kyle@kyleam.com>
-rw-r--r--piem-notmuch.el32
-rw-r--r--piem.el5
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 @@
"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 @@ The function is called with the message ID (no surrounding
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