diff options
author | Kyle Meyer <kyle@kyleam.com> | 2020-05-10 23:41:59 -0400 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2020-05-11 00:22:16 -0400 |
commit | d55b7895a8829d4fd120295bfb6134b51bf87fe4 (patch) | |
tree | a1884d1e58e3a941c5190dfb54bd9c19b3457ff1 /piem.el | |
parent | bf7ac5923e205e298b38f50f01841cdaf30d6a60 (diff) | |
download | piem-d55b7895a8829d4fd120295bfb6134b51bf87fe4.tar.gz |
piem: Extract "inbox from headers" logic from -notmuch
This will be used in the upcoming piem-gnus.el as well.
Diffstat (limited to 'piem.el')
-rw-r--r-- | piem.el | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -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." |