#old.pl
while (@emails = $sth->fetchrow) {
$id = $emails[0];
$subject = $emails[1];
$body = $emails[2];
$mailto = $emails[3];
$mailfrom = $emails[4];
$type = $emails[5];
push (@emailsToSend,"To: $mailto\nFrom: $mailfrom\nSubject: $subject\n\n$body\n");
push (@emailIds,$id);
push (@fromAddys,$mailfrom);
if ($type eq 'weekly') {
$totalweekly++;
}
elsif ($type eq 'daily') {
$totaldaily++;
}
elsif ($type eq 'blast') {
$totalnewsBlast++;
}
elsif ($type eq 'news') {
$totalnews++;
}
}
$emailcount = 0;
foreach $singleEmail (@emailsToSend) {
# SEND THE EMAIL
$mailfrom = $fromAddys[$emailcount];
open (OUT, ">>oldEmail.txt");
print OUT $singleEmail;
close(OUT);
$dbh->do(qq[UPDATE shawnTest set sent = 'Y' WHERE emailId=$emailIds[$emailcount]]) ||
&ErrorAlert("500E emailmonitor.pl DBI do error: ".DBI->errstr);
$emailcount++;
}
####
#new.pl
my %total=map{$_,0}(qw(weekly daily blast custom));
my $updateSql=qq[UPDATE shawnTest set sent='Y' WHERE emailId=?];
my $update=$dbh->prepare($updateSql);
while(@emails = $sth->fetchrow_array())
{
open (OUT, ">>newEmail.txt");
print OUT "To: $emails[3]\nFrom: $emails[4]\nSubject:$emails[1]\n\n$emails[2]\n";
close OUT;
$update->execute($emails[0]);
$total{$emails[5]}++;
}
####
my $t0 = new Benchmark;
fetchmail();
my $t1 = new Benchmark;
my $td = timediff($t1, $t0);
print "the code took:",timestr($td),"\n";