From 21f80eb17189a95f90f02af1cca52acb5bc31df5 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Sun, 3 Feb 2008 20:10:45 +0000 Subject: Rewrite, borrowing the flexible structure from localshowmaildelivered. --- localshowmailreceived | 55 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 8 deletions(-) (limited to 'localshowmailreceived') diff --git a/localshowmailreceived b/localshowmailreceived index 468f106..38bf64a 100755 --- a/localshowmailreceived +++ b/localshowmailreceived @@ -1,18 +1,57 @@ #!/bin/sh # # /usr/local/sbin/localshowmailreceived -# Copyright 2007 Jonas Smedegaard +# Copyright 2007-2008 Jonas Smedegaard # -# $Id: localshowmailreceived,v 1.3 2007-09-27 21:43:37 jonas Exp $ +# $Id: localshowmailreceived,v 1.4 2008-02-03 20:10:45 jonas Exp $ # # List recently received emails # -# TODO: Handle other indicatiors than AMaViS +# TODO: Handle other patterns than AMaViS # -logfiles="${logfiles:-1}" -maildomain=$(if [ -r /etc/mailname ]; then head -n 1 /etc/mailname; fi;) +input="${input:-user}" +output="${output:-shortline}" +logfilecount="${logfilecount:-1}" +pattern="${pattern:-user_amavis}" -find /var/log -name 'mail.log*' | sort -nr -t. -k3 | tail -n "$logfiles" | xargs zcat -f \ - | egrep -- ' -> <'"$1"'@'"$maildomain" \ - | sed 's/^\(.\{15\}\) [^)]*) \([^,]*\), [^]]*] \([^ ]*\) -> .*Message-ID: \([^>,]*>\?\).*/\1 \3 (\4) \2/' +mailname="$(cat /etc/mailname | head -n 1)" + +sed_longline='s/^\(.\{15\}\) [^:]*: /\1 /' +sed_time='s/^\(.\{15\}\) .*$/\1 /' + +case $pattern in + user_amavis) + # AMaViSd new + egrep_before=' -> <' + egrep_after='@'"$mailname" + sed_shortline='s/^\(.\{15\}\) [^)]*) \([^,]*\), [^]]*] \([^ ]*\) -> .*Message-ID: \([^>,]*>\?\).*/\1 \3 (\4) \2/' + sed_msgid='s/^.*Message-ID: //;s/: .*$//' + ;; + *) + echo >&2 "ERROR: unknwon pattern \"$pattern\"" + exit 1 + ;; +esac + +case $output in + shortline) + sedstring="$sed_shortline" + ;; + longline) + sedstring="$sed_longline" + ;; + msgid) + sedstring="$sed_msgid" + ;; + *) + echo >&2 "ERROR: unknwon output \"$output\"" + exit 1 + ;; +esac + +localuser="$1" + +find /var/log -name 'mail.log*' | sort -nr -t. -k3 | tail -n "$logfilecount" | xargs zcat -f \ + | egrep -- "$egrep_before$localuser$egrep_after" \ + | sed "$sedstring" -- cgit v1.2.3