Update on the evil mangling

Found at: republic.circumlunar.space:70/~katolaz/phlog/20190807_mangling2.txt

Update on the evil link-mangling story. After a chat with dive on 
#bitreich-en, I came up with an alternative solution for de-mangling
Microbloat's "safe" links. First, here is an updated version of the 
de-mangling script, which I called `demangle_msg`:



	cat "$URL" | \
	    sed -E 's:(\\.):\\\1:g' | \
	    sed -E '/http.*safelinks\.protection\.outlook\.com.*url=([^&]*).*$/{s::\1:g;s:\+: :g;s:%:\\x:g}' | \
	    xargs -0 printf "%b"

The script reads lines from the given file (or the standard input)
instead than reading the primary X11 selection. The first `sed` quotes
backslashes (which would otherwise be interpreted by `printf(1)`), while
the second `sed` does the de-mangling (the meaning of the `sed`
expressions will be explained in a future post, to keep this one short
and to the point).  There is actually no need to use `cat` and two
different `sed` commands, but I left them separate here for the sake of
clarity. You can call this script on the press of a keystroke in your
email client, and have the output shown in `elinks(1)`. I use mutt, so I
added the following line:

	macro attach M "|demangle_msg | elinks -force-html "

in my ~/.muttrc. This binds the key "M" to a simple pipeline that passes
the current multipart section to `demangle_msg`, and then shows it in
`elinks(1). I decided to have the key-binding working only in 'attach'
mode (i.e., after you have pressed 'v' to see all the components of the
message), but YMMV. Also, some additional incantation might be needed
for some messages, and the actual URL of the "safe" proxy might vary.