From: Kyle Meyer <kyle@kyleam.com>
To: piem@inbox.kyleam.com
Subject: [PATCH 4/4] elfeed, eww: Be stricter about the returned message ID
Date: Thu, 27 Aug 2020 23:19:20 -0400 [thread overview]
Message-ID: <20200828031920.7515-5-kyle@kyleam.com> (raw)
In-Reply-To: <20200828031920.7515-1-kyle@kyleam.com>
Using the second group in piem-link-re is not reliable because the
trailing part of the URL may be anything. Instead get the inboxes
:url first and then generate a regular expression that has that value
as the prefix.
---
piem-elfeed.el | 9 +++++----
piem-eww.el | 9 +++++----
piem.el | 26 ++++++++++++++------------
3 files changed, 24 insertions(+), 20 deletions(-)
diff --git a/piem-elfeed.el b/piem-elfeed.el
index 5a6472b..b1e112b 100644
--- a/piem-elfeed.el
+++ b/piem-elfeed.el
@@ -43,10 +43,11 @@ (defun piem-elfeed-get-inbox ()
(defun piem-elfeed-get-mid ()
"Return the message ID of an `elfeed-show-mode' buffer."
- (when (derived-mode-p 'elfeed-show-mode)
- (when-let ((link (elfeed-entry-link elfeed-show-entry)))
- (and (string-match piem-link-re link)
- (match-string 2 link)))))
+ (when-let ((inbox (piem-elfeed-get-inbox))
+ (inbox-url (piem-inbox-get :url inbox))
+ (link (elfeed-entry-link elfeed-show-entry)))
+ (and (string-match (piem-message-link-re inbox-url) link)
+ (match-string 1 link))))
;;;###autoload
(define-minor-mode piem-elfeed-mode
diff --git a/piem-eww.el b/piem-eww.el
index 5fb629b..62b7166 100644
--- a/piem-eww.el
+++ b/piem-eww.el
@@ -42,10 +42,11 @@ (defun piem-eww-get-inbox ()
(defun piem-eww-get-mid ()
"Return the message ID of an EWW buffer."
- (when (derived-mode-p 'eww-mode)
- (when-let ((link (plist-get eww-data :url)))
- (and (string-match piem-link-re link)
- (match-string 2 link)))))
+ (when-let ((inbox (piem-eww-get-inbox))
+ (inbox-url (piem-inbox-get :url inbox))
+ (url (plist-get eww-data :url)))
+ (and (string-match (piem-message-link-re inbox-url) url)
+ (match-string 1 url))))
;;;###autoload
(define-minor-mode piem-eww-mode
diff --git a/piem.el b/piem.el
index 4b840cb..da1a693 100644
--- a/piem.el
+++ b/piem.el
@@ -255,18 +255,20 @@ (defun piem-process-call-with-buffer-input
(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"))))
- "/" (group (zero-or-one
- (or "raw"
- "t.mbox.gz"
- (and (or "t" "T") "/#"
- (one-or-more (not (any "/" "\n")))))))
- string-end)
- "Regular expression matching public-inbox HTTP link.
-The first group is the inbox, the second is the message ID, and
-the rest is any trailing endpoint.")
+(defun piem-message-link-re (url &optional mid)
+ "Return a regular expression matching a public-inbox url.
+URL should be the top-level url for the inbox. If MID is
+non-nil, make the match specific for that message."
+ (rx-to-string
+ `(and ,(piem--ensure-trailing-slash url)
+ (group ,(or mid
+ '(one-or-more (not (any "/" "\n")))))
+ "/" (group (zero-or-one
+ (or "raw"
+ "t.mbox.gz"
+ (and (or "t" "T") "/#"
+ (one-or-more (not (any "/" "\n")))))))
+ string-end)))
(defun piem-inbox-by-header-match ()
"Return inbox based on matching message headers.
--
2.28.0
prev parent reply other threads:[~2020-08-28 3:19 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-28 3:19 [PATCH 0/4] eww, elfeed: Improve inbox and message ID detection Kyle Meyer
2020-08-28 3:19 ` [PATCH 1/4] elfeed, eww: Don't assume inbox name in piem-inboxes and URL match Kyle Meyer
2020-08-28 3:19 ` [PATCH 2/4] Add accessor for piem-inboxes Kyle Meyer
2020-08-28 3:19 ` [PATCH 3/4] piem-inbox-{codrepo,get}: Allow caller to specify inbox Kyle Meyer
2020-08-28 3:19 ` 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=20200828031920.7515-5-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).