#! /bin/csh -f
#
# use: rtfmail subject file from to...
# bundle up an rtf file in NeXT-mail format and ship it
#
# M. J. Hawley
# MIT Media Laboratory
# mike@media-lab.mit.edu
#
# Copyright (c) August 1991
#
set subject = "$1" ; shift
set file = "$1"    ; shift
set from = "$1"    ; shift
set to = "$*"

echo "$subject" | tr ' :/' '__' | \
     sed -e 's/\*//g' -e 's/\(........................\).*/\1/' > /tmp/t$$
set fsub = "`cat /tmp/t$$`"
set tfile = ".tar.$$.$fsub.attach"
set ffile = /tmp/d$$

if (-d $file) then
   echo "You can't mail directories."
   exit
else
if ("$file" == "stdin") then
   cat > /tmp/s$$
   set file = /tmp/s$$
   mkdir $ffile
   cp $file $ffile/index.rtf
else
   mkdir $ffile
   cp $file $ffile/index.rtf
endif

(cd $ffile; \
 /NextApps/Mail.app/safetar cf - . |\
 compress | \
 uuencode $tfile > /tmp/t$$)

set wc = (`wc /tmp/t$$`)
set wco = (`wc $file`)

cat > /tmp/f$$ << eof
To: $to
From: $from
Subject: $subject
Next-Attachment: $tfile, $wc[3], 1/1, $wco[3], 0

eof

cat /tmp/f$$ /tmp/t$$ | /usr/lib/sendmail $to

rm -rf /tmp/t$$ /tmp/f$$ /tmp/s$$ $tfile $ffile
