#!/bin/sh set -o pipefail set -eu myemail=$(mktemp) cat - > $myemail email=$(maddr -a -h From $myemail 2>/dev/null) replyto=$(maddr -h Reply-To $myemail 2>/dev/null) records=$(host -t txt _dmarc.${email#*@}) # cleanup the lines to drop ; and " and have every fields space separated savIFS=${IFS} export IFS=' ";' set -- $records export IFS=${savIFS} case "$@" in *\ p=reject\ *|*\ p=quarantine\ *) fullmail=$(maddr -h From $myemail 2>/dev/null) newfrom="${fullmail%<${email}>} via " if [ -z ${replyto} ]; then msed "/from/c/$newfrom/;/Reply-To/a/$fullmail/" $myemail 2>/dev/null else msed "/from/c/$newfrom/;/reply-to/s/.*/&, $fullmail/" $myemail 2>/dev/null fi ;; *) cat $myemail esac rm $myemail