#!/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
endif


## Save subject of message
source get-subject


## Extract body of message, excluding any signature
# First see if there's a signature
cp ${file} /tmp/ap.post
ggrep -s '^--' /tmp/ap.post
if ( ${status} == 0 ) then
  # There is, strip it
  ed /tmp/ap.post << EOF
/^\-\-/
.,\$d
w
q
EOF
endif

# Append two blank lines (fixes potential security hole)
echo "" >> /tmp/ap.post
echo "" >> /tmp/ap.post

# Now strip original header and add one for inews
# Also add anonymous signature
ed /tmp/ap.post << EOF
1,/^\$/d
i
Subject: ${subject}
Organization: ${organization}
X-ACS2-Version: ${version}

.
EOF
cat ${signature} >> /tmp/ap.post


## Feed message to inews
cat /tmp/ap.post | sendmail -f ${adminuser}@${server} ${raddress}

done:
rm -f ${file} /tmp/ap.post
exit 0
