#!/usr/npac/bin/perl

#####################################
#                                   #
# Rob's Mass Mail v2.02             #
# Copyright 1998 by Rob Eisler      #
# eislerr@tdi.uregina.ca            #
# http://tdi.uregina.ca/~eislerr    #
#                                   #
# Last modified on February 26, '98 #
#                                   #
#####################################
#
# Copyright Notice:
# Copyright 1998 Robert S. Eisler.  All Rights Reserved.
#
# This code may be used and modified by anyone so long as this header and
# copyright information remains intact.  By using this code you agree to 
# indemnify Robert S. Eisler from any liability that might arise from its 
# use.  You must obtain written consent before selling or redistributing 
# this code.
#
#####################################

# declare the variables

$mailprog = '/usr/lib/sendmail';
$maildir = "/npac/server/foxsden00/sroot/droot/psf/FFE/m";
$mailurl = "http://www.foxsden.org/psf/FFE/m/massmail";
$cgi = 'http://boss.npac.syr.edu:8080/cgi-bin/pamfox/massmail.pl';

#########################################################################
# Don't change anything below here unless you know what you're doing :) #
#########################################################################

$err = 0;
$datafile = "$maildir/lists.txt";

print "Content-type: text/html\n\n";

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{
    ($name, $value) = split(/=/, $pair);

    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

    $FORM{$name} = $value;
}

$what = $FORM{'what'};

if ($what eq 'setmail') {
	&set_mail;
}

if ($what eq 'setsig') {
	&set_sig;
}

if ($what eq 'setaddlist') {
	&set_add_list;
}

if ($what eq 'setdellist') {
	&set_del_list;
}

if ($what eq 'setlist') {
	&set_list;
}

if ($what eq 'setpass') {
	&set_pass;
}

$pass = $FORM{'pass'};

open(FILE, "$maildir/pwd.txt") || die "Can't find password file.\n";

@lines = <FILE>;
close(FILE);

($p, $nochop) = split(/``/,$lines[0]);

if ($p ne "$pass") {
	$err = 1;
	&error1;
}

if ($what eq "makemail") {
	&make_mail;
}

if ($what eq 'changesig') {
	&change_sig;
}

if ($what eq 'addlist') {
	&add_list;
}

if ($what eq 'setdellist2') {
	&set_del_list2;
}

if ($what eq 'dellist') {
	&del_list;
}

if ($what eq 'setlist2') {
	&set_list2;
}

if ($what eq 'changelist') {
	&change_list;
}

if ($what eq 'changepass') {
	&change_pass;
}

sub set_mail {

	print "<html><head><title>Rob's Mass Mail</title></head>\n";
	print "<body bgcolor=white link=blue vlink=blue text=black>\n\n";
	print "<!--\n";
	print "Rob's Mass Mail v2.02 Copyright 1998 by Rob Eisler\n";
	print "eislerr\@tdi.uregina.ca\n";
	print "http://tdi.uregina.ca/~eislerr\n";
	print "-->\n\n";
	print "<center>\n";
	print "<font face=arial>\n";
	print "<h2>Compose a Message</h2>\n";
	print "<form action=\"$cgi\" method=post>\n";

	print "Password: <input type=\"password\" name=\"pass\" size=10><p>\n";

	open(FILE, "$datafile") || die "Can't find data file.\n";
	@list = <FILE>;
	close(FILE);
	$numlist = @list;

	print "Mailing List:\n";

	print "<select size=1 name=\"list\">\n";

	for ($a = 0; $a < $numlist; $a ++) {
		($one, $nochop) = split(/``/, $list[$a]);
		print "<option value=\"$one\">$one</option>\n";
	}

	print "</select><p>\n";

	close(FILE);

	print "Subject: <input type=\"text\" name=\"subject\" size=40><p>\n";
	print "Use salutation?<br>\n";
	print "<input type=\"radio\" name=\"usename\" value=\"yes\">Yes\n";
	print "<input type=\"radio\" name=\"usename\" value=\"no\">No<p>\n";

	print "Of the form:<br>\n";
	print "<input type=\"text\" name=\"beforename\" size=20>\n";
	print "NAME\n";
	print "<input type=\"text\" name=\"aftername\" size=20><p>\n";

	print "Include the number of messages sent?<br>\n";
	print "<input type=\"radio\" name=\"usenum\" value=\"yes\">Yes\n";
	print "<input type=\"radio\" name=\"usenum\" value=\"no\">No<p>\n";

	print "Include signature?<br>\n";
	print "<input type=\"radio\" name=\"usesig\" value=\"yes\">Yes\n";
	print "<input type=\"radio\" name=\"usesig\" value=\"no\">No<p>\n";

	print "Body of the e-mail:<br>\n";
	print "<textarea name=\"body\" cols=\"60\" rows=\"10\" wrap=\"virtual\"></textarea><br>\n";

	print "<input type=\"hidden\" name=\"what\" value=\"makemail\">\n";
	print "<input type=\"hidden\" name=\"edit\" value=\"yes\">\n";
	print "<input type=\"submit\" value=\"Go\">\n";
	print "<input type=\"reset\" value=\"Reset\">\n";

	print "</form>\n";
	print "<big><b>\&#183;</big></b> <a href=\"$mailurl\">Mass Mail Main</a> <big><b>\&#183;</b></big>\n";
	print "</font></center></body></html>\n";

	exit;

}

