#!/bin/csh -f
# Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore)
# 
# Permission to use, copy, modify, and distribute this material 
# for any purpose and without fee is hereby granted, provided 
# that the above copyright notice and this permission notice 
# appear in all copies, and that the name of Bellcore not be 
# used in advertising or publicity pertaining to this 
# material without the specific, prior written permission 
# of an authorized representative of Bellcore.  BELLCORE 
# MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY 
# OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS", 
# WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
#

echo -n "To: "
set to = $<
echo -n "Subject: "
set subject = $<
echo -n "CC: "
set cc = $<
echo -n "Content-type: "
set ctype = $<

getfile:
echo -n "Name of file containing $ctype data: "
set prog = $<

set fname = /tmp/metasend.$$
if (! -e  $prog) then
    echo The file $prog does not exist.
    goto getfile
endif

echo "To: " "$to" > $fname
echo "Subject: " "$subject" >> $fname
echo "CC: " "$cc" >> $fname
echo "MIME-Version: RFC-XXXX" >> $fname
echo "Content-type: " $ctype >> $fname
retry:
echo "Do you want to encode this data for sending through the mail?"
echo "  1 -- No, it is already in 7 bit ASCII"
echo "  2 -- Yes, encode in base64 (most efficient)"
echo "  3 -- Yes, encode in quoted-printable (less efficient, more readable)"
set encode=$<
    switch ("$encode")
        case 1:
            set encodingprog = cat
            breaksw
        case 2:
            set encodingprog = "mmencode -b"
            echo "Content-Transfer-Encoding: base64" >> $fname
            breaksw
        case 3:
            set encodingprog = "mmencode -q"
            echo "Content-Transfer-Encoding: quoted-printable" >> $fname
            breaksw
        default:
            echo Unrecognized answer, please try again.
            goto retry
    endsw
echo  "" >> $fname
$encodingprog < $prog >> $fname
# Ensure last line has trailing carraige return
echo "" >> $fname

# /usr/lib/sendmail -t < $fname
/usr/lib/sendmail $to  $cc < $fname
if (! $status) then
    rm $fname
else
    echo Mail delivery failed, draft mail is in $fname
endif

