#!/bin/sh
#
SMAIL_PROGRAM="/usr/lib/sendmail"
MAIL_PROGRAM="/usr/ucb/Mail"
HOST=`${SMAIL_PROGRAM} -bP primary_name`
SMAIL_VER=`${SMAIL_PROGRAM} -bP version`
SMAILSTAT="/usr/local/bin/smailstat"
ML=/tmp/mail.$$
MAILLOG="/usr/smail/spool/log/OLD/logfile.0"
RECIPIENT=$1
if [ -z "$1" ]; then
  RECIPIENT=neighorn@qiclab.scn.rain.com
fi

set ${SMAIL_VER}
case $2 in
Smail3.1.25*)
   awk '
   BEGIN        { printf "Scanning Log " }
   /new msg:/   { tot_rec++ }
   /delivered/  { tot_del++ }
   /deferred/   { tot_def++ }
   start_date == "" { start_date = $1 }
   start_time == "" { start_time = $2 }
   { end_date = $1 }
   { end_time = $2 }

   END  { print "\n\n\t\t\t SMAIL MAIL ACTIVITY REPORT"
             printf "\n\n%s \t%s %s\n","Started:",start_date,start_time
             printf "%s \t%s %s\n\n","Ending:",end_date,end_time
             printf "%s \t\t %s\n","Message Status  ","  Total"
             print "==================================================="
             printf "%s \t\t\t %6d\n","Received",tot_rec 
             printf "%s \t\t\t %6d   (%6.2f)\n","Delivered ",tot_del, ( tot_del/
tot_rec)*100
             printf "%s \t\t\t %6d\n","Deferred",tot_def
             printf "\n\n"
             }
   ' ${MAILLOG} >${ML}
   /usr/local/bin/smaillog < ${MAILLOG} >>${ML}
;;

Smail3.1.28*)

   DOMAINS=`${SMAIL_PROGRAM} -bP domains`
   ${SMAILSTAT} -aq -n "${HOST}" -d "${DOMAINS}" ${MAILLOG} >${ML};;
esac

echo Sending SMAIL Activity Mail
${SMAIL_PROGRAM} -oeq -m $RECIPIENT  << EOF
From: Daily Processing <root@${HOST}>
Precedence: junk
Reply-To: Postmaster@${HOST}
Subject: `hostname` Mail Activity Report

${HOST}:
`ls -l ${MAILLOG}`

--------------------------------------------------------------------
`cat ${ML}`
EOF
/bin/rm -f ${ML}
exit 