sub make_mail {

	$edit = $FORM{'edit'};
	$subject = $FORM{'subject'};
	$body = $FORM{'body'};
	$usename = $FORM{'usename'};
	$beforename = $FORM{'beforename'};
	$aftername = $FORM{'aftername'};
	$usenum = $FORM{'usenum'};
	$usesig = $FORM{'usesig'};
	$list = $FORM{'list'};

	if ($FORM{'body'}) {}
	else { 
		$err = 2;
		&error1; 
	}

	if ($subject eq '') {
		$subject = '< none >';
	}

	if ($usename eq 'yes' && $beforename eq '' && $aftername eq '') {
		$aftername = ',';
	}

	if ($usesig eq 'yes') {
		open(FILE, "$maildir/sig.txt") || die "Can't find signature file.\n";
		@sig = <FILE>;
		close(FILE);
		$numsig = @sig;
	}

	open (FILE, "$maildir/$list\.txt") || die "Can't open datafile\n";
	@info = <FILE>;
	close(FILE);
	$num = @info;

	$temp = 'NAME';
	$osubject = $subject;
	$obody = $body;
	$obname = $beforename;
	$oaname = $aftername;
	@osig = @sig;
	$subject =~ s/</&lt;/g;
	$subject =~ s/>/&gt;/g;
	$subject =~ s/"/&quot;/g;
	$beforename =~ s/</&lt;/g;
	$beforename =~ s/>/&gt;/g;
	$beforename =~ s/"/&quot;/g;
	$aftername =~ s/</&lt;/g;
	$aftername =~ s/>/&gt;/g;
	$aftername =~ s/"/&quot;/g;

	for ($a = 0; $a < $numsig; $a ++) {
		$sig[$a] =~ s/</&lt;/g;
		$sig[$a] =~ s/>/&gt;/g;
		$sig[$a] =~ s/"/&quot;/g;
	}

	$body =~ s/</&lt;/g;
	$body =~ s/>/&gt;/g;
	$body =~ s/"/&quot;/g;
	$body =~ s/\cM//g;
	$body =~ s/\n\n/<p>/g;
	$body =~ s/\n/<br>/g;

	if ($edit eq 'yes') {
	# preview message

		print "<html><head><title>Mass Mail</title></head>\n";
		print "<body bgcolor=white link=blue vlink=blue text=black>\n\n";
		print "<!--\n";
		print "Rob's Mass Mail v2.02 Copyright 1998 by Rob Eisler\n";
		print "eislerr\@tdi.uregina.ca\n";
		print "http://tdi.uregina.ca/~eislerr\n";
		print "-->\n\n";
		print "<center>\n";
		print "<font face=arial size=4><b>Message Preview</b></font><p>\n";

		if ($osubject eq '< none >') {
			print "<font face=arial size=2><b>\n";
			print "You did not enter a subject, so the subject has ";
			print "been entered as \&lt; none \&gt;.  You can change it ";
			print "below.</font></b><p>\n";
		}

		print "<table width=90% cellpadding=10 border=1 cellspacing=1 bgcolor=#000066>\n";

		print "<tr><td><font color=white>Subject: $subject</font></td></tr>\n";

		print "<tr><td><font color=white>Sending to mailing list \"$list\".</font></td></tr>\n";

		print "<tr><td><font color=white>";

		if ($usename eq 'yes') {
			print "$beforename$temp$aftername<p>\n";
		}
		print "$body\n";

		if ($usenum eq 'yes') {
			print "<p>\n";
			print "This message was sent to $num people.\n";
		}

		if ($usesig eq 'yes') {
			print "<p>\n";
			for ($a = 0; $a < $numsig; $a ++) {
				print "$sig[$a]";
				if ($a < ($numsig - 1)) {
					print "<br>";
				}
				print "\n";
			}
		}

		print "</font></td></tr>\n";
		print "</table>\n";

		print "<p>\n";
		print "<font face=arial>\n";

		print "<font size=2><b>\n";
		print "If you want to send the message as it is now, click 'no' ";
		print "for the next question, then click Go.  If you want to ";
		print "edit the message, leave the next question as 'yes', edit ";
		print "the message below, and then click Go.</b></font><p>\n";

		print "<form action=\"$cgi\" method=\"post\">\n";

		print "Do you want to edit this message?<br>\n";
		print "<input checked type=\"radio\" name=\"edit\" value=\"yes\"> Yes\n";
		print "<input type=\"radio\" name=\"edit\" value=\"no\"> No\n";

		print "<p>\n";

		print "<input type=\"submit\" value=\"Go\">\n";
		print "<input type=\"reset\" value=\"Reset\">\n<p>";

		$osubject =~ s/"/'/g;

		open(FILE, "$datafile") || die "Can't find data file.\n";
		@list = <FILE>;
		close(FILE);
		$numlist = @list;

		print "Mailing List:\n";

		print "<select size=1 name=\"list\">\n";

		for ($a = 0; $a < $numlist; $a ++) {
			($one, $nochop) = split(/``/, $list[$a]);
			if ($one eq $list) {
				print "<option selected value=\"$one\">$one</option>\n";
			} else {
				print "<option value=\"$one\">$one</option>\n";
			}
		}

		print "</select><p>\n";

		close(FILE);

		print "Subject: <input type=\"text\" name=\"subject\" value=\"$osubject\" size=40><p>\n";

		print "Use salutation?<br>\n";

		if ($usename eq 'yes') {
			print "<input checked type=\"radio\" name=\"usename\" value=\"yes\"> Yes\n";
			print "<input type=\"radio\" name=\"usename\" value=\"no\"> No\n";
		} else {
			print "<input type=\"radio\" name=\"usename\" value=\"yes\"> Yes\n";
			print "<input checked type=\"radio\" name=\"usename\" value=\"no\"> No\n";
		}

		print "<p>\n";

		print "Of the form:<br>\n";
		print "<input type=\"text\" name=\"beforename\" value=\"$obname\" size=20>\n";
		print "NAME\n";
		print "<input type=\"text\" name=\"aftername\" value=\"$oaname\" size=20>\n";
		print "<p>\n";

		print "Include the number of messages sent?<br>\n";

		if ($usenum eq 'yes') {
			print "<input checked type=\"radio\" name=\"usenum\" value=\"yes\"> Yes\n";
			print "<input type=\"radio\" name=\"usenum\" value=\"no\"> No\n";
		} else {
			print "<input type=\"radio\" name=\"usenum\" value=\"yes\"> Yes\n";
			print "<input checked type=\"radio\" name=\"usenum\" value=\"no\"> No\n";
		}

		print "<p>\n";

		print "Include signature?<br>\n";

		if ($usesig eq 'yes') {
			print "<input checked type=\"radio\" name=\"usesig\" value=\"yes\"> Yes\n";
			print "<input type=\"radio\" name=\"usesig\" value=\"no\"> No\n";
		} else {
			print "<input type=\"radio\" name=\"usesig\" value=\"yes\"> Yes\n";
			print "<input checked type=\"radio\" name=\"usesig\" value=\"no\"> No\n";
		}

		print "<p>\n";

		print "Body of the e-mail:<br>\n";

		print "<textarea name=\"body\" cols=\"60\" rows=\"10\" wrap=\"virtual\">\n";
		print "$obody\n";
		print "</textarea><p>\n";

		print "<input type=\"hidden\" name=\"pass\" value=\"$pass\">\n";
		print "<input type=\"hidden\" name=\"what\" value=\"makemail\">\n";

		print "<input type=\"submit\" value=\"Go\">\n";
		print "<input type=\"reset\" value=\"Reset\">\n";

		print "</form>\n";
		print "<big><b>\&#183;</big></b> <a href=\"$mailurl\">Mass Mail Main</a> <big><b>\&#183;</b></big>\n";
		print "</center></font></body></html>\n";

	}
	else {
	# send message

		print "<html><head><title>Mass Mail Complete</title></head>";
		print "<body bgcolor=white link=blue vlink=blue text=black>\n\n";
		print "<!--\n";
		print "Rob's Mass Mail v2.02 Copyright 1998 by Rob Eisler\n";
		print "eislerr\@tdi.uregina.ca\n";
		print "http://tdi.uregina.ca/~eislerr\n";
		print "-->\n\n";
		print "<font face=arial>\n";
		print "<center>";
		print "<font size=5>Your message has been sent.</font><p>";
		print "The message \"$subject\" was sent to the following $num people.<p>\n";
		print "</center>";
		print "<ul>\n";

		for ($a = 0; $a < $num; $a++) {

			($recipient,$name,$nochop) = split(/``/,$info[$a]);

			open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n";

			print MAIL "Subject: $osubject\n";

			if ($usename eq 'yes') {
				print MAIL "$obname$name$oaname\n\n";
			}

			print MAIL "$obody\n";

			if ($usenum eq 'yes') {
				print MAIL "\n";
				print MAIL "This message was sent to $num people.\n";
			}

			if ($usesig eq 'yes') {
				print MAIL "\n";
				for ($b = 0; $b < $numsig; $b ++) {
					print MAIL "$osig[$b]";
				}
			}

			close (MAIL);

			print "<li> \"$name\" - $recipient </li>\n";

		}

		print "</ul><p>\n";
		print "<center>\n";
		print "<big><b>\&#183;</big></b> <a href=\"$mailurl\">Mass Mail Main</a> <big><b>\&#183;</b></big>\n";
		print "</center></font></body></html>\n";

	}

}

