No idea if this will be of interest to anyone, but my users are finding it useful so I’m sharing. I’m sure this is not especially efficient, but it’s running for only a handful of users who are super paranoid about their email.
--- #! /bin/bash # requires smtpd_log_access_permit_actions = static:all in /etc/postfix/main.cf # will not list emails sent to multiple users # v1.0 2016 Public Domain [email protected] (@lbutlr) EXCLUDE=".top\|.stream\|.win>\|.us>" LOGF="/var/log/maillog.0.bz2” REJECT=1 ACCEPT=1 helpm () { echo "usage: `basename "$0"` -p <pattern> [ -x <exclude pattern> ] [ -o <outputfile> ] [ -R ] [ -A ] [ -l <maillog> ] | [-h]]" echo " -x | --exclude defaults to $EXCLUDE" echo " -l | --log defaults to $LOGF" echo " -A | --noaccept Supress showing accepted email" echo " -R | --noreject Supress showing rejected email" } if [ "$1" = "" ];then helpm exit else while [ "$1" != "" ]; do case $1 in -p | --pattern ) shift MATCHPAT=$1 ;; -x | --exclude ) shift EXCLUDE=$1 ;; -o | --output ) shift OUTF=$1 exec 1>>{$OUTF} ;; -l | -log ) shift LOGF=$1 ;; -R | --noreject ) REJECT=0 ;; -A | --noaccept ) ACCEPT=0 ;; * | -h | --help ) helpm exit ;; esac shift done fi if [ "$MATCHPAT" = "" ]; then echo "-p <patttern> is required." exit else TITLE=` gdate --date='yesterday' +'%d %B %Y'` echo "<!DOCTYPE html><html><head><title>$TITLE \"$1\"</title> <style>" echo 'table { border-collapse: collapse; background-color: #FFFFFC; } td,th { border-top: 1px solid black; border-bottom: 1px solid black; Padding: .5em; } th { border-right: 2px solid black; background-color: #EEE; } tr { border-left: 1px black solid; border-right: 1px black solid; } .rej { color: red; letter-spacing: .5em; text-align: right; } .right { text-align: right; font-family: monospace; } .qid { background-color: #EEFFEE; } </style> </head><body><table>' if [ "$REJECT" = 1 ]; then echo '<tr><th> </th><th>IP address</th><th>Claimed address</th></tr>' bzgrep "$MATCHPAT" $LOGF | grep -i reject | egrep 'from=<[^>]+>' | \ egrep -v "$EXCLUDE" | sort -u | sed 's/from=<//' | tr -d '>,[]:' | grep -v rejected | \ awk '{print "<tr><td class=\"rej\">REJECTED</td><td class=\"right\">"$16"</td><td>"$20"</td></tr>"}' fi if [ "$ACCEPT" = 1 ]; then echo '<tr><th style="width:8em;">Accepted ID</th><th style="width:6em;">Time</th><th>From</th></tr>' bzgrep -E 'DATA|\"from=\"' $LOGF | grep -v "<>"| \ awk '{print $6"\t"$3"\t"$17"\t"$16}' | grep -v ESMTP | \ grep -v "to=<backup" | column -t | sort -k 2 | grep "to=<.*$MATCHPAT" | \ egrep -v "$EXCLUDE" | sed 's/from//g' | sed 's/://' | tr -d '=><' | awk '{print "<tr><td class=\"right qid\">"$1"</td><td class=\"right\">"$2"</td><td>"$4"</td></tr>"}' fi echo "</table></body></html>" fi #EOF How I use this [One line]: /usr/local/bin/DMRH -p kremels\@ -x ".top\|.stream\|.win>\|.us>\grandcentral" | mutt -e 'set content_type=text/html' -s "DMR LIST $($DAY)" [email protected] Output looks like this: <https://www.dropbox.com/s/98n3mk0cv70elp8/Screenshot%202016-10-11%2015.48.53.png?dl=0>
