From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:1004:224b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms12.migadu.com with LMTPS id KidDGVu9emSPRgAATFOONw (envelope-from ) for ; Sat, 03 Jun 2023 06:11:07 +0200 Received: from mta0.migadu.com ([2001:41d0:1004:224b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id aNdmGFu9emSzHwEAauVa8A (envelope-from ); Sat, 03 Jun 2023 06:11:07 +0200 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kyleam.com; s=key1; t=1685765467; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=bD47+1Fd5DfsYky28lDeb+rJDU3d9xo9wH9PxWQBwcY=; b=lVKcp6s9Yn5EifqcgWH+Wm1chmf0w+Sg3KWCHnU65RFiNd5klc8e6Tn+1ylxso0tKUosdw 0EdlHVNptGIce4uV7GWQLw9vgar/8Rwp/CmVr79rgD/FRCnwSuYUGZxD1uGdZx0KTg6lAp r8izyXMtUEeX8I5aFF3aO1y0QHtHcFqTDTSTECzy41ew4TnCyNB1phCjNVFZps14f8MGsz 9GeH4b3Zos7nT9gvb2hs8N9H2LhN/r4DAMofQMkBD5XIi035LK2OIEJY5r1utg4EVlPZFc z4fW9JBf14fWYBMw5Oplz8T+MM1pXy5DpcAytNoksnanlvtaIw/tXzdmg8rjrw== From: Kyle Meyer To: piem@inbox.kyleam.com Cc: Jelle Licht Subject: [PATCH] piem-inboxes: Allow :url values without a trailing slash Date: Sat, 3 Jun 2023 00:11:00 -0400 Message-Id: <20230603041100.200632-1-kyle@kyleam.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-TUID: mEmWPych4nLO The piem-inboxes documentation says that the :url value must end in a slash, which is confusing because 1) public-inbox does not require this and has examples in its docs without a slash and 2) some spots in piem already append a slash if needed. Add a piem-inbox-get wrapper that ensures the returned URL ends with a slash, and use it in all spots that retrieve an inbox's URL. Reported-by: Jelle Licht Link: https://inbox.kyleam.com/piem/87y1l9ualg.fsf@fsfe.org --- piem-b4.el | 2 +- piem-elfeed.el | 2 +- piem-eww.el | 2 +- piem.el | 16 +++++++++++----- tests/piem-tests.el | 6 +++--- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/piem-b4.el b/piem-b4.el index cd19ebb3..8a381c69 100644 --- a/piem-b4.el +++ b/piem-b4.el @@ -73,7 +73,7 @@ (defun piem-b4--get-am-files (mid coderepo args) ;; b4's configuration. (unless local-mbox-p (when-let ((url (and (equal mid (piem-mid)) - (piem-inbox-get :url)))) + (piem-inbox-url)))) (ignore-errors (piem-with-url-contents (concat url (piem-escape-mid mid) "/t.mbox.gz") diff --git a/piem-elfeed.el b/piem-elfeed.el index ce9c75ce..eef61e85 100644 --- a/piem-elfeed.el +++ b/piem-elfeed.el @@ -44,7 +44,7 @@ (defun piem-elfeed-get-inbox () (defun piem-elfeed-get-mid () "Return the message ID of an `elfeed-show-mode' buffer." (when-let ((inbox (piem-elfeed-get-inbox)) - (inbox-url (piem-inbox-get :url inbox)) + (inbox-url (piem-inbox-url inbox)) (link (elfeed-entry-link elfeed-show-entry))) (and (string-match (piem-message-link-re inbox-url) link) (url-unhex-string (match-string 1 link))))) diff --git a/piem-eww.el b/piem-eww.el index 01a9f9de..57690602 100644 --- a/piem-eww.el +++ b/piem-eww.el @@ -43,7 +43,7 @@ (defun piem-eww-get-inbox () (defun piem-eww-get-mid () "Return the message ID of an EWW buffer." (when-let ((inbox (piem-eww-get-inbox)) - (inbox-url (piem-inbox-get :url inbox)) + (inbox-url (piem-inbox-url inbox)) (url (plist-get eww-data :url))) (and (string-match (piem-message-link-re inbox-url) url) (url-unhex-string (match-string 1 url))))) diff --git a/piem.el b/piem.el index a933a6cc..568e91b7 100644 --- a/piem.el +++ b/piem.el @@ -80,7 +80,7 @@ (defcustom piem-inboxes nil repository, with the first value in this list offered as the default. :url - A URL hosting HTTPS archives. This value must end with a slash. + A URL hosting HTTPS archives. :maildir A Maildir directory to inject messages into. @@ -522,6 +522,13 @@ (defun piem-inbox-get (key &optional inbox) (when-let ((p (or inbox (piem-inbox)))) (plist-get (cdr (assoc p (piem-merged-inboxes))) key))) +(defun piem-inbox-url (&optional inbox) + "Return URL associated with INBOX. +If INBOX is nil, use the inbox returned by `piem-inbox'." + (when-let ((inbox (or inbox (piem-inbox))) + (url (piem-inbox-get :url inbox))) + (piem--ensure-trailing-slash url))) + (defun piem-inbox-coderepo (&optional inbox) "Return the code repository of current buffer's inbox." (when-let ((inbox (or inbox (piem-inbox))) @@ -665,10 +672,9 @@ (defun piem-mid-url (mid &optional inbox) public-inbox's configuration. If INBOX is nil, use the inbox returned by `piem-inbox'." (concat - (piem--ensure-trailing-slash - (or (piem-inbox-get :url inbox) - (user-error "Couldn't find URL for %s" - (or inbox "current buffer")))) + (or (piem-inbox-url inbox) + (user-error "Couldn't find URL for %s" + (or inbox "current buffer"))) (piem-escape-mid mid))) ;;;###autoload diff --git a/tests/piem-tests.el b/tests/piem-tests.el index 7f9f30f3..b612b964 100644 --- a/tests/piem-tests.el +++ b/tests/piem-tests.el @@ -74,7 +74,7 @@ (ert-deftest piem-merged-inboxes:from-config-disabled () (piem-merged-inboxes)))) (let ((piem-get-inboxes-from-config nil) (piem-inboxes '(("inbox" :url "inbox-url")))) - (should (equal (piem-inbox-get :url "inbox") "inbox-url")))) + (should (equal (piem-inbox-url "inbox") "inbox-url/")))) (ert-deftest piem-merged-inboxes:from-config () (piem-clear-merged-inboxes) @@ -83,8 +83,8 @@ (ert-deftest piem-merged-inboxes:from-config () (piem-tests-with-pi-config piem-tests-sample-pi-config (should (equal (piem-inbox-get :address "foo") "foo@example.com")) - (should (equal (piem-inbox-get :url "foo") - "https://example.com/foo")) + (should (equal (piem-inbox-url "foo") + "https://example.com/foo/")) (should (equal (piem-inbox-coderepo "foo") "/code/foo/"))) (piem-tests-with-pi-config "" base-commit: 880413af62393d932ca8838d3023399064d72013 -- 2.40.1