# 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.


## Get current index
if ! ( -f ${indexfile} ) then
  echo 0 >! ${indexfile}
  echo "Index file ${indexfile} created with index 0"
endif

set index = "`cat ${indexfile}`"
@ index++

# Set new alias
set alias = ${prefix}.${index}

# Add line to ACS alias file
echo "${alias}:${address}" >> ${aliasdb}

echo "New alias is ${alias}"
echo "Reply address is ${address}"

# Add line to sendmail aliases file
#echo "${alias}: ${dquote}|${acsdir}/anon-reply ${prefix}.${index}${dquote}" >> ${mail_aliases}

# Sendmail is configured to rebuild aliases automagically,
# so don't bother rebuilding
#newaliases

# Update index file
echo ${index} >! ${indexfile}


## Tell user hir new alias
cat >! /tmp/ping-mess.$$ << EOF
From: ${adminuser}@${server}
Subject: New ACS alias
To: ${raddress}
Reply-To: ${adminuser}@${server}
X-ACS2-Version: ${version}

Your message has been received by the Anonymous Contact Service
at ${server}.

You have been given a new alias ${alias}.
Your return address is ${reply}.
EOF
cat ${signature} >> /tmp/ping-mess.$$
cat /tmp/ping-mess.$$ | sendmail ${raddress}

echo "Mail sent to ${address}"

rm -f /tmp/ping-mess.$$
exit 0
