$HOSTNAME    = $ENV{SERVER_HOSTNAME}; 
$SERVER_HOME = $ENV{SERVER_HOME};

$TOKEN = "\U$ARGV[0]";
($TYPE, $SOLVER) = split(/:/, $TOKEN);

if ($TOKEN =~ /^ADMIN:/) {
  $SOLVERS = $ENV{SERVER_ADMIN_SOLVERS};
} else {
  $SOLVERS = $ENV{SERVER_SOLVERS};
}
chop($TITLE = `cat $SOLVERS/$TOKEN/TITLE`);
if (-s "$SOLVERS/$TOKEN/config") {
  chop(@config = `cat $SOLVERS/$TOKEN/config`);
}
print "\n\n";
print "======================E-MAIL TEMPLATE======================\n\n";
print "Cut below, complete, and mail to $ENV{SERVER_EMAIL}.\n\n";
print "NOTES:\n\n";
print "   -Do not include the brackets (<, >, [, ]).\n";
print "   -Tokens in square brackets are optional.\n";
print "   -The token \"END-SOLVER-INPUT\" is only necessary if your\n";
print "    mailer attaches a signature to your outgoing mail.\n";
print "   -Tokens should not be inserted in submission files\n";
print "    uploaded via the Web or Submission Tool interfaces.\n\n";
print "-------------------------cut here--------------------------\n\n";
print "TYPE $TYPE\n";
print "SOLVER $SOLVER\n\n";

foreach (@config) {
  ($name, $default, $begin, $end, $file) = split(/:/);
  $name =~ s/(^\s*)(\S)/$2/; #Leading space
  $name =~ s/(\S)(\s*$)/$1/; #Trailing space
  $default =~ s/(^\s*)(\S)/$2/; #Leading space
  $default =~ s/(\S)(\s*$)/$1/; #Trailing space
  $begin = "\U$begin"; 
  $end = "\U$end"; 
  $begin =~ s/\s*//g; 
  $end =~ s/\s*//g; 
  if (($default eq "BINARY-ON") || ($default eq "BINARY-OFF")) {
    print "[$begin] = <yes/no>\n";
  } elsif ($end eq "NULL") {
    print "$begin = <$name>\n";
  } else {
    print "$begin\n";
    print "<$name>\n";
    print "$end\n";
  }
  print "\n";
}
print "END-SERVER-INPUT\n";
