#!/usr/bin/perl
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%0D%0A/|/g;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
if ($in{$name}) {
$in{$name} = $in{$name}.",".$value;
}
else {
$in{$name} = $value;
}
}
$in{'txt_message'} =~ s/\|/%0D%0A/g;
$in{'txt_message'} =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$text_message = $in{'txt_message'};
$in{'html_message'} =~ s/\|/%0D%0A/g;
$in{'html_message'} =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$html_message = $in{'html_message'};
$totalEmails = $in{'rightrange'} - $in{'leftrange'} + 1;
$time_start = time() + $in{'time_diff'}*3600;
$lock = "2";
$pid = fork();
print "Content-type: text/html \n\n fork failed: $!" unless defined $pid;
if ($pid) {
if ($in{'archive'} eq "1") {
&archive;
#an archiving procedure at the end of this script
}
print "Content-type: text/html \n\n";
print "
List Administration
Congratulations!
The mailing has been started. You will receive a confirmation e-mail when the mailing has been completed.
";
exit(0);
}
else {
close (STDOUT);
$count = 0;
open(LIST,"$in{'list_dir'}/$in{'list'}/$in{'list'}.txt");
if ($lock){flock(LIST, $lock);}
@addresses=;
close(LIST);
$text_message =~ s/(.{60}\s)/$1\n/g;
my @boundaryv = (0..9, 'A'..'F');
srand(time ^ $$);
for (my $i = 0; $i++ < 24;) {
$boundary .= $boundaryv[rand(@boundaryv)];
}
for ($count = ($in{'leftrange'} - 1); $count < $in{'rightrange'}; $count++) {
$member = @addresses[$count];
chomp($member);
open (MAIL, "|$in{'mailprog'} -t") || die "Can't open $in{'mailprog'}!\n";
if ($in{'type'} eq "html") {
print MAIL "Content-type:text/html\n";
}
print MAIL "From: $in{'adminMail'}\n";
print MAIL "To: $member\n";
print MAIL "Subject: $in{'subject'}\n";
if ($in{'type'} eq "multipart") {
print MAIL "MIME-Version: 1.0\n";
print MAIL "Content-Type: multipart/mixed; boundary=\"----=_Next_Part_$boundary\"\n";
}
if ($in{'type'} eq "multipart") {
print MAIL "------=_Next_Part_$boundary\n";
print MAIL "Content-type: text/plain;\n";
print MAIL "charset=us-ascii\n";
print MAIL "Content-Transfer-Encoding: quoted-printable\n\n";
}
if ($in{'type'} eq "text" || $in{'type'} eq "multipart") {
print MAIL "$text_message\n\n";
if ($in{'remove_notice'} eq "1") {
print MAIL "---------------------------------------------------------------------\n";
print MAIL "Removal notice";
print MAIL "$in{'subscribeUrl'}?$unsubscribe&$in{'list'}&member\n";
print MAIL "---------------------------------------------------------------------\n\n";
}
}
if ($in{'type'} eq "multipart") {
print MAIL "------=_Next_Part_$boundary\n";
print MAIL "Content-type: text/html;\n";
print MAIL "charset=\"base64\"\n";
print MAIL "Content-Transfer-Encoding: quoted-printable\n\n";
}
if ($in{'type'} eq "multipart" || $in{'type'} eq "html") {
print MAIL "$html_message\n\n";
if ($in{'remove_notice'} eq "1") {
print MAIL "
";
print MAIL "---------------------------------------------------------------------
";
print MAIL "HTML removaql notice";
print MAIL "$in{'subscribeUrl'}?$unsubscribe&$in{'list'}&member
";
print MAIL "---------------------------------------------------------------------
";
}
}
close MAIL;
if (int($count/100)*100 == $count) {
$time_now = time() + $in{'time_diff'}*3600;
open(LOG, ">$in{'list_dir'}/$in{'list'}/log_sent.txt");
if ($lock){flock(LOG, $lock);}
$status = $count - $in{'leftrange'} + 1;
print LOG "$time_start" . "::" . "$totalEmails" . "::" . "$status" . "::" . "$time_now";
close(LOG);
}
}
}
$time_now = time() + $in{'time_diff'}*3600;
open(LOG, ">$in{'list_dir'}/$in{'list'}/log_sent.txt");
if ($lock){flock(LOG, $lock);}
print LOG "$time_start" . "::" . "$totalEmails" . "::" . "$count" . "::" . "$time_now" . "::end";
close(LOG);
open (MAIL, "|$in{'mailprog'} -t");
print MAIL "From: $in{'adminMail'}\n";
print MAIL "To: $in{'adminMail'}\n";
print MAIL "Subject: Congratulations!\n\n";
print MAIL "Congratulations!\nThe mailing was successfully sent to $totalEmails people by $ENV{'REMOTE_ADDR'}.\nMailing started at $time_start and ended at $time_now.\nHere is what was sent:\n\n-----\n\n";
print MAIL "Type - $in{'type'}\n\n";
print MAIL "Subject: $in{'subject'}\n\n$in{'message'}\n\n-----";
close (MAIL);
exit;