#!/bin/sh set -euo pipefail text="$(cat)" # The Mime Format emails we're trying to parse have the following layout # # To: mail@example.org # ... # # Content-Type: multipart/mixed; # boundary="=_c4f4c8bf54a05b2b47ef558c3c61e418" # ... # # This is a message in Mime Format. If you see this, your mail reader does not support this format. # # --=_c4f4c8bf54a05b2b47ef558c3c61e418 # Content-Type: multipart/alternative; # boundary="=_935b3ef6db1361fbfde9e3eb2b1debe5" # Content-Transfer-Encoding: 8bit # # # --=_935b3ef6db1361fbfde9e3eb2b1debe5 # Content-Type: text/plain; charset=iso-8859-1 # Content-Transfer-Encoding: quoted-printable # # ... # # --=_935b3ef6db1361fbfde9e3eb2b1debe5 # Content-Type: text/html; charset=iso-8859-1 # Content-Transfer-Encoding: quoted-printable # # =0A =0A =09=0A # ... # --=_c4f4c8bf54a05b2b47ef558c3c61e418-- # We're only interested in 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 ' "$datadir/info.rc"