#!/bin/sh
EMAILADDRESS=`cat /var/spool/hylafax/bin/faxrcvd|grep -E "^TOADDR="|cut -d\" -f2`

USER=`echo $EMAILADDRESS|cut -d@ -f1`
DOMINIO=`echo $EMAILADDRESS|cut -d@ -f2`

if [ "$DOMINIO" = "\$DOMINIO" ]; then
  DOMINIO=`hostname -d`
fi


test -f /usr/sbin/xferfaxstats || exit 0

# Generate HylaFAX's monthly fax statistics

# Generate statistics for faxes during the past month. Two reports
# are generated - one ordered by the destination fax number, the
# other ordered by the sender.

# No fax received in last month
test -f /var/spool/hylafax/log/xferfaxlog || exit 0

/usr/sbin/xferfaxstats -dest -since `date +%D -d'-1 month'` 2>&1 | mail -s "Monthly fax stats - by destination" $USER@$DOMINIO

/usr/sbin/xferfaxstats -send -since `date +%D -d'-1 month'` 2>&1 | mail -s "Monthly fax stats - by sender" $USER@$DOMINIO