sub set_sig {

	open(FILE, "$maildir/sig.txt") || die "Can't find sig file.\n";
	@sig = <FILE>;
	close(FILE);
	$numsig = @sig;

	print "<html><head><title>Change Signature</title></head>\n";
	print "<body bgcolor=white link=blue vlink=blue text=black>\n\n";
	print "<!--\n";
	print "Rob's Mass Mail v2.02 Copyright 1998 by Rob Eisler\n";
	print "eislerr\@tdi.uregina.ca\n";
	print "http://tdi.uregina.ca/~eislerr\n";
	print "-->\n\n";
	print "<font face=arial>\n";
	print "<center>\n";
	print "<font size=5>Change Signature</font><p>\n";

	print "<form action=\"$cgi\" method=\"post\">\n";

	print "Password: <input type=\"password\" name=\"pass\" size=10><p>\n";

	print "<textarea cols=60 rows=5 name=\"signature\">\n";
	for ($a = 0; $a < $numsig; $a ++) {
		print "$sig[$a]";
	}
	print "</textarea><br>\n";

	print "<input type=\"hidden\" name=\"what\" value=\"changesig\">\n";
	print "<input type=\"submit\" value=\"Go\">\n";
	print "</form>\n";
	print "<big><b>\&#183;</big></b> <a href=\"$mailurl\">Mass Mail Main</a> <big><b>\&#183;</b></big>\n";
	print "</center></font></body></html>\n";
	exit;

}

sub change_sig {

	$signature = $FORM{'signature'};

	open(FILE, ">$maildir/sig.txt") || die "Can't find signature file.\n";
	print FILE "$signature";
	close(FILE);

	print "<html><head><title>Signature Changed</title></head>\n";
	print "<body bgcolor=white link=blue vlink=blue text=black>\n\n";
	print "<!--\n";
	print "Rob's Mass Mail v2.02 Copyright 1998 by Rob Eisler\n";
	print "eislerr\@tdi.uregina.ca\n";
	print "http://tdi.uregina.ca/~eislerr\n";
	print "-->\n\n";
	print "<font face=arial>\n";
	print "<center>\n";
	print "<font size=5>Signature Changed!</font><p>\n";
	print "<big><b>\&#183;</big></b> <a href=\"$mailurl\">Mass Mail Main</a> <big><b>\&#183;</b></big>\n";
	print "</center></font></body></html>\n";
	exit;

}

sub set_add_list {

	print "<html><head><title>Add a Mailing List</title></head>\n";
	print "<body bgcolor=white link=blue vlink=blue text=black>\n\n";
	print "<!--\n";
	print "Rob's Mass Mail v2.02 Copyright 1998 by Rob Eisler\n";
	print "eislerr\@tdi.uregina.ca\n";
	print "http://tdi.uregina.ca/~eislerr\n";
	print "-->\n\n";
	print "<font face=arial>\n";
	print "<center>\n";
	print "<font size=5>Add a Mailing List</font><p>\n";

	print "<form action=\"$cgi\" method=\"post\">\n";

	print "Password: <input type=\"password\" name=\"pass\" size=10><p>\n"; 

	print "Please enter the name of the new list:<br>\n";
	print "<input type=\"text\" name=\"newlist\" size=20><br>\n";

	print "<input type=\"hidden\" name=\"what\" value=\"addlist\">\n";
	print "<input type=\"submit\" value=\"Go\">\n";
	print "</form>\n";
	print "<big><b>\&#183;</big></b> <a href=\"$mailurl\">Mass Mail Main</a> <big><b>\&#183;</b></big>\n";
	print "</center></font></body></html>\n";
	exit;

}

sub add_list {

	$newlist = $FORM{'newlist'};

	$newlist =~ s/ /_/g;
	$newlist =~ s/#//g;
	$newlist =~ s/\&//g;
	$newlist =~ s/\@//g;
	$newlist =~ s/\*//g;
	$newlist =~ s/\?//g;
	$newlist =~ s/\$//g;
	$newlist =~ s/%//g;
	$newlist =~ s/`//g;
	$newlist =~ s/~//g;
	$newlist =~ s/\|//g;
	$newlist =~ s/"//g;
	$newlist =~ s/'//g;
	$newlist =~ s/://g;
	$newlist =~ s/;//g;
	$newlist =~ s/\!//g;
	$newlist =~ s/\^//g;
	$newlist =~ s/\(//g;
	$newlist =~ s/\)//g;
	$newlist =~ s/\\//g;
	$newlist =~ s/\[//g;
	$newlist =~ s/\]//g;
	$newlist =~ s/\{//g;
	$newlist =~ s/\}//g;
	$newlist =~ s/\///g;
	$newlist =~ s/\.//g;
	$newlist =~ s/,//g;
	$newlist =~ s/\+//g;
	$newlist =~ s/\=//g;
	$newlist =~ s/\-//g;
	$newlist =~ s/\<//g;
	$newlist =~ s/\>//g;



	if ($newlist eq '') {
		$err = 6;
		&error1;
	}

	open(FILE, "$datafile") || die "Can't find data file.\n";
	@list = <FILE>;
	close(FILE);
	$numlist = @list;

	$found = 0;

	for ($a = 0; $a < $numlist; $a++) {
		($one, $nochop) = split(/``/, $list[$a]);
		if ($newlist eq $one) {
			$found = 1;
		}
	}		

	if ($found == 0) {
		open(FILE, ">$datafile") || die "MWAHAHA\n";
		for ($a = 0; $a < $numlist; $a++) {
			($one, $nochop) = split(/``/, $list[$a]);
			print FILE "$one``xx\n";
		}
		print FILE "$newlist``xx";
		close(FILE);

		open(FILE, ">$maildir/$newlist\.txt") || die "MWAHAHA\n";
		print FILE "person1\@somewhere.com``Name 1``x\n";
		print FILE "person2\@somewhere.com``Name 2``x\n";
		close(FILE);
		
		print "<html><head><title>List Added</title></head>\n";
		print "<body bgcolor=white link=blue vlink=blue text=black>\n\n";
		print "<!--\n";
		print "Rob's Mass Mail v2.02 Copyright 1998 by Rob Eisler\n";
		print "eislerr\@tdi.uregina.ca\n";
		print "http://tdi.uregina.ca/~eislerr\n";
		print "-->\n\n";
		print "<font face=arial>\n";
		print "<center>\n";
		print "<font size=5>List '$newlist' Added</font><p>\n";
		print "<big><b>\&#183;</big></b> <a href=\"$mailurl\">Mass Mail Main</a> <big><b>\&#183;</big></b>\n";
		print "</center></font></body></html>\n";

	}
	else {
		$err = 4;
		&error1;
	}

	exit;

}

sub set_del_list {

	open(FILE, "$datafile") || die "Can't find data file.\n";
	@list = <FILE>;
	close(FILE);
	$numlist = @list;

	if ($numlist <= 1) {
		$err = 5;
		&error1;
	}

	print "<html><head><title>Delete a Mailing List</title></head>\n";
	print "<body bgcolor=white link=blue vlink=blue text=black>\n\n";
	print "<!--\n";
	print "Rob's Mass Mail v2.02 Copyright 1998 by Rob Eisler\n";
	print "eislerr\@tdi.uregina.ca\n";
	print "http://tdi.uregina.ca/~eislerr\n";
	print "-->\n\n";
	print "<font face=arial>\n";
	print "<center>\n";
	print "<font size=5>Delete a Mailing List</font><p>\n";

	print "<form action=\"$cgi\" method=\"post\">\n";

	print "Password: <input type=\"password\" name=\"pass\" size=10><p>\n";

	print "Delete which list?<br>\n";

	print "<select size=1 name=\"list\">\n";

	for ($a = 0; $a < $numlist; $a ++) {
		($one, $nochop) = split(/``/, $list[$a]);		
 		print "<option value=\"$one\">$one</option>\n";
	}

	print "</select>\n";

	print "<input type=\"hidden\" name=\"what\" value=\"setdellist2\">\n";
	print "<input type=\"submit\" value=\"Go\">\n";
	print "</form>\n";
	print "<big><b>\&#183;</big></b> <a href=\"$mailurl\">Mass Mail Main</a> <big><b>\&#183;</b></big>\n";
	print "</center></font></body></html>\n";
	exit;

}

sub set_del_list2 {

	open(FILE, "$datafile") || die "Can't find data file.\n";
	@list = <FILE>;
	close(FILE);
	$numlist = @list;

	if ($numlist <= 1) {
		$err = 5;
		&error1;
	}

	$dellist = $FORM{'list'};

	print "<html><head><title>Delete List - Confirm</title></head>\n";
	print "<body bgcolor=white link=blue vlink=blue text=black>\n\n";
	print "<!--\n";
	print "Rob's Mass Mail v2.02 Copyright 1998 by Rob Eisler\n";
	print "eislerr\@tdi.uregina.ca\n";
	print "http://tdi.uregina.ca/~eislerr\n";
	print "-->\n\n";
	print "<font face=arial>\n";
	print "<center>\n";
	print "<font size=5>Delete List - Confirm</font><p>\n";

	print "<form action=\"$cgi\" method=\"post\">\n";

	print "Are you sure you want to delete \"$dellist\"?<br>\n";

	print "<input type=\"hidden\" name=\"pass\" value=\"$pass\">\n";
	print "<input type=\"hidden\" name=\"list\" value=\"$dellist\">\n";
	print "<input type=\"hidden\" name=\"what\" value=\"dellist\">\n";
	print "<input type=\"submit\" value=\"Go\">\n";
	print "</form>\n";
	print "<big><b>\&#183;</big></b> <a href=\"$mailurl\">Mass Mail Main</a> <big><b>\&#183;</b></big>\n";
	print "</center></font></body></html>\n";
	exit;

}

sub del_list {

	open(FILE, "$datafile") || die "Can't find data file.\n";
	@list = <FILE>;
	close(FILE);
	$numlist = @list;

	if ($numlist <= 1) {
		$err = 5;
		&error1;
	}

	$dellist = $FORM{'list'};

	open(FILE, ">$datafile") || die "MWAHAHA\n";

	for ($a = 0; $a < $numlist; $a++) {
		($one, $nochop) = split(/``/, $list[$a]);		
		if ($dellist ne $one) {
			print FILE "$one``xx\n";
		}
	}

	close(FILE);

	open(FILE, ">$maildir/$dellist\.txt") || die "MWAHAHA\n";
	print FILE " ";
	close(FILE);

	print "<html><head><title>List Deleted</title></head>\n";
	print "<body bgcolor=white link=blue vlink=blue text=black>\n\n";
	print "<!--\n";
	print "Rob's Mass Mail v2.02 Copyright 1998 by Rob Eisler\n";
	print "eislerr\@tdi.uregina.ca\n";
	print "http://tdi.uregina.ca/~eislerr\n";
	print "-->\n\n";
	print "<font face=arial>\n";
	print "<center>\n";
	print "<font size=5>List '$dellist' Deleted</font><p>\n";
	print "<big><b>\&#183;</big></b> <a href=\"$mailurl\">Mass Mail Main</a> <big><b>\&#183;</big></b>\n";
	print "</center></font></body></html>\n";
	exit;

}

sub set_list {

	open(FILE, "$datafile") || die "Can't find data file.\n";
	@list = <FILE>;
	close(FILE);
	$numlist = @list;

	print "<html><head><title>Edit a Mailing List</title></head>\n";
	print "<body bgcolor=white link=blue vlink=blue text=black>\n\n";
	print "<!--\n";
	print "Rob's Mass Mail v2.02 Copyright 1998 by Rob Eisler\n";
	print "eislerr\@tdi.uregina.ca\n";
	print "http://tdi.uregina.ca/~eislerr\n";
	print "-->\n\n";
	print "<font face=arial>\n";
	print "<center>\n";
	print "<font size=5>Edit a Mailing List</font><p>\n";

	print "<form action=\"$cgi\" method=\"post\">\n";

	print "Password: <input type=\"password\" name=\"pass\" size=10><p>\n";

	print "Edit which list?<br>\n";

	print "<select size=1 name=\"list\">\n";

	for ($a = 0; $a < $numlist; $a ++) {
		($one, $nochop) = split(/``/, $list[$a]);
		print "<option value=\"$one\">$one</option>\n";
	}

	print "</select>\n";

	print "<input type=\"hidden\" name=\"what\" value=\"setlist2\">\n";
	print "<input type=\"submit\" value=\"Go\">\n";
	print "</form>\n";
	print "<big><b>\&#183;</big></b> <a href=\"$mailurl\">Mass Mail Main</a> <big><b>\&#183;</b></big>\n";
	print "</center></font></body></html>\n";
	exit;

}

sub set_list2 {

	$editlist = $FORM{'list'};

	open(FILE, "$maildir/$editlist\.txt") || die "Can't find data file.\n";
	@list = <FILE>;
	close(FILE);
	$numlist = @list;

	print "<html><head><title>Edit a Mailing List</title></head>\n";
	print "<body bgcolor=white link=blue vlink=blue text=black>\n\n";
	print "<!--\n";
	print "Rob's Mass Mail v2.02 Copyright 1998 by Rob Eisler\n";
	print "eislerr\@tdi.uregina.ca\n";
	print "http://tdi.uregina.ca/~eislerr\n";
	print "-->\n\n";
	print "<font face=arial>\n";
	print "<center>\n";
	print "<font size=5>Edit a Mailing List</font><p>\n";

	print "<form action=\"$cgi\" method=\"post\">\n";

	print "Password: <input type=\"password\" name=\"pass\" size=10><p>\n";

	print "<font size=2>Edit the mailing list below.  Enter each recipient, one per line, with their e-mail address first, followed by their name.  Separate each address and name by two hyphens --</font><br>\n";

	print "<textarea cols=60 rows=5 name=\"list\">\n";

	for ($a = 0; $a < $numlist; $a ++) {
		($one, $two, $nochop) = split(/``/, $list[$a]);
		print "$one--$two\n";
	}

	print "</textarea><br>\n";

	print "<input type=\"hidden\" name=\"what\" value=\"changelist\">\n";
	print "<input type=\"hidden\" name=\"editlist\" value=\"$editlist\">\n";
	print "<input type=\"submit\" value=\"Go\">\n";
	print "</form>\n";
	print "<big><b>\&#183;</big></b> <a href=\"$mailurl\">Mass Mail Main</a> <big><b>\&#183;</b></big>\n";
	print "</center></font></body></html>\n";
	exit;

}

sub change_list {

	$list = $FORM{'list'};
	$editlist = $FORM{'editlist'};

	(@splitlist) = split(/\n/, $list);

	$numlist = @splitlist;

	open(FILE, ">$maildir/$editlist\.txt") || die "Can't find data file.\n";

	for ($a = 0; $a < $numlist; $a++) {

		($one, $two) = split(/--/, $splitlist[$a]);
		$two =~ s/\cM//g;
		print FILE "$one``$two``x\n";

	}

	close(FILE);

	print "<html><head><title>Mailing List Changed</title></head>\n";
	print "<body bgcolor=white link=blue vlink=blue text=black>\n\n";
	print "<!--\n";
	print "Rob's Mass Mail v2.02 Copyright 1998 by Rob Eisler\n";
	print "eislerr\@tdi.uregina.ca\n";
	print "http://tdi.uregina.ca/~eislerr\n";
	print "-->\n\n";
	print "<font face=arial>\n";
	print "<center>\n";
	print "<font size=5>List '$editlist' Changed</font><p>\n";
	print "<big><b>\&#183;</big></b> <a href=\"$mailurl\">Mass Mail Main</a> <big><b>\&#183;</b></big>\n";
	print "</center></font></body></html>\n";
	exit;

}

sub set_pass {

	print "<html><head><title>Change Password</title></head>\n";
	print "<body bgcolor=white link=blue vlink=blue text=black>\n\n";
	print "<!--\n";
	print "Rob's Mass Mail v2.02 Copyright 1998 by Rob Eisler\n";
	print "eislerr\@tdi.uregina.ca\n";
	print "http://tdi.uregina.ca/~eislerr\n";
	print "-->\n\n";
	print "<font face=arial>\n";
	print "<center>\n";

	print "<font size=5>Change Password</font><p>\n";
	print "<form action=\"$cgi\" method=\"post\">\n";

	print "<table border=0>\n";
	print "<tr><td align=right><font face=arial>Old Password: </font></td>\n";
	print "<td align=left><input type=\"password\" name=\"pass\" size=10></td></tr>\n";
	print "<tr><td align=right><font face=arial>New Password: </font></td>\n";
	print "<td align=left><input type=\"password\" name=\"newpass1\" size=10></td></tr>\n";
	print "<tr><td align=right><font face=arial>Retype New Password: </font></td>\n";
	print "<td align=left><input type=\"password\" name=\"newpass2\" size=10></td></tr>\n";
	print "</table><p>\n";

	print "<input type=\"hidden\" name=\"what\" value=\"changepass\">\n";
	print "<input type=\"submit\" value=\"Go\">\n";
	print "</form>\n";
	print "<big><b>\&#183;</big></b> <a href=\"$mailurl\">Mass Mail Main</a> <big><b>\&#183;</b></big>\n";
	print "</center></font></body></html>\n";
	exit;

}

sub change_pass {

	$newpass1 = $FORM{'newpass1'};
	$newpass2 = $FORM{'newpass2'};

	if ($newpass1 ne $newpass2) {
		$err = 3;
		&error1;
	}

	open(FILE, ">$maildir/pwd.txt") || die "Can't find password file.\n";
	print FILE "$newpass1``x";
	close(FILE);

	print "<html><head><title>Password Changed</title></head>\n";
	print "<body bgcolor=white link=blue vlink=blue text=black>\n\n";
	print "<!--\n";
	print "Rob's Mass Mail v2.02 Copyright 1998 by Rob Eisler\n";
	print "eislerr\@tdi.uregina.ca\n";
	print "http://tdi.uregina.ca/~eislerr\n";
	print "-->\n\n";
	print "<font face=arial>\n";
	print "<center>\n";
	print "<font size=5>Password Changed!</font><p>\n";
	print "<big><b>\&#183;</big></b> <a href=\"$mailurl\">Mass Mail Main</a> <big><b>\&#183;</b></big>\n";
	print "</center></font></body></html>\n";
	exit;

}

sub error1 {

	print "<html><head><title>Zoops!</title></head>\n";
	print "<body bgcolor = white link=blue vlink=blue text=black>\n\n";
	print "<!--\n";
	print "Rob's Mass Mail v2.02 Copyright 1998 by Rob Eisler\n";
	print "eislerr\@tdi.uregina.ca\n";
	print "http://tdi.uregina.ca/~eislerr\n";
	print "-->\n\n";
	print "<font face=arial>\n";
	print "<center>\n";
	print "<font size=5>Zoops!</font><p>\n";

	if ($err == 1) {
		print "Invalid Password<p>\n";
	} elsif ($err == 2) {
		print "You didn't enter anything for the body of the message!<p>\n";
	} elsif ($err == 3) {
		print "The two new password fields do not match!<p>\n";
	} elsif ($err == 4) {
		print "A list with that name already exists!<p>\n";
	} elsif ($err == 5) {
		print "You can't delete the last mailing list.<p>\n";
	} elsif ($err == 6) {
		print "You entered an improper list name.  Cut it out with the blanks and the weird characters, ok?<p>\n";
	} else {
		print "Error (unknown) - What did you do?<p>\n";
	}

	print "<big><b>\&#183;</big></b> <a href=\"$mailurl\">Mass Mail Main</a> <big><b>\&#183;</b></big>\n";
	print "</font></center></body></html>\n";
	exit;

}

