summaryrefslogtreecommitdiff
path: root/localshowmaildelivered
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2007-10-03 17:38:17 +0000
committerJonas Smedegaard <dr@jones.dk>2007-10-03 17:38:17 +0000
commit0dba35f17d796e036d8a72ec0c9addd61ee8b652 (patch)
treeb6019459d348e8db063db6af9e6de9e506c42cf3 /localshowmaildelivered
parent281e16d08017c63987007c0d211dc0a37c5b2e56 (diff)
Implement alternative hinttype procmail (in addition to the default dovecot).
Diffstat (limited to 'localshowmaildelivered')
-rwxr-xr-xlocalshowmaildelivered32
1 files changed, 27 insertions, 5 deletions
diff --git a/localshowmaildelivered b/localshowmaildelivered
index 4d3bc5a..7340196 100755
--- a/localshowmaildelivered
+++ b/localshowmaildelivered
@@ -3,15 +3,37 @@
# /usr/local/sbin/localshowmaildelivered
# Copyright 2007 Jonas Smedegaard <dr@jones.dk>
#
-# $Id: localshowmaildelivered,v 1.4 2007-09-27 21:43:37 jonas Exp $
+# $Id: localshowmaildelivered,v 1.5 2007-10-03 17:38:17 jonas Exp $
#
# List recently delivered emails
#
-# TODO: Handle other delivery methods than dovecot
-#
logfiles="${logfiles:-1}"
+hinttype="${hinttype:-dovecot}"
+
+mailname="$(cat /etc/mailname | head -n 1)"
+
+case $hinttype in
+ dovecot)
+ # Dovecot "deliver"
+ egrep_before='deliver\(('
+ egrep_after=')\).*saved mail to '
+ sed='s/^\(.\{15\}\) [^)]*): msgid=/\1 (/;s/: saved mail to/)/;s/ INBOX$//'
+ ;;
+ procmail)
+ # Postfix/local via procmail
+ egrep_before=' postfix/local.*: to=<'
+ egrep_after='@'"$mailname"'>, .*status=sent \(delivered to command: procmail'
+ sed='s/^\(.\{15\}\) [^:]*: /\1 (/;s/: .*$/)/'
+ ;;
+ *)
+ echo >&2 "ERROR: unknwon logtype \"$logtype\""
+ exit 1
+ ;;
+esac
+
+localuser="$1"
find /var/log -name 'mail.log*' | sort -nr -t. -k3 | tail -n "$logfiles" | xargs zcat -f \
- | egrep -- 'deliver\(('"$1"')\).*saved mail to ' \
- | sed 's/^\(.\{15\}\) [^)]*): msgid=/\1 (/;s/: saved mail to/)/;s/ INBOX$//'
+ | egrep -- "$egrep_before$localuser$egrep_after" \
+ | sed "$sed"