#!/bin/csh -f

# Copyright (c) 1991, Andrew Rosen.
# All rights reserved.
#
# This  software is supplied free of charge.  This software, or any part
# of it,  may  not  be  redistributed or otherwise made available to, or
# used  by,  any  other  person  without the inclusion of this copyright
# notice.  This software may not be used to make a profit in any way.
#
# This  software  is provided with absolutely no warranty, to the extent
# permitted  by  applicable  state law.  In no event, unless required by
# applicable law,  will the author(s) of this software be liable for any
# damages caused by this software.


source ~acs/acs-vars
cd ${acsdir}

set file = $argv[1]

source get-address
if ( ${quit} == "yes" ) then
  goto done
endif

# Check if user has an alias
source check-alias

if ( ${status} == 0 ) then
  # User does not have an alias
  source give-alias

  # Clean up
  rm -f ${file}
  exit 0
endif

# Use already has an alias, prepare message
cat >! /tmp/ping-mess.$$ << EOF
From: ${pinguser}@${server}
Subject: ACS ping
To: ${raddress}
Reply-To: ${adminuser}@${server}
X-ACS2-Version: ${version}

Your ping request has been received by ${pinguser}@${server}.

You already have an alias ${alias}.
Your return address is ${reply}.
EOF

# Append signature and mail file
#cat ${signature} >> /tmp/ping-mess.$$
cat /tmp/ping-mess.$$ | sendmail -f ${adminuser}@${server} ${raddress}

echo "Mail sent to ${address}"

# Clean up
done:
rm -f /tmp/ping-mess.$$ ${file}
exit 1
