From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms12 with LMTPS id UPL7Atp3SF9KcwAAsNZ9tg (envelope-from ) for ; Fri, 28 Aug 2020 03:19:54 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id GNmIOtl3SF9jBwAA1q6Kng (envelope-from ) for ; Fri, 28 Aug 2020 03:19:53 +0000 Received: from pb-smtp20.pobox.com (pb-smtp20.pobox.com [173.228.157.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 4381D9404C3 for ; Fri, 28 Aug 2020 03:19:53 +0000 (UTC) Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 062D9F3927; Thu, 27 Aug 2020 23:19:49 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=X2EwVUYgR4eWFyDjtWRKHoV81 Uk=; b=VcUq6d22VPH9A8pstb47B10pnyBhbEz46afUtvnxRuApZun+bd4xm+zyk 3Djuljgqxyc0iSasAhb/9QGr0ggEM9YsjRck151jN9Iv+MVRlUb1UOuijxB9/Gak bisOreA2SkUxKW8o4Re8xqNCv+PXgVfdBalflcktrzP07S62MA= Received: from pb-smtp20.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id F2096F3926; Thu, 27 Aug 2020 23:19:48 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=kyleam.com; h=from:to:subject:date:message-id:in-reply-to:references:mime-version:content-transfer-encoding; s=mesmtp; bh=T7OhhF9jdaRR/GW9VFpNFvXPTa4RGXOPrm2BUJP5URc=; b=0nQf1tF7CujfaHpQCUPxWF/Pdqp6wJArKsd06NgGg14hRHxz7vCQokwUkIG0wFxm/uvkwtwzWXcMD/oRzurH7Qnyjb5/gNE+XgcJzyt/rmdwQObz2u5lt2DuK/Q9EaqGI1M19ToxYZN+yegKffoh4TvoUUJNAyxePN8AQYvNtlM= Received: from localhost (unknown [45.33.91.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp20.pobox.com (Postfix) with ESMTPSA id 6015EF3925; Thu, 27 Aug 2020 23:19:46 -0400 (EDT) (envelope-from kyle@kyleam.com) From: Kyle Meyer To: piem@inbox.kyleam.com Subject: [PATCH 1/4] elfeed, eww: Don't assume inbox name in piem-inboxes and URL match Date: Thu, 27 Aug 2020 23:19:17 -0400 Message-Id: <20200828031920.7515-2-kyle@kyleam.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200828031920.7515-1-kyle@kyleam.com> References: <20200828031920.7515-1-kyle@kyleam.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 52E0F628-E8DD-11EA-9DC6-F0EA2EB3C613-24757444!pb-smtp20.pobox.com Content-Transfer-Encoding: quoted-printable X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=pobox.com header.s=sasl header.b=VcUq6d22; dkim=fail (body hash did not verify) header.d=kyleam.com header.s=mesmtp header.b=0nQf1tF7; dmarc=none; spf=pass (aspmx1.migadu.com: domain of kyle@kyleam.com designates 173.228.157.52 as permitted sender) smtp.mailfrom=kyle@kyleam.com X-Spam-Score: 2.50 X-TUID: RP/28KXJuNex 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. --- piem-elfeed.el | 3 +-- piem-eww.el | 7 +------ piem.el | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/piem-elfeed.el b/piem-elfeed.el index e1ee2f8..5a6472b 100644 --- a/piem-elfeed.el +++ b/piem-elfeed.el @@ -39,8 +39,7 @@ (defun piem-elfeed-get-inbox () "Return inbox name from 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 1 link))))) + (piem-inbox-by-url-match link)))) =20 (defun piem-elfeed-get-mid () "Return the message ID of an `elfeed-show-mode' buffer." diff --git a/piem-eww.el b/piem-eww.el index e8c77f5..5fb629b 100644 --- a/piem-eww.el +++ b/piem-eww.el @@ -38,12 +38,7 @@ (defun piem-eww-get-inbox () "Return inbox name from an EWW buffer." (when (derived-mode-p 'eww-mode) (when-let ((link (plist-get eww-data :url))) - ;; NEEDSWORK: This relies on the inbox name in the URL matching - ;; the inbox name in `piem-inboxes', which might not be the - ;; case. If there's a :url in `piem-inboxes', that could be - ;; matched instead. - (and (string-match piem-link-re link) - (match-string 1 link))))) + (piem-inbox-by-url-match link)))) =20 (defun piem-eww-get-mid () "Return the message ID of an EWW buffer." diff --git a/piem.el b/piem.el index 42646a0..f59f723 100644 --- a/piem.el +++ b/piem.el @@ -252,6 +252,9 @@ (defun piem-process-call-with-buffer-input =0C ;;;; Extractors =20 +(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 @@ (defun piem-inbox-coderepo () (repo (plist-get (cdr (assoc p piem-inboxes)) :coderepo))) (expand-file-name repo))) =20 +(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))) --=20 2.28.0