# copy individual mail files from uuxqt to single file for mailx
# and extpost

#set -vx

UUCP=/usr/lib/uucp
UUIN=/usr/lib/uucp/user  # waffle put messages in here as individual files
UUOUT=/usr/lib/uucp/mail # mailx like to uses single file mailboxes
EXTPOST=/wwiv/extpost    # the extpost (WWIV import) program
WWIV=/wwiv               # the mail WWIV bbs directory


echo "\n# PROCUUCP: UUCP->WWIVnet - Copyright 1992 (C) Andrew Gaunt"

# Convert the waffle mailxbox files to a single file mailbox (for mailx)
cd $UUIN
for i in *
do
	if [ -d $i ]
	then
		echo "  found mail for $i"
		cat $i/* >>$UUOUT/$i && rm -rf $UUIN/$i
	fi
done

# Handle any mail directed to quantum or awg, send it to my WWIV mailbox

#echo "\n################# Looking for mail UUCP -> WWIVnet ############"

cd $EXTPOST
for i in `cat $UUCP/admin/password`
do

#	echo "\t$i - \c"
	if [ -r $UUOUT/$i ]
	then
		echo "Exporting mail :\t$i"
		cat $UUOUT/$i > $EXTPOST/$i.tmp && rm -f $UUOUT/$i
	fi


	if [ -f "$EXTPOST/$i.tmp" ]
	then
		nlfilt $i.tmp $i.txt && mv $i.txt $i.tmp
		extsplt '"From previous_address"' $i.tmp $i.txt
		extpost $i.cfg
		rm -f $i.tmp
		cd $WWIV
		network1.exe
		network2.exe
		cd $EXTPOST
	else
		echo "No new mail for:\t$i"
	fi
done
#echo "\n################# End of procuucp #############################"

