#!/bin/bash
# $Id: lsbounced,v 1.46 2015/05/08 10:48:03 fulford Exp $
# $Source: /src/merlin/usr/local/etc/RCS/lsbounced,v $
# $Revision: 1.46 $
# Author C W Fulford.
# Copyright 2015 (c) C W Fulford.
# Licensed for public use under the LGPL, .
# For assistance contact fulford@fulford.net 0709 229 5385
########################################################################
cmd=`basename $0`
ver=`echo "$Id: lsbounced,v 1.46 2015/05/08 10:48:03 fulford Exp $"|awk '{print $3,$4,$5}'`
syntax="$cmd [-c <cc_addr>] [-d] [-L <mail_directory>] [-l] [-r <email_rcpt>] [-s <display_tool>] [-v] [-V] [-x <string>] <mailbox>"
while [ $# -gt 0 ] ;do
case $1 in
-c) cc="-c $2";shift 2;;
-d) set -x;debug=0;shift;;
-L) mdir=$2;shift 2;;
-l) log=:;shift;;
-r) rcpt=$2;shift 2;;
-s) display=gv;shift;;
-v) verbose=:;shift;;
-V) echo "$cmd $Revision: 1.46 $ $Date: 2015/05/08 10:48:03 $"|awk '{print $1,$3,$6}';exit;;
-x) xclude=$2;shift;;
-*) echo "$syntax" >&2;exit 1;;
*) mbx=$1;shift;;
esac
done
#mbx=`echo $mbox|sed 's/^\([a-z].*\)\(@\)\(.*\)$/\1\2\3/'`
[ "$mbx" ]||{ echo "syntax: $syntax">&2; exit 1 ;}
date=`date "+%x"`
xclude=${xclude:-"root"}
vhost=`echo $mbx |awk -F@ '{print $2}'`
muser=`echo $mbx |awk -F@ '{print $1}'`
mdir=${location:-/var/qmail/mailnames/$vhost/$muser/Maildir/cur}
tmp=/tmp/$cmd.$$
dtmp=$tmp.display
pdf=$dtmp.pdf
#chkmail -s bounced
[ "$verbose" ] && echo "$cmd: checking $muser at $vhost"
mtot=`ssh $vhost "sudo ls $mdir" |wc -l`
ssh $vhost "sudo ls $mdir|
while read f;do
m=$mdir/\$f
sudo awk -F: '/^To:/{ if( \$2 !~ /'$xclude'/) print \$2}' \$m
done" |
sed -ne 's/<\;/</g
s/>\;/>/g
s/.*<\(.*\)>.*/\1/p'|
tr 'A-Z' 'a-z'|
sort -u >$tmp
total=`wc -l < $tmp`
if [ "$display" -o "$rcpt" ];then
echo -e ".SH\nBounced Email Addresses - $date\n.LP\n\\\fB$mtot\\\fR bounced messages at $mbx.\n.br\n\\\fB$total\\\fR unique addresses found.\n.LP\n.nf\n"|
cat - $tmp >$dtmp
echo ".fi">>$dtmp
groff -t -ms $dtmp |ps2pdf - $pdf
else
echo "$cmd: $total addressees found. List at $tmp"
fi
if [ "$display" ];then
gv $pdf &
fi
if [ "$rcpt" ];then
name=`echo $rcpt|awk -F@ '{print $1}'|awk -F"." '{print $1}'`
name=`echo ${name:0:1}|tr '[a-z]' '[A-Z]'`${name:1}
mailx -s "Bounced mail addressees" -a $pdf $cc $rcpt <<- .
$name
Please find attached a list of e-mail addressees which resulted
in returned messages.
.
fi
######################################################################
# This program is free software: you can redistribute it and or #
# modify it under the terms of the Lesser GNU General Public License #
# as published by the Free Software Foundation, either version 3 of #
# the License, or (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# A copy of the Lesser GNU General Public License and the GNU #
# General Public License is available at #
# <http://www.gnu.org/licenses/>. #
######################################################################
Copyright
© 2003-2017
Clifford W Fulford.
Fulford Consulting Ltd.
Regd. Co. 4250037 in England & Wales.
Regd. office 162, Edward Rd. Nottingham NG2 5GF, England, UK.
Related web sites: City Linux | Flare Support | West Bridgford | Fulford Portal | Joan Mary Fulford (Nottingham Writer) | Fulford Gallery | Amharic Interpreter | Arabic Interpreter | Tigrinya Interpreter
The layout and associated style sheets for this page are taken from the World Wide Web Consortium and used here under the W3C software licence.