From 31a2f897cfd72618879f348b9c6c63b6f317d2c5 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Sun, 3 Feb 2008 22:09:07 +0000 Subject: Rewrite to use common localshowlogentries. --- localshowmailreceived | 50 ++++++++------------------------------------------ 1 file changed, 8 insertions(+), 42 deletions(-) (limited to 'localshowmailreceived') diff --git a/localshowmailreceived b/localshowmailreceived index 38bf64a..9278191 100755 --- a/localshowmailreceived +++ b/localshowmailreceived @@ -3,55 +3,21 @@ # /usr/local/sbin/localshowmailreceived # Copyright 2007-2008 Jonas Smedegaard # -# $Id: localshowmailreceived,v 1.4 2008-02-03 20:10:45 jonas Exp $ +# $Id: localshowmailreceived,v 1.5 2008-02-03 22:09:07 jonas Exp $ # # List recently received emails # # TODO: Handle other patterns than AMaViS # -input="${input:-user}" -output="${output:-shortline}" -logfilecount="${logfilecount:-1}" -pattern="${pattern:-user_amavis}" +set -e mailname="$(cat /etc/mailname | head -n 1)" -sed_longline='s/^\(.\{15\}\) [^:]*: /\1 /' -sed_time='s/^\(.\{15\}\) .*$/\1 /' +localshowlogentries "$1" \ + ' -> <' \ + '@'"$mailname" \ + 's/^\(.\{15\}\) [^)]*) \([^,]*\), [^]]*] \([^ ]*\) -> .*Message-ID: \([^>,]*>\?\).*/\1 \3 (\4) \2/' \ + 's/^.*Message-ID: //;s/: .*$//' -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" +exit 0 -- cgit v1.2.3