# Shell script for Csh (version 2.06M or higher)

# Needed Utilities:
#	CM	    ConfMail
#	BT	    BinkleyTerm
#	ET	    EchoText
#	PKXARC	    Archive extract utility
#	ARC	    Archive builder
#
#	Csh	    To execute this script
#	CP	    My copy command (here, the normal Copy would do it also)
#	FIND	    File selection utility

# If you want to start this script directly from the normal CLI (with
# "Csh MAIL:domail.sh"), replace the 'return ...' statements with 'quit'.

set _maxerr 0

# Export new messages
CM EXPORT -k -i -rb -nf -p ram: -d MAIL:outbound/ -a

if $_maxerr = 2
echo "Severe error in EXPORT"
return 10
else

# Dial out
BT DIAL -1 WaZOO

# Backup inbound mail
CP -v MAIL:inbound MAIL:bak

if $_lasterr > 0
echo "Was not able to backup inbound mail"
return 10
else

# Maintain backup directory: delete backups older than a week
FIND MAIL:bak  -mtime +7  -exec delete {} \;  -print

set _maxerr 0

# Import inbound mail
CM IMPORT -o -f MAIL:imported -a

if $_maxerr = 2

echo "Severe error in IMPORT"
return 10

else; if $_maxerr = 1

set _maxerr 0
CM MAINT -f MAIL:imported

else

set _maxerr 0

endif

# Save inbound mail to text file
ET -adl2v -oMAIL:text/ ALL

if $_maxerr >= 2
echo "Severe error in MAINT or EchoText"
return 10
else

# Set new highwater marks, 'cause EchoText deleted messages
# (change the area names according to your configuration)
CM HIMARK  INTERNAT CLONE COMMS BINKLEY MAIL_DIR BAD_MSGS

endif
endif
endif
endif

return 0
