diff options
author | Kyle Meyer <kyle@kyleam.com> | 2020-08-27 23:19:17 -0400 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2020-08-28 23:05:56 -0400 |
commit | d200092f77fa8613db0bf58a5670fe91353e8b96 (patch) | |
tree | 3a95b39a1068aa91959b240f0acae5daa736eee9 /piem.el | |
parent | ad1cd6ae77e06c3d53938000b8d559ed436a1dad (diff) | |
download | piem-d200092f77fa8613db0bf58a5670fe91353e8b96.tar.gz |
elfeed, eww: Don't assume inbox name in piem-inboxes and URL match
piem-elfeed-get-inbox and piem-eww-get-inbox match the URL against
piem-link-re and take the second group as the inbox name. That's a
bad approach because the inbox name in the URL doesn't necessarily
match the one in piem-inboxes. For example, public-inbox's own
archive is https://public-inbox.org/meta/, but my entry in
piem-inboxes uses the name "public-inbox":
("public-inbox" :url "https://public-inbox.org/meta/" ...)
The approach also fails if the URL isn't a public-inbox message URL
because piem-link-re isn't very specific. (That will be improved in
an upcoming commit.)
Find the inbox name by matching the buffer URL against the :url values
in piem-inboxes.
Message-Id: <20200828031920.7515-2-kyle@kyleam.com>
Diffstat (limited to 'piem.el')
-rw-r--r-- | piem.el | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -252,6 +252,9 @@ Functions should accept one argument, the message ID given to ;;;; Extractors +(defun piem--ensure-trailing-slash (s) + (if (string-match-p ".+/\\'" s) s (concat s "/"))) + (defvar piem-link-re (rx "/" (group (one-or-more (not (any "/" "\n")))) "/" (group (one-or-more (not (any "/" "\n")))) @@ -301,6 +304,17 @@ intended to be used by libraries implementing a function for (repo (plist-get (cdr (assoc p piem-inboxes)) :coderepo))) (expand-file-name repo))) +(defun piem-inbox-by-url-match (url) + "Return inbox based on matching URL against `:url'." + (setq url (piem--ensure-trailing-slash url)) + (catch 'hit + (dolist (inbox piem-inboxes) + (when-let ((info (cdr inbox)) + (p-url (plist-get info :url))) + (setq p-url (piem--ensure-trailing-slash p-url)) + (when (string-match-p (regexp-quote p-url) url) + (throw 'hit (car inbox))))))) + (defun piem-inbox-url () "Return the URL of current buffer's inbox." (when-let ((p (piem-inbox))) |