diff options
-rw-r--r-- | piem-notmuch.el | 25 | ||||
-rw-r--r-- | piem.el | 27 |
2 files changed, 30 insertions, 22 deletions
diff --git a/piem-notmuch.el b/piem-notmuch.el index ed5bd4b..96b8a05 100644 --- a/piem-notmuch.el +++ b/piem-notmuch.el @@ -26,7 +26,6 @@ ;;; Code: -(require 'message) (require 'notmuch) (require 'piem) (require 'subr-x) @@ -49,27 +48,9 @@ (defun piem-notmuch-get-inbox () "Return inbox name from a `notmuch-show-mode' buffer." - (pcase-let ((`(,listid ,to ,cc) - (when (derived-mode-p 'notmuch-show-mode) - (piem-notmuch--with-current-message - (message-narrow-to-headers) - (list (message-fetch-field "list-id") - (message-fetch-field "to") - (message-fetch-field "cc")))))) - (catch 'hit - (dolist (inbox piem-inboxes) - (let* ((info (cdr inbox)) - (p-listid (plist-get info :listid))) - (when (and listid - p-listid - (string-match-p (concat "<" (regexp-quote p-listid) ">") - listid)) - (throw 'hit (car inbox))) - (when-let ((addr (plist-get info :address)) - (to (mapconcat #'identity (list to cc) - " "))) - (when (string-match-p (regexp-quote addr) to) - (throw 'hit (car inbox))))))))) + (when (derived-mode-p 'notmuch-show-mode) + (piem-notmuch--with-current-message + (piem-inbox-by-header-match)))) (defun piem-notmuch-get-mid () "Return the message ID of a `notmuch-show-mode' buffer." @@ -26,6 +26,7 @@ ;;; Code: +(require 'message) (require 'subr-x) (defgroup piem () @@ -90,6 +91,32 @@ should return a function that takes no arguments and inserts the mbox's contents in the current buffer." :type 'hook) +(defun piem-inbox-by-header-match () + "Return inbox based on matching message headers. +This should be called from a buffer containing a message and is +intended to be used by libraries implementing a function for +`piem-get-mid-functions'." + (pcase-let ((`(,listid ,to ,cc) + (save-restriction + (message-narrow-to-headers) + (list (message-fetch-field "list-id") + (message-fetch-field "to") + (message-fetch-field "cc"))))) + (catch 'hit + (dolist (inbox piem-inboxes) + (let* ((info (cdr inbox)) + (p-listid (plist-get info :listid))) + (when (and listid + p-listid + (string-match-p (concat "<" (regexp-quote p-listid) ">") + listid)) + (throw 'hit (car inbox))) + (when-let ((addr (plist-get info :address)) + (to (mapconcat #'identity (list to cc) + " "))) + (when (string-match-p (regexp-quote addr) to) + (throw 'hit (car inbox))))))))) + ;;;###autoload (defun piem-inbox () "Return the current buffer's inbox." |