* [PATCH 1/5] piem: Add helper to construct message ID link
2021-02-07 7:57 [PATCH 0/5] New command for copying public-inbox URLs Kyle Meyer
@ 2021-02-07 7:57 ` Kyle Meyer
2021-02-07 7:57 ` [PATCH 2/5] piem-dispatch: Add command for copying public-inbox URLs Kyle Meyer
` (4 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Kyle Meyer @ 2021-02-07 7:57 UTC (permalink / raw)
To: piem; +Cc: Xinglu Chen
There are two spots that use (piem-inbox-get :url ...) and
piem-escape-mid to construct the public-inbox link, and there is about
to be another. Extract this shared logic.
Cc: Xinglu Chen <public@yoctocell.xyz>
---
piem-notmuch.el | 10 +++-------
piem.el | 21 ++++++++++++++++-----
tests/piem-tests.el | 13 +++++++++++++
3 files changed, 32 insertions(+), 12 deletions(-)
diff --git a/piem-notmuch.el b/piem-notmuch.el
index a222f3f..2a5c525 100644
--- a/piem-notmuch.el
+++ b/piem-notmuch.el
@@ -109,13 +109,9 @@ (defun piem-notmuch-am-ready-mbox ()
(defun piem-notmuch-show-get-public-inbox-link (mid)
"Given the message-id MID, return the public-inbox url.
This will lookup the url in the `piem-inboxes' variable."
- (let* ((inbox (or (piem-notmuch-get-inbox)
- (user-error "No inbox associated with current buffer")))
- (link (or (piem-inbox-get :url inbox)
- (user-error "No url was found for %s" inbox))))
- (concat
- (piem--ensure-trailing-slash link)
- (piem-escape-mid mid))))
+ (piem-mid-url mid
+ (or (piem-notmuch-get-inbox)
+ (user-error "No inbox associated with current buffer"))))
;;;###autoload
(define-minor-mode piem-notmuch-mode
diff --git a/piem.el b/piem.el
index b66894f..24d252e 100644
--- a/piem.el
+++ b/piem.el
@@ -444,7 +444,7 @@ (defun piem-am-ready-mbox ()
nil))))
\f
-;;;; Download helpers
+;;;; Link handling
(defconst piem--unreserved-chars
(append url-unreserved-chars
@@ -456,6 +456,20 @@ (defun piem-escape-mid (mid)
"Escape MID for use in path part of a public-inbox URL."
(url-hexify-string mid piem--unreserved-chars))
+(defun piem-mid-url (mid &optional inbox)
+ "Return a public-inbox URL for MID.
+The URL is determined by INBOX's entry in `piem-inboxes'. 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"))))
+ (piem-escape-mid mid)))
+
+\f
+;;;; Download helpers
+
(defvar piem--has-gunzip)
(defun piem-check-gunzip ()
"Return non-nil if gunzip is available."
@@ -550,10 +564,7 @@ (defun piem-inject-thread-into-maildir (mid &optional message-only)
"`piem-maildir-directory' does not look like a Maildir directory"))
((not (or message-only (piem-check-gunzip)))
(user-error "gunzip executable not found")))
- (when-let ((url (concat (or (piem-inbox-get :url)
- (user-error
- "Could not find inbox URL for current buffer"))
- (piem-escape-mid mid)
+ (when-let ((url (concat (piem-mid-url mid)
(if message-only "/raw" "/t.mbox.gz")))
(buffer (url-retrieve-synchronously url 'silent)))
(unwind-protect
diff --git a/tests/piem-tests.el b/tests/piem-tests.el
index 795686a..969c9d0 100644
--- a/tests/piem-tests.el
+++ b/tests/piem-tests.el
@@ -49,6 +49,19 @@ (ert-deftest piem-escape-mid ()
(should (equal (piem-escape-mid "msg@id") "msg@id"))
(should (equal (piem-escape-mid "m/g@id") "m%2Fg@id")))
+(ert-deftest piem-mid-url ()
+ (let ((piem-inboxes '(("inbox-a" :url "https://example.com/a/")
+ ("inbox-b" :url "https://example.com/b/"))))
+ (should (equal (piem-mid-url "msg@id" "inbox-a")
+ "https://example.com/a/msg@id"))
+ (should (equal (piem-mid-url "m/sg@id" "inbox-b")
+ "https://example.com/b/m%2Fsg@id"))
+ (should-error (piem-mid-url "msg@id")
+ :type 'user-error))
+ (let ((piem-inboxes '(("inbox-a"))))
+ (should-error (piem-mid-url "msg@id" "inbox-a")
+ :type 'user-error)))
+
(ert-deftest piem-name-branch-who-what-v ()
(should (equal (piem-name-branch-who-what-v
(list :from "Foo Bar <f@example.com>"
--
2.30.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/5] piem-dispatch: Add command for copying public-inbox URLs
2021-02-07 7:57 [PATCH 0/5] New command for copying public-inbox URLs Kyle Meyer
2021-02-07 7:57 ` [PATCH 1/5] piem: Add helper to construct message ID link Kyle Meyer
@ 2021-02-07 7:57 ` Kyle Meyer
2021-02-07 7:57 ` [PATCH 3/5] piem-copy-mid-url: Add support for browsing url Kyle Meyer
` (3 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Kyle Meyer @ 2021-02-07 7:57 UTC (permalink / raw)
To: piem; +Cc: Xinglu Chen
piem-notmuch configures notmuch-show-stash-mlarchive-link-alist with a
custom piem function that's useful for grabbing the pubic-inbox URL.
Add a command to piem-dispatch that provides similar functionality.
---
piem.el | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/piem.el b/piem.el
index 24d252e..0ed288a 100644
--- a/piem.el
+++ b/piem.el
@@ -467,6 +467,16 @@ (defun piem-mid-url (mid &optional inbox)
(or inbox "current buffer"))))
(piem-escape-mid mid)))
+(defun piem-copy-mid-url ()
+ "Copy public-inbox URL for the current buffer's message."
+ (interactive)
+ (kill-new
+ (message "%s"
+ (piem-mid-url
+ (or (piem-mid)
+ (user-error "No message ID found for the current buffer"))
+ (piem-inbox)))))
+
\f
;;;; Download helpers
@@ -787,9 +797,10 @@ (defun piem-am (mbox &optional format info coderepo toggle-worktree)
;;;###autoload (autoload 'piem-dispatch "piem" nil t)
(define-transient-command piem-dispatch ()
"Invoke a piem command."
- [("a" "apply patch" piem-am)
- ("b" "call b4-am" piem-b4-am)
- ("i" "inject thread into maildir" piem-inject-thread-into-maildir)])
+ [[("a" "apply patch" piem-am)
+ ("b" "call b4-am" piem-b4-am)]
+ [("i" "inject thread into maildir" piem-inject-thread-into-maildir)
+ ("l" "copy public-inbox link" piem-copy-mid-url)]])
\f
--
2.30.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 3/5] piem-copy-mid-url: Add support for browsing url
2021-02-07 7:57 [PATCH 0/5] New command for copying public-inbox URLs Kyle Meyer
2021-02-07 7:57 ` [PATCH 1/5] piem: Add helper to construct message ID link Kyle Meyer
2021-02-07 7:57 ` [PATCH 2/5] piem-dispatch: Add command for copying public-inbox URLs Kyle Meyer
@ 2021-02-07 7:57 ` Kyle Meyer
2021-02-07 7:57 ` [PATCH 4/5] piem-copy-mid-url: Allow overriding browse-url-browser-function Kyle Meyer
` (2 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Kyle Meyer @ 2021-02-07 7:57 UTC (permalink / raw)
To: piem; +Cc: Xinglu Chen
I find the notmuch-show-stash-mlarchive-link-and-go command useful.
It's like notmuch-show-stash-mlarchive-link but calls browse-url on
the copied URL.
Make piem-copy-mid-url do the same when given a prefix argument.
---
piem.el | 23 ++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/piem.el b/piem.el
index 0ed288a..5a646c5 100644
--- a/piem.el
+++ b/piem.el
@@ -37,6 +37,7 @@
;;; Code:
+(require 'browse-url)
(require 'cl-lib)
(require 'mail-extr)
(require 'message)
@@ -467,15 +468,19 @@ (defun piem-mid-url (mid &optional inbox)
(or inbox "current buffer"))))
(piem-escape-mid mid)))
-(defun piem-copy-mid-url ()
- "Copy public-inbox URL for the current buffer's message."
- (interactive)
- (kill-new
- (message "%s"
- (piem-mid-url
- (or (piem-mid)
- (user-error "No message ID found for the current buffer"))
- (piem-inbox)))))
+(defun piem-copy-mid-url (&optional browse)
+ "Copy public-inbox URL for the current buffer's message.
+With prefix argument BROWSE, call `browse-url' on the URL
+afterwards."
+ (interactive "P")
+ (let ((url (piem-mid-url
+ (or (piem-mid)
+ (user-error "No message ID found for the current buffer"))
+ (piem-inbox))))
+ (prog1
+ (kill-new (message "%s" url))
+ (when browse
+ (browse-url url)))))
\f
;;;; Download helpers
--
2.30.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 4/5] piem-copy-mid-url: Allow overriding browse-url-browser-function
2021-02-07 7:57 [PATCH 0/5] New command for copying public-inbox URLs Kyle Meyer
` (2 preceding siblings ...)
2021-02-07 7:57 ` [PATCH 3/5] piem-copy-mid-url: Add support for browsing url Kyle Meyer
@ 2021-02-07 7:57 ` Kyle Meyer
2021-02-07 7:57 ` [PATCH 5/5] manual: Add section on "copy public-inbox link" functionality Kyle Meyer
2021-02-07 12:38 ` [PATCH 0/5] New command for copying public-inbox URLs Xinglu Chen
5 siblings, 0 replies; 10+ messages in thread
From: Kyle Meyer @ 2021-02-07 7:57 UTC (permalink / raw)
To: piem; +Cc: Xinglu Chen
I don't use EWW as my default browser for browse-url, but, for
public-inbox HTTP access, I primarily use EWW. Add an option that
makes it easier to do so without adding lots of regular expressions to
browse-url-browser-function.
---
piem.el | 31 +++++++++++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
diff --git a/piem.el b/piem.el
index 5a646c5..6424498 100644
--- a/piem.el
+++ b/piem.el
@@ -192,6 +192,29 @@ (defcustom piem-after-mail-injection-functions nil
`piem-inject-thread-into-maildir'."
:type 'hook)
+(defcustom piem-browse-url-browser-function nil
+ "Overriding value for `browse-url-browser-function'.
+
+public-inbox's HTTP interface is well suited for browsers like
+w3m and EWW, allowing you to stay in Emacs rather than launch an
+external browser. However, assuming you have `browse-url'
+configured to usually go through an external browser, sending
+public-inbox URLs through, say, EWW would require you to
+configure `browse-url-browser-function' with a regular expression
+for each inbox URL that you want to be handled by
+`eww-browse-url'.
+
+Instead, you can simply set this option to `eww-browse-url' (or
+anything else `browse-url-browser-function' accepts), and piem
+will use it when calling `browse-url'.
+
+When this option is nil, piem calls `browse-url' without
+overriding the value of `browse-url-browser-function'."
+ :type (append
+ '(choice
+ (const :tag "Don't override `browse-url-browser-function'" nil))
+ (cdr (get 'browse-url-browser-function 'custom-type))))
+
\f
;;;; Subprocess handling
@@ -471,7 +494,8 @@ (defun piem-mid-url (mid &optional inbox)
(defun piem-copy-mid-url (&optional browse)
"Copy public-inbox URL for the current buffer's message.
With prefix argument BROWSE, call `browse-url' on the URL
-afterwards."
+afterwards. If `piem-browse-url-browser-function' is non-nil, it
+is used as the value of `browse-url-browser-function'."
(interactive "P")
(let ((url (piem-mid-url
(or (piem-mid)
@@ -480,7 +504,10 @@ (defun piem-copy-mid-url (&optional browse)
(prog1
(kill-new (message "%s" url))
(when browse
- (browse-url url)))))
+ (let ((browse-url-browser-function
+ (or piem-browse-url-browser-function
+ browse-url-browser-function)))
+ (browse-url url))))))
\f
;;;; Download helpers
--
2.30.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 5/5] manual: Add section on "copy public-inbox link" functionality
2021-02-07 7:57 [PATCH 0/5] New command for copying public-inbox URLs Kyle Meyer
` (3 preceding siblings ...)
2021-02-07 7:57 ` [PATCH 4/5] piem-copy-mid-url: Allow overriding browse-url-browser-function Kyle Meyer
@ 2021-02-07 7:57 ` Kyle Meyer
2021-02-07 12:38 ` [PATCH 0/5] New command for copying public-inbox URLs Xinglu Chen
5 siblings, 0 replies; 10+ messages in thread
From: Kyle Meyer @ 2021-02-07 7:57 UTC (permalink / raw)
To: piem; +Cc: Xinglu Chen
Cc: Xinglu Chen <public@yoctocell.xyz>
---
piem.texi | 35 +++++++++++++++++++++++++++++++++--
1 file changed, 33 insertions(+), 2 deletions(-)
diff --git a/piem.texi b/piem.texi
index 070adf4..e3019c7 100644
--- a/piem.texi
+++ b/piem.texi
@@ -48,7 +48,7 @@ Top
* Overview::
* Getting started::
* Applying patches::
-* Injecting messages into a Maildir directory::
+* Miscellaneous functionality::
* Contributing::
Appendices
@@ -383,8 +383,11 @@ Applying patches without a public-inbox archive
b4-inspired patch extraction.
\f
+@node Miscellaneous functionality
+@chapter Miscellaneous functionality
+
@node Injecting messages into a Maildir directory
-@chapter Injecting messages into a Maildir directory
+@section Injecting messages into a Maildir directory
@cindex Maildir
public-inbox allows you to follow lists through several mechanisms
@@ -441,6 +444,34 @@ Injecting messages into a Maildir directory
#'piem-notmuch-known-mid-p)
@end lisp
+@node Copying public-inbox URLs
+@section Copying public-inbox URLs
+
+@findex piem-copy-mid-url
+When referring to a message from a public-inbox archive, a common format
+to use is a URL that points to a specific archive and ends with
+@code{/$INBOX/$MESSAGE_ID}, e.g.,
+@url{https://public-inbox.org/meta/20190108015420.GA28903@@dcvr}.
+Calling @code{piem-copy-mid-url} (available in the @code{piem-dispatch}
+transient) constructs such a URL, using the message ID and inbox
+asscociated with the current buffer, and then copies the URL to the kill
+ring. When a prefix agument is given, @code{browse-url} is called after
+copying the URL.
+
+@vindex piem-browse-url-browser-function
+Note that EWW works nicely with public-inbox's HTTP interface. If you'd
+prefer it to be invoked even though it's not your default browser (as
+configured by @code{browse-url-browser-function}), you can set
+@code{piem-browse-url-browser-function} to @code{eww-browse-url}.
+
+@findex piem-notmuch-mode
+@findex piem-notmuch-show-get-public-inbox-link
+For notmuch.el users, there's an additional entry point for copying
+public-inbox URLs: enabling @code{piem-notmuch-mode} adds a ``piem''
+candidate to archives offered by
+@code{notmuch-show-stash-mlarchive-link} and
+@code{notmuch-show-stash-mlarchive-link-and-go}.
+
\f
@node Contributing
@chapter Contributing
--
2.30.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 0/5] New command for copying public-inbox URLs
2021-02-07 7:57 [PATCH 0/5] New command for copying public-inbox URLs Kyle Meyer
` (4 preceding siblings ...)
2021-02-07 7:57 ` [PATCH 5/5] manual: Add section on "copy public-inbox link" functionality Kyle Meyer
@ 2021-02-07 12:38 ` Xinglu Chen
2021-02-07 16:57 ` Kyle Meyer
5 siblings, 1 reply; 10+ messages in thread
From: Xinglu Chen @ 2021-02-07 12:38 UTC (permalink / raw)
To: Kyle Meyer, piem
On Sun, Feb 07 2021, Kyle Meyer wrote:
> Prompted by Xinglu's recent notmuch-show-stash-mlarchive-link addition
> (<https://inbox.kyleam.com/piem/878s81kd8u.fsf@kyleam.com>), this
> series adds a command, piem-copy-mid-url, that can copy the URL in any
> buffer with an associated message ID and inbox (which I'll mostly find
> useful in Gnus).
>
> The last patch updates the manual to mention piem-copy-mid-url as well
> as the piem-aware notmuch-show-stash-mlarchive-link.
>
> [1/5] piem: Add helper to construct message ID link
> [2/5] piem-dispatch: Add command for copying public-inbox URLs
> [3/5] piem-copy-mid-url: Add support for browsing url
> [4/5] piem-copy-mid-url: Allow overriding browse-url-browser-function
> [5/5] manual: Add section on "copy public-inbox link" functionality
This looks good to me. But when I try to apply the patchset with
`piem-b4-am-from-mid` it returns an error (I only pasted the last part):
File "/nix/store/c3rw242zljng83r21jbpczwg54g97d5l-python3.8-dnspython-2.0.0/lib/python3.8/site-packages/dns/resolver.py", line 598, in next_nameserver
raise NoNameservers(request=self.request, errors=self.errors)
dns.resolver.NoNameservers: All nameservers failed to answer the query key1._domainkey.kyleam.com. IN TXT: Server 192.168.1.1 UDP port 53 answered ; Server 192.168.1.1 TCP port 53 answered [Errno 111] Connection refused
This doesn’t happen if i try the same thing on the notmuch archive [1].
Are you able to reproduce this?
Sorry for the extra noise.
[1]: https://yhetil.org/notmuch/20210205132654.3258292-1-david@tethera.net
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/5] New command for copying public-inbox URLs
2021-02-07 12:38 ` [PATCH 0/5] New command for copying public-inbox URLs Xinglu Chen
@ 2021-02-07 16:57 ` Kyle Meyer
2021-02-07 17:35 ` Kyle Meyer
0 siblings, 1 reply; 10+ messages in thread
From: Kyle Meyer @ 2021-02-07 16:57 UTC (permalink / raw)
To: Xinglu Chen; +Cc: piem
Xinglu Chen writes:
> This looks good to me. But when I try to apply the patchset with
> `piem-b4-am-from-mid` it returns an error (I only pasted the last part):
>
> File "/nix/store/c3rw242zljng83r21jbpczwg54g97d5l-python3.8-dnspython-2.0.0/lib/python3.8/site-packages/dns/resolver.py", line 598, in next_nameserver
> raise NoNameservers(request=self.request, errors=self.errors)
> dns.resolver.NoNameservers: All nameservers failed to answer the query key1._domainkey.kyleam.com. IN TXT: Server 192.168.1.1 UDP port 53 answered ; Server 192.168.1.1 TCP port 53 answered [Errno 111] Connection refused
>
> This doesn’t happen if i try the same thing on the notmuch archive [1].
> Are you able to reproduce this?
Just tried piem-b4-am-from-mid from an eww buffer visiting
<https://inbox.kyleam.com/piem/20210207075738.8752-1-kyle@kyleam.com>
and didn't run into any issues on my end.
Hmm, based on dnspython being involved, I guess this happens when b4
tries to download the thread. piem-b4--get-am-files should take care of
downloading the mbox (mostly to prevent users from needing to configure
b4.midmask), but I guess it falls back to b4 because
piem-b4--get-am-files's call to piem-download-and-decompress fails for
the same reason.
Anyway, going through b4 doesn't explain the above error of course, and
things look okay using `b4 am' directly on my end:
# in piem repo
$ git config b4.midmask https://inbox.kyleam.com/piem/%s
$ b4 am 20210207075738.8752-1-kyle@kyleam.com
Looking up https://inbox.kyleam.com/piem/20210207075738.8752-1-kyle%40kyleam.com
Grabbing thread from inbox.kyleam.com/piem
Analyzing 7 messages in the thread
[...]
Assuming the above isn't a transient error, I'm guessing a plain curl
call fails on your end too?
$ curl -fsS \
https://inbox.kyleam.com/piem/20210207075738.8752-1-kyle@kyleam.com/t.mbox.gz | zless
> Sorry for the extra noise.
Not at all. Thanks for reporting. Sorry I don't have more helpful
response.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/5] New command for copying public-inbox URLs
2021-02-07 16:57 ` Kyle Meyer
@ 2021-02-07 17:35 ` Kyle Meyer
2021-02-07 20:25 ` Xinglu Chen
0 siblings, 1 reply; 10+ messages in thread
From: Kyle Meyer @ 2021-02-07 17:35 UTC (permalink / raw)
To: Xinglu Chen; +Cc: piem
Kyle Meyer writes:
> Hmm, based on dnspython being involved, I guess this happens when b4
> tries to download the thread. piem-b4--get-am-files should take care of
> downloading the mbox (mostly to prevent users from needing to configure
> b4.midmask), but I guess it falls back to b4 because
> piem-b4--get-am-files's call to piem-download-and-decompress fails for
> the same reason.
But then again, I guess you were probably doing that from notmuch? And
in that case, piem-notmuch-mid-to-thread should have produced the thread
locally, and there should be no network involved. So maybe this is
related to b4's optional attestation checking. Here's how to turn that
off:
$ git config --global b4.attestation-policy off
^ permalink raw reply [flat|nested] 10+ messages in thread