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 autodie qw(open close);
use DBI; use DBI;
use Encode qw(encode decode);
use Date::Manip::DM5; use Date::Manip::DM5;
use Supporters; 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'); my $TODAY = UnixDate(ParseDate("today"), '%Y-%m-%d');
@ -35,27 +39,33 @@ my(@supporterIds) = $sp->findDonor({});
foreach my $id (@supporterIds) { foreach my $id (@supporterIds) {
my $expiresOn = $sp->supporterExpirationDate($id); my $expiresOn = $sp->supporterExpirationDate($id);
my $isLapsed = ( (not defined $expiresOn) or $expiresOn lt $TODAY); 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); next unless $sp->emailOk($id);
my @emails; my %emails;
my $preferredEmail = $sp->getPreferredEmailAddress($id); my $email = $sp->getPreferredEmailAddress($id);
if (defined $preferredEmail) { if (defined $email) {
push(@emails, $preferredEmail); $emails{$email} = {};
} else { } else {
(@emails) = $sp->getEmailAddresses($id); %emails = $sp->getEmailAddresses($id);
} }
my(@emails) = keys(%emails);
my $fullEmailLine = ""; my $fullEmailLine = "";
my $emailTo = join(' ', @emails); my $emailTo = join(' ', @emails);
my $displayName = $sp->getDisplayName($supporterId); my $displayName = $sp->getDisplayName($id);
foreach my $email (@emails) { foreach my $email (@emails) {
$fullEmailLine .= ", " if ($fullEmailLine ne ""); $fullEmailLine .= ", " if ($fullEmailLine ne "");
my $line = ""; my $line = "";
if (defined $displayName) { if (defined $displayName) {
$line .= "\"$displayName\" "; $line .= $encoder->encode_phrase($displayName) . " ";
} }
$line .= "<$email>"; $line .= "<$email>";
$fullEmailLine .= Encode::encode("MIME-Header", $line); $fullEmailLine .= $line;
} }
open(SENDMAIL, "|-", "/usr/lib/sendmail -f \"$FROM_ADDDRESS\" -oi -oem -- \'$emailTo\'"); 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 DBI;
use Encode qw(encode decode); use Encode qw(encode decode);
use Encode qw(encode decode);
use Email::MIME::RFC2047::Encoder;
use Email::MIME; use Email::MIME;
use Date::Manip::DM5; use Date::Manip::DM5;
use Supporters; use Supporters;
my $encoder = Email::MIME::RFC2047::Encoder->new();
use LaTeX::Encode; use LaTeX::Encode;
my $BIG_DONOR_CUTOFF = 500.00; my $BIG_DONOR_CUTOFF = 500.00;
my $TODAY = UnixDate(ParseDate("today"), '%Y-%m-%d'); my $TODAY = UnixDate(ParseDate("today"), '%Y-%m-%d');
@ -177,17 +181,20 @@ foreach my $supporterId (sort @supporterIds) {
push(@message, $line); push(@message, $line);
} }
close MESSAGE; close MESSAGE;
my $emailTo = join(' ', @emails);
my $fullEmailLine = ""; my $fullEmailLine = "";
foreach my $email (@emails) { my $emailTo = join(' ', @emails);
$fullEmailLine .= ", " if ($fullEmailLine ne ""); my $displayName = $sp->getDisplayName($supporterId);
my $line = ""; foreach my $email (@emails) {
if (defined $displayName) { $fullEmailLine .= ", " if ($fullEmailLine ne "");
$line .= "\"$displayName\" "; my $line = "";
} if (defined $displayName) {
$line .= "<$email>"; $line .= $encoder->encode_phrase($displayName) . " ";
$fullEmailLine .= Encode::encode("MIME-Header", $line);
} }
$line .= "<$email>";
$fullEmailLine .= $line;
}
open(SENDMAIL, "|/usr/lib/sendmail -f \"$FROM_ADDRESS\" -oi -oem -- $emailTo $FROM_ADDRESS") or open(SENDMAIL, "|/usr/lib/sendmail -f \"$FROM_ADDRESS\" -oi -oem -- $emailTo $FROM_ADDRESS") or
die "unable to run sendmail: $!"; die "unable to run sendmail: $!";
@ -214,7 +221,7 @@ my $headerInfo = "$subject\n" . ("=" x length($subject)) .
( ($activeCounter{Annual} / ($totalSupporters - $lapsedCount)) * 100.00)) . ".\n\n"; ( ($activeCounter{Annual} / ($totalSupporters - $lapsedCount)) * 100.00)) . ".\n\n";
foreach my $type (keys %lapsedCounter) { 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); $type, $lapsedCounter{$type}, $activeCounter{$type}, $type, ($lapsedCounter{$type} / ($lapsedCounter{$type} + $activeCounter{$type})) * 100.00);
} }
$headerInfo .= "\n"; $headerInfo .= "\n";