#!/usr/bin/perl

#
# print header stuff
#
print "Content-type: text/html", "\n\n";
print "<html>\n";
print "<body background=\"nevada.gif\">\n";
#
#define stuff to grab data entered on form
#
require TripodCGI;
use CGI;
$cgi = new CGI;
#
# get the email address they entered on the form
#
$email_address=$cgi->param('email_address');
#
#remove spaces from the email address
#
$email_address=~s/ //g;
#
#convert the email address to upper case
#
$email_address=~s/[a-z]/\U$&/g;
#
#the email address must contain an @ to be valid
#
if ( $email_address !~ /@/) {
print "<h2>Error</h2>";
print "Error! your email address must contain an \@<p>";
print "This e-mail address is invalid<blockquote>$email_address</blockquote>";
exit;
}
#
#if the email address contains more then one @ its invalid
#
if ( $email_address =~ /@.*@/) {
print "<h2>Error</h2>";
print "Error! your email address must contain ONLY ONE \@<p>";
print "This e-mail address is invalid<blockquote>$email_address</blockquote>";
exit;
}
#
#open the file so we can read it
#
open(ALL,"email_press_releases.txt");
#
#lock the file so only ONE person can write to it
#
flock(ALL,LOCK_EX);
# and, in case someone appended
# while we were waiting...
#seek(ALL, 0, 2);
#
#read all the names in.
#
$i=0;
$deleted=0;
while(<ALL>){
#
#remove the stinking carrage return
#
chomp($_);
$n = $_;
#
#if it aint the same as the name they gave us
#stick it in an array and we will rewrite it later
#
if ($n ne $email_address ) {
$email[$i]=$n;
$i++;
}
else {
#
#this name matches the email address they want deleted
#dont write it out
#
#print "deleting $n $email_address<br>";
$deleted++;
}
};
#
#if we deleted some email addresses rewrite the file
#
if ( $deleted > 0 ) {
open(ALL,">email_press_releases.txt");
foreach $x (@email) {
print ALL "$x\n";
}
print "$email_address<p>has been removed from the COPWATCH mailing list<br>";
}
else {
#
#the email address they gave us was not in the file
#
print "<h2>Warning</h2>$email_address<p>in not in our files<br>";
}
#
#unlock the file
#
flock(ALL,LOCK_UN);
#
#close the file
#
close(ALL);
exit;