#!/bin/csh -f
# Usage: mkcmtform [ emailaddress [ basefilename ] ]
# 
# NOTE:  The mkcmtform script is useful at MIT Athena because we have
#        insanely long URL's based on full afs pathnames.  Most other
#        sites will benefit more from examples than from a script like
#        mkcmtform.  You do not need mkcmtform to use cgiemail.
# 

## Determine email address.

if ($#argv > 0) then
	set email = $argv[1]
else
	set email = ${USER}@MIT.EDU
endif

## Determine base filename to use.

if ($#argv > 1) then
	set basefilename = $argv[2]
else
	set basefilename = comments
endif
set tmptxt=/tmp/f$$.txt
set tmphtml=/tmp/f$$.html

echo The files $basefilename.txt and $basefilename.html
echo will be set up to send email to $email ....

## Create the comments.txt template.

cat << END_COMMENTS_TXT > $tmptxt
From: [email]
To: $email
Subject: [required-subject]
Errors-To: ${USER}@MIT.EDU

[required-body]
----
NOTE: This message was sent using a WWW form. The address [email]
was typed manually, and may easily be incorrect.
END_COMMENTS_TXT
cp -i $tmptxt $basefilename.txt

## Create the comments.html form.

set mydir=`pwd`
cat << END_COMMENTS_HTML > $tmphtml
<HTML>

    <HEAD>
    <TITLE>Comment Form for $email</TITLE>
    </HEAD>

    <BODY>
    <H1><IMG ALT="" ALIGN="middle"
SRC="/afs/athena.mit.edu/org/c/cwis/www/graphics/mlogo.gif">
    Comment Form for $email</H1>

    <HR>

    <!-- NOTE: the ACTION below must be changed if ${basefilename}.txt
        is ever moved from the directory it is now in:
        ${mydir} -->
    <FORM METHOD="POST"
ACTION="http://web.mit.edu/bin/cgiemail${mydir}/${basefilename}.txt">

      From: (your email address please)<BR>
      <INPUT NAME="email" SIZE=30><BR>
      Subject: (please don't leave blank)<BR>
      <INPUT NAME="required-subject" SIZE=60><BR>
      Message:<BR>
      <TEXTAREA NAME="required-body" ROWS=10 COLS=60></TEXTAREA><P>

      You may <INPUT TYPE="submit" VALUE="send email"> when done, or
      <INPUT TYPE="reset" VALUE="reset this form"> if you want to start over.

    </FORM>
    </BODY>

</HTML>
END_COMMENTS_HTML
cp -i $tmphtml $basefilename.html

rm -f $tmptxt $tmphtml
echo Done.
