#!/bin/sh
#
# This file is part of SnarfNews
# Copyright (C) 1991,1992,1993,1994,1995,1996 Alec Muffett
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

prog=batch2mail
log=/tmp/L$date$$
date=`date "+%y%m%d%H%M%S"`
spool=$SNARFRUN/B$prog.$date$$

if [ $# -lt 1 ]
then
    echo "Usage: $prog address [file]" 1>&2
    exit 1
fi

addr=$1
shift

cat $@ > $spool

runbatch "conva2m -skip-to 'To: $addr' | ifbytes sendmail -t" <$spool >$log 2>&1

if [ -s $log ]
then
    (
	echo "$prog: $0 $addr $@"
	echo "$prog: $spool produced messages:"
	cat $log
    ) | $SNARFMAIL $SNARFADMIN
else
    rm -f $spool
fi

rm -f $log

exit 0
