Lore links in mutt

A chance to use awk

The following script takes an email on stdin and constructs the associated lore.kernel.org link based on the email’s Message-ID header. The script copies the link to the Wayland clipboard and posts a notification.

The escaping story is not perfect, but at least it is secure. (It only supports the most common characters in the message ID, but then it also can’t accidentally be misused for escaping shenanigans.)

The script email-to-lore:

#!/bin/sh
awk '
/^Message-ID: <[a-zA-Z0-9/+-=.@]+>/ {
  match($2, /<([^>]+)/, a);
  system("wl-copy -- https://lore.kernel.org/all/" a[1] "/");
  system("notify-send --expire-time=5000 \"Copied to clipboard\" https://lore.kernel.org/" a[1] "/");
}
'

The script is registered in the mutt configuration in the following way:

macro pager l "| /path/to/email-to-lore<enter>" "Copy a Lore link to the clipboard"

When you now hit l in the mutt email view (pager), you get a desktop notification indicating that the link has been copied to the clipboard and you can use the usual shortcuts to paste it.

FYI: Existing alternatives: An alternative to this is the Python lorifier script, which adds the Lore link to the mail headers before display. lorifier is probably smarter about detecting the mailing list which the mail was posted to, whereas my awk script only generates the “all” link.

Comments