#! /bin/sh

############################################################################
#              Copyright 1992 Digital Equipment Corporation
#                         All Rights Reserved
#
# Permission to use, copy, and modify this software and its documentation is
# hereby granted only under the following terms and conditions.  Both the
# above copyright notice and this permission notice must appear in all copies
# of the software, derivative works or modified versions, and any portions
# thereof, and both notices must appear in supporting documentation.
#
# Users of this software agree to the terms and conditions set forth herein,
# and hereby grant back to Digital a non-exclusive, unrestricted, royalty-
# free right and license under any changes, enhancements or extensions 
# made to the core functions of the software, including but not limited to 
# those affording compatibility with other hardware or software 
# environments, but excluding applications which incorporate this software.
# Users further agree to use their best efforts to return to Digital any
# such changes, enhancements or extensions that they make and inform Digital
# of noteworthy uses of this software.  Correspondence should be provided
# to Digital at:
#
#                       Director of Licensing
#                       Western Research Laboratory
#                       Digital Equipment Corporation
#                       100 Hamilton Avenue
#                       Palo Alto, California  94301
#
# This software may be distributed (but not offered for sale or transferred
# for compensation) to third parties, provided such third parties agree to
# abide by the terms and conditions of this notice.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
# WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
# CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
# PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
# SOFTWARE.
############################################################################

# sccsid = "@(#)ack	@(#)ack	2.0	Network Systems Lab 4/15/92"
#
# Author: Geoff Mulligan (mulligan@pa.dec.com)
#	Please send any modifications or comments to me.
#
# Original code from Brian Reid
#
# This program is called from enqueue to let the customer know the status
# of his request, and possibly also to send the request if the size of the
# request is small enough.
#
# usage: ack address name date type-of-msg bytes BadFiles GoodFiles

TmpFile=/tmp/ack.$$

Addr="$1"; shift;
From="$1"; shift;
Date="$1"; shift;
ReplyCode="$1"; shift;
ByteCount="$1"; shift;
BadFiles="$1"; shift;
GoodFiles="$1"; shift;

case $ReplyCode in
    null) RetVal=1
          cat << a1 > $TmpFile
The server could not find in your message the name of anything to send.
If you need instructions, send the server a message saying "help".
a1
;;
    allgood) RetVal=0
             cat << a2 > $TmpFile
All of the files you requested are available.
a2
;;
    allbad) RetVal=1
            cat << a3 > $TmpFile
The server was not able to find any of the files you requested. You
asked for these files:

`echo $BadFiles | fmt`

Perhaps you are looking in the wrong directory?  Perhaps you are
using the server incorrectly?  If you would like instructions, send
the server a message saying "help".

If you are completely baffled, send a message to nsl-techreports-management
(rather than to nsl-techreports) and an actual human will answer
(though perhaps not instantly).
a3
;;
    somegood) RetVal=0
              cat << a4 > $TmpFile
The server was able to find some of the files you requested.
However, these files were not found:

`echo $BadFiles | fmt`
a4
;;
    multishar) RetVal=0
               cat << a5 > $TmpFile
You have requested more than one "shar" file.  These files are bundles
containing numerous other files, and it is unwise to bundle more than
one together. Therefore the server will send you the first
shar file - $GoodFiles.  It will not send:

`echo $BadFiles | fmt`

To get those files, send a separate retrieval request.
a5
;;
    toobiguucp) RetVal=0
		cat << a6 > $TmpFile
The collection of files you have requested is too large to send via UUCP.
Our UUCP mailer is limited to sending no more than 100 Kbytes per message.

a6
		if test -z "$GoodFiles" ;then
                  cat << a6a >> $TmpFile
None of your files can be retrieved, please order a hardcopy version with
the 'order' command.
a6a
		else
		  cat << a6b >> $TmpFile

The server can send the following files:

`echo $GoodFiles | fmt`

The following files could not be sent.  You must submit separate
retrival request for them.

`echo $BadFiles | fmt`
a6b
                fi
esac

if [ $ByteCount -lt $LOWLIMIT ] ;then
  cat << smallrequest >> $TmpFile
Since your request is small, it is being processed immediately!

`cat ${DIRECTORY}/copyright`

smallrequest
  set $GoodFiles
  if [ $# -gt 1 ] ;then
    rshar $GoodFiles >> $TmpFile
  else
    cat $GoodFiles >> $TmpFile
  fi
  RetVal=2
else
  cat << bigrequest >> $TmpFile
Your request is $ByteCount bytes and has been placed in the server's
queue. The queue is periodically processed by the server, which always
sends the shortest queued request first. The length of time it takes
to process your request will depend on the number of smaller requests in
the queue.
bigrequest
fi

cat << end_message | /usr/lib/sendmail -ba "$Addr"
From: NSL tech report service <nsl-techreports>
To: $Addr
Subject: Receipt of your archive retrieval request
In-reply-to: Request from $From dated $Date

The NSL tech report server has received your request.

`cat $TmpFile`
end_message

rm -f $TmpFile

echo -n "`$DATE`" ACK: $ReplyCode $Addr"(`setdir $Addr`)" $ByteCount >> ${REQDIR}/out.log
if [ "$RetVal" = 2 ] ;then
  echo " sent" >> ${REQDIR}/out.log
else
  echo " queued" >> ${REQDIR}/out.log
fi

exit $RetVal











