[neomutt] Add keybind to reply based on mailto: link in the body

This commit is contained in:
lara 2022-10-01 12:35:35 +02:00
parent 10e98e71af
commit 8b3920deb5
2 changed files with 49 additions and 0 deletions

42
config/neomutt/extract-reply.sh Executable file
View file

@ -0,0 +1,42 @@
#!/bin/sh
set -euo pipefail
text="$(cat)"
# Extract only the text/html part of the multipart email
# TODO parse actual encoding instead of defaulting to iso-8859-1
mailto="$(printf "%s" "$text" \
| awk '
boundary {
if ($0 ~ boundary) {
boundary = "";
next
}
print $0
}
/Content-Type: text\/html;/ {
boundary=line
}
{
line=$0
}' \
| qprint -d \
| iconv -f iso-8859-1 -t utf-8 \
| grep -Eo '<a href="mailto:.*?</a>')"
to="$(printf "%s" "$mailto" | sed -En 's/.*mailto:(.*?)\?subject=.*/\1/p')"
subject="$(printf "%s" "$mailto" | sed -En 's/.*\?subject=(.*?)" .*/\1/p')"
# TODO extract original To: to emulate use_envelope_from
datadir="${XDG_DATA_HOME:-"$HOME/.local/share"}/neomutt"
mkdir -p "$datadir"
format_str="unmy_hdr To: Subject:
my_hdr To: \"%s\"
my_hdr Subject: \"%s\"
echo \`rm \"%s\"\`"
printf "$format_str" "$to" "$subject" "$datadir/info.rc" > "$datadir/info.rc"

View file

@ -55,6 +55,13 @@ bind pager gh display-toggle-weed
bind pager ge extract-keys
macro pager gu "<pipe-message> urlscan <enter>"
# Answer emails with a reply address in the body
# https://unix.stackexchange.com/a/586010/248368
macro pager gr "<pipe-message> ~/.config/neomutt/extract-reply.sh <enter>\
<enter-command>source ~/.local/share/neomutt/info.rc <enter>\
<mail><enter><enter><enter>"
# Use a hook to reset sender and subject just after creating the reply
send-hook . 'unmy_hdr To: Subject:'
##########
# ATTACH #