summaryrefslogtreecommitdiff
path: root/localshowmailreceived
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2008-02-03 20:10:45 +0000
committerJonas Smedegaard <dr@jones.dk>2008-02-03 20:10:45 +0000
commit21f80eb17189a95f90f02af1cca52acb5bc31df5 (patch)
treec7e8c1ccbbc63706ac498556b071c9a497a6a263 /localshowmailreceived
parent5cddf674dab6f1c04edd6dd1ebc57ded44cd4ce0 (diff)
Rewrite, borrowing the flexible structure from localshowmaildelivered.
Diffstat (limited to 'localshowmailreceived')
-rwxr-xr-xlocalshowmailreceived55
1 files changed, 47 insertions, 8 deletions
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 <dr@jones.dk>
+# Copyright 2007-2008 Jonas Smedegaard <dr@jones.dk>
#
-# $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"