discussion and development of piem
 help / color / mirror / code / Atom feed
* [PATCH 0/2] URL escaping fixes
@ 2020-09-19  4:46 Kyle Meyer
  2020-09-19  4:46 ` [PATCH 1/2] Escape message IDs when constructing URLs Kyle Meyer
  2020-09-19  4:46 ` [PATCH 2/2] Unescape message IDs extracted from URLs Kyle Meyer
  0 siblings, 2 replies; 3+ messages in thread
From: Kyle Meyer @ 2020-09-19  4:46 UTC (permalink / raw)
  To: piem

For personal use, you can get by pretty well with just tacking the
message ID as is onto the URL, but piem should of course provide
proper handling here.

I should have thought to do this right away in piem, but didn't until
the topic was discussed on guix-devel (*).  Thanks to simon, Ricardo
Wurmus, and Arun Isaac.

(*) https://yhetil.org/guix-devel/86sgbhz3fe.fsf@gmail.com/

  [1/2] Escape message IDs when constructing URLs
  [2/2] Unescape message IDs extracted from URLs

 piem-b4.el     |  2 +-
 piem-elfeed.el |  2 +-
 piem-eww.el    |  2 +-
 piem.el        | 14 ++++++++++++--
 4 files changed, 15 insertions(+), 5 deletions(-)


base-commit: dd52b69332f077644f792b49f1ea7c58397a0e97
--
2.28.0

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] Escape message IDs when constructing URLs
  2020-09-19  4:46 [PATCH 0/2] URL escaping fixes Kyle Meyer
@ 2020-09-19  4:46 ` Kyle Meyer
  2020-09-19  4:46 ` [PATCH 2/2] Unescape message IDs extracted from URLs Kyle Meyer
  1 sibling, 0 replies; 3+ messages in thread
From: Kyle Meyer @ 2020-09-19  4:46 UTC (permalink / raw)
  To: piem

Message IDs can include characters that must escaped before being
included in the path part of public-inbox URLs.  Add a variant of
url-hexify-string that uses the same set of characters as
public-inbox's mid_escape().
---
 piem-b4.el |  2 +-
 piem.el    | 14 ++++++++++++--
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/piem-b4.el b/piem-b4.el
index b77d111..596e563 100644
--- a/piem-b4.el
+++ b/piem-b4.el
@@ -66,7 +66,7 @@ (defun piem-b4--get-am-files (mid coderepo args)
                  (mid (piem-mid))
                  (buffer (condition-case nil
                              (piem-download-and-decompress
-                              (concat url mid "/t.mbox.gz"))
+                              (concat url (piem-escape-mid mid) "/t.mbox.gz"))
                            (error nil))))
         (with-current-buffer buffer
           (write-region nil nil mbox-thread))
diff --git a/piem.el b/piem.el
index dd2b30e..7c6ca6f 100644
--- a/piem.el
+++ b/piem.el
@@ -261,7 +261,7 @@ (defun piem-message-link-re (url &optional mid)
 non-nil, make the match specific for that message."
   (rx-to-string
    `(and ,(piem--ensure-trailing-slash url)
-         (group ,(or mid
+         (group ,(or (and mid (piem-escape-mid mid))
                      '(one-or-more (not (any "/" "\n")))))
          "/" (group (zero-or-one
                      (or "raw"
@@ -403,6 +403,16 @@ (defun piem-am-ready-mbox ()
 \f
 ;;;; Download helpers
 
+(defconst piem--unreserved-chars
+  (append url-unreserved-chars
+          ;; These extra characters follow what's used by
+          ;; public-inbox's mid_escape().
+          (list ?! ?$ ?& ?' ?\( ?\) ?* ?+ ?, ?= ?: ?\; ?@)))
+
+(defun piem-escape-mid (mid)
+  "Escape MID for use in path part of a public-inbox URL."
+  (url-hexify-string mid piem--unreserved-chars))
+
 (defvar piem--has-gunzip)
 (defun piem-check-gunzip ()
   "Return non-nil if gunzip is available."
@@ -500,7 +510,7 @@ (defun piem-inject-thread-into-maildir (mid &optional message-only)
   (when-let ((url (concat (or (piem-inbox-get :url)
                               (user-error
                                "Could not find inbox URL for current buffer"))
-                          mid
+                          (piem-escape-mid mid)
                           (if message-only "/raw" "/t.mbox.gz")))
              (buffer (url-retrieve-synchronously url 'silent)))
     (unwind-protect
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] Unescape message IDs extracted from URLs
  2020-09-19  4:46 [PATCH 0/2] URL escaping fixes Kyle Meyer
  2020-09-19  4:46 ` [PATCH 1/2] Escape message IDs when constructing URLs Kyle Meyer
@ 2020-09-19  4:46 ` Kyle Meyer
  1 sibling, 0 replies; 3+ messages in thread
From: Kyle Meyer @ 2020-09-19  4:46 UTC (permalink / raw)
  To: piem

All downstream code expects unescaped message IDs.
---
 piem-elfeed.el | 2 +-
 piem-eww.el    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/piem-elfeed.el b/piem-elfeed.el
index 24b3108..add7547 100644
--- a/piem-elfeed.el
+++ b/piem-elfeed.el
@@ -45,7 +45,7 @@ (defun piem-elfeed-get-mid ()
              (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))))
+         (url-unhex-string (match-string 1 url)))))
 
 ;;;###autoload
 (define-minor-mode piem-elfeed-mode
diff --git a/piem-eww.el b/piem-eww.el
index 9fd34ac..849a3b5 100644
--- a/piem-eww.el
+++ b/piem-eww.el
@@ -44,7 +44,7 @@ (defun piem-eww-get-mid ()
              (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))))
+         (url-unhex-string (match-string 1 url)))))
 
 ;;;###autoload
 (define-minor-mode piem-eww-mode
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-09-19  4:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-19  4:46 [PATCH 0/2] URL escaping fixes Kyle Meyer
2020-09-19  4:46 ` [PATCH 1/2] Escape message IDs when constructing URLs Kyle Meyer
2020-09-19  4:46 ` [PATCH 2/2] Unescape message IDs extracted from URLs Kyle Meyer

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).