#!/usr/bin/perl
###############################################
##           Version 04.28.99                ##
###############################################
##   (c)1999 Daevid Vincent                  ##
## Unauthorized use of this code is strictly ##
## prohibited and subject to criminal        ##
## prosecution and or death                  ##
###############################################
##  Generates email lists from User_Table    ##
###############################################

#  list_announce
#  list_beta
#  list_devel
#  list_dist
#  list_support

print "\n";

$default_db_name  = "wt_client";
@EmailListName = ( "support", "beta", "devel", "dist", "announce");
use Mysql;
	
$dbh = Mysql->Connect("localhost",$default_db_name) or die "Error Connecting to $default_db_name: $Mysql::db_errstr<BR>\n";
$dbh->SelectDB($default_db_name);

	foreach $i (@EmailListName) {

			$sth = $dbh->Query ( "SELECT email FROM User_Table WHERE list_$i = 1" )
			 	and print "Querying $default_db_name User_Table for list_$i: "
			 	or die "Error Querying $default_db_name User_Table: $Mysql::db_errstr\n";
			$x = 0;
			$found = $sth->numrows;
			if ($found) {
				open(TEMP,">/home/majordom/lists/$i") || die("Can't open input file: $!");
				 while (($email) = $sth->FetchRow) { 
				 	if ($email ne "x\@x.xxx") { 
						print TEMP "$email\n"; 
						#print "$email\n";
						$x++
					} 
				 } # while FetchRow
				close(TEMP);
			} # if found
			print "Found $x/$found valid email addresses in $i.\n";
			
	} # end foreach EmailListName

#	print "cat /home/majordom/lists/announce_too >> /home/majordom/lists/announce\n\n";
#	system("cat /home/majordom/lists/announce_too >> /home/majordom/lists/announce");
