#!/bin/sh
#
# getmail :		This file downloads our mail folder from our remote
#              host and merges it with our folder on our local host.
#              It then clears our mail folder on the remote host.
#
# Last modified: 05/01/95
#
# Author: David J. Lennox  < djlennox@mtu.edu >
# 
#
#
LOCAL="root"          # Replace with your local login name. 
REMOTE="djlennox"     # Replace with your remote login name. 
DIR="/usr/spool/mail" # Replace with the mail directory of your remote host. 

#
# Download our mail from our remote host.
#
# NOTE: The lines that are commented out below should be left that 
#       way until you run for awhile and make sure that everything
#       is working correctly. If for some reason something is balled
#       up you risk losing mail. Un-comment after a trial period.
#

echo "Retreving mail...."
tdownload ${DIR}/${REMOTE} --as /var/spool/mail/${REMOTE}

#trsh -s rm ${DIR}/${REMOTE}
#trsh -s touch ${DIR}/${REMOTE}
#trsh -s chmod 600 ${DIR}/${REMOTE}

sleep 2
echo"" 

# 
# Check that we have received mail and if so perform merge
#

if [ -f /var/spool/mail/${REMOTE} ]
then
  cd /var/spool/mail
  cat ${LOCAL} ${REMOTE} > mail.tmp
  rm -f ${LOCAL}
  rm -f ${REMOTE}
  mv mail.tmp ${LOCAL}
fi


# Done!
