mass email changes for encoding and skipping addresses.

This commit is contained in:
Bradley M. Kuhn 2018-01-24 11:47:47 -08:00
parent 2816c8ab2e
commit c0714f3995
2 changed files with 38 additions and 21 deletions

View file

@ -5,10 +5,14 @@ use warnings;
use autodie qw(open close);
use DBI;
use Encode qw(encode decode);
use Date::Manip::DM5;
use Supporters;
use Encode qw(encode decode);
use Email::MIME::RFC2047::Encoder;
use utf8;
my $encoder = Email::MIME::RFC2047::Encoder->new();
my $TODAY = UnixDate(ParseDate("today"), '%Y-%m-%d');
@ -35,27 +39,33 @@ my(@supporterIds) = $sp->findDonor({});
foreach my $id (@supporterIds) {
my $expiresOn = $sp->supporterExpirationDate($id);
my $isLapsed = ( (not defined $expiresOn) or $expiresOn lt $TODAY);
# next if $isLapsed;
# next unless $expiresOn lt "2017-02-01";
# invalid email address
my @invalidEmailAddresses = qw//;
next if ($id ~~ @invalidEmailAddresses);
next unless $sp->emailOk($id);
my @emails;
my $preferredEmail = $sp->getPreferredEmailAddress($id);
if (defined $preferredEmail) {
push(@emails, $preferredEmail);
my %emails;
my $email = $sp->getPreferredEmailAddress($id);
if (defined $email) {
$emails{$email} = {};
} else {
(@emails) = $sp->getEmailAddresses($id);
%emails = $sp->getEmailAddresses($id);
}
my(@emails) = keys(%emails);
my $fullEmailLine = "";
my $emailTo = join(' ', @emails);
my $displayName = $sp->getDisplayName($supporterId);
my $displayName = $sp->getDisplayName($id);
foreach my $email (@emails) {
$fullEmailLine .= ", " if ($fullEmailLine ne "");
my $line = "";
if (defined $displayName) {
$line .= "\"$displayName\" ";
$line .= $encoder->encode_phrase($displayName) . " ";
}
$line .= "<$email>";
$fullEmailLine .= Encode::encode("MIME-Header", $line);
$fullEmailLine .= $line;
}
open(SENDMAIL, "|-", "/usr/lib/sendmail -f \"$FROM_ADDDRESS\" -oi -oem -- \'$emailTo\'");

View file

@ -9,11 +9,15 @@ use autodie qw(open close);
use DBI;
use Encode qw(encode decode);
use Encode qw(encode decode);
use Email::MIME::RFC2047::Encoder;
use Email::MIME;
use Date::Manip::DM5;
use Supporters;
my $encoder = Email::MIME::RFC2047::Encoder->new();
use LaTeX::Encode;
my $BIG_DONOR_CUTOFF = 500.00;
my $TODAY = UnixDate(ParseDate("today"), '%Y-%m-%d');
@ -177,17 +181,20 @@ foreach my $supporterId (sort @supporterIds) {
push(@message, $line);
}
close MESSAGE;
my $emailTo = join(' ', @emails);
my $fullEmailLine = "";
my $emailTo = join(' ', @emails);
my $displayName = $sp->getDisplayName($supporterId);
foreach my $email (@emails) {
$fullEmailLine .= ", " if ($fullEmailLine ne "");
my $line = "";
if (defined $displayName) {
$line .= "\"$displayName\" ";
$line .= $encoder->encode_phrase($displayName) . " ";
}
$line .= "<$email>";
$fullEmailLine .= Encode::encode("MIME-Header", $line);
$fullEmailLine .= $line;
}
open(SENDMAIL, "|/usr/lib/sendmail -f \"$FROM_ADDRESS\" -oi -oem -- $emailTo $FROM_ADDRESS") or
die "unable to run sendmail: $!";
@ -214,7 +221,7 @@ my $headerInfo = "$subject\n" . ("=" x length($subject)) .
( ($activeCounter{Annual} / ($totalSupporters - $lapsedCount)) * 100.00)) . ".\n\n";
foreach my $type (keys %lapsedCounter) {
$headerInfo .= sprintf("%7s: Lapsed Count: %3d Active Count: %3d Percent of %7s Lapsed: %2.2f%\n",
$headerInfo .= sprintf("%7s: Lapsed Count: %3d Active Count: %3d Percent of %7s Lapsed: %2.2f\n",
$type, $lapsedCounter{$type}, $activeCounter{$type}, $type, ($lapsedCounter{$type} / ($lapsedCounter{$type} + $activeCounter{$type})) * 100.00);
}
$headerInfo .= "\n";