#!/bin/sh

noticesfrom=`perl -n -e 'print "$_" if chomp && s/^\s*Notices\s*From\s*=\s*([^\s#]+).*$/$1/' /etc/MailScanner/MailScanner.conf`
localpostmaster=`perl -n -e 'print "$_" if chomp && s/^\s*Local\s*Postmaster\s*=\s*([^\s#]+).*$/$1/' /etc/MailScanner/MailScanner.conf`
noticesto=`perl -n -e 'print "$_" if chomp && s/^\s*Notices\s*To\s*=\s*([^\s#]+).*$/$1/' /etc/MailScanner/MailScanner.conf`
sendnotices=`perl -n -e 'print "$_" if chomp && s/^\s*Send\s*Notices\s*=\s*([^\s#]+).*$/$1/' /etc/MailScanner/MailScanner.conf`

# Only do this if they want to send notices to postmaster at all
if [ "x$sendnotices" = "xno" ]; then
  exit 0
fi

alert=`/usr/local/bin/MailScanner --processing`

if [ \! "x$alert" = "x" ]; then
  #cat <<EOM
  sendmail -oem -t <<EOM
From: $noticesfrom <$localpostmaster>
To: MailScanner Administrator <$noticesto>
Subject: Problem Messages

$alert

-- 
MailScanner
EOM
fi

