Support paper mailing for renewal notices.
This allows adding a .tex file and sending a paper renewal notice. This worked for me to send the paper renewal notices to Conservancy Supporters in late 2016.
This commit is contained in:
parent
5cf6dfb805
commit
fda04200df
1 changed files with 80 additions and 27 deletions
|
@ -13,9 +13,13 @@ use Email::MIME;
|
|||
use Date::Manip::DM5;
|
||||
use Supporters;
|
||||
|
||||
use LaTeX::Encode;
|
||||
my $BIG_DONOR_CUTOFF = 500.00;
|
||||
|
||||
my $TODAY = UnixDate(ParseDate("today"), '%Y-%m-%d');
|
||||
my $ONE_WEEK = UnixDate(DateCalc(ParseDate("today"), "+ 1 week"), '%Y-%m-%d');
|
||||
my $ONE_MONTH = UnixDate(DateCalc(ParseDate("today"), "+ 1 month"), '%Y-%m-%d');
|
||||
my $ONE_YEAR_AGO = UnixDate(DateCalc(ParseDate("today"), "- 1 year"), '%Y-%m-%d');
|
||||
my $TWO_YEARS_AGO = UnixDate(DateCalc(ParseDate("today"), "- 2 years"), '%Y-%m-%d');
|
||||
my $THREE_YEARS_AGO = UnixDate(DateCalc(ParseDate("today"), "- 3 years"), '%Y-%m-%d');
|
||||
|
||||
|
@ -54,8 +58,15 @@ my(%activeCounter, %lapsedCounter);
|
|||
|
||||
my %monthExpirations;
|
||||
|
||||
my $isPaper = 0;
|
||||
$isPaper = 1 if $EMAIL_TEMPLATE =~ /\.tex$/;
|
||||
|
||||
if ($isPaper) {
|
||||
open(ENVELOPES, ">envelopes-ready-to-send.tex") or die "unable to open labels: $!";
|
||||
}
|
||||
my $totalSupporters = 0;
|
||||
foreach my $supporterId (@supporterIds) {
|
||||
my $sentCount = 0;
|
||||
foreach my $supporterId (sort @supporterIds) {
|
||||
next unless $sp->isSupporter($supporterId);
|
||||
$totalSupporters++;
|
||||
my $expiresOn = $sp->supporterExpirationDate($supporterId);
|
||||
|
@ -107,7 +118,46 @@ foreach my $supporterId (@supporterIds) {
|
|||
print STDERR "$supporterId skipped since he is not lapsed\n" if ( (not $isLapsed and not $lapsesSoon) and $VERBOSE > 1);
|
||||
next unless $isLapsed or $lapsesSoon;
|
||||
|
||||
my $displayName = $sp->getDisplayName($supporterId);
|
||||
if ($isPaper) {
|
||||
my $latexDisplayName = latex_encode($displayName);
|
||||
$latexDisplayName =~ s/\\unmatched\{0141\}/\L{}/g;
|
||||
$latexDisplayName =~ s/\\unmatched\{0142\}/\l{}/g;
|
||||
if ($latexDisplayName =~ /unmatched/) {
|
||||
print "Skipping $supporterId because the address has characters I can't print in LaTeX\n name was: ", encode('UTF-8', $displayName), "\n";
|
||||
next;
|
||||
}
|
||||
my $postalAddress = $sp->getPreferredPostalAddress($supporterId);
|
||||
if (not defined $postalAddress) {
|
||||
my(@postalAddresses) = $sp->getPostalAddresses($supporterId);
|
||||
$postalAddress = $postalAddresses[0];
|
||||
}
|
||||
if ( (not defined $postalAddress) or $postalAddress =~ /^\s*$/m or $postalAddress eq $displayName) {
|
||||
print "Skipping $supporterId because no postal address was available\n";
|
||||
next;
|
||||
}
|
||||
|
||||
my $latexPostal = latex_encode($postalAddress);
|
||||
$latexPostal =~ s/\\unmatched\{0141\}/\L{}/g;
|
||||
$latexPostal =~ s/\\unmatched\{0142\}/\l{}/g;
|
||||
if ($latexPostal =~ /unmatched/) {
|
||||
print "Skipping $supporterId because the address has characters the post office will not accept\n Address was: ", encode('UTF-8', $postalAddress), "\n";
|
||||
next;
|
||||
}
|
||||
$latexPostal = join(' \\\\ ', split('\n', $latexPostal));
|
||||
print ENVELOPES '\mlabel{}{TO: \\\\ ' . $latexPostal . "}\n";
|
||||
|
||||
open(MESSAGE, "<", $EMAIL_TEMPLATE);
|
||||
open(LETTER, ">", sprintf("%4.4d", $sentCount++) . "-" . $supporterId . ".tex");
|
||||
while (my $line = <MESSAGE> ) {
|
||||
$line =~ s/FIXME-LAST-DONATE-DATE/$lastDonateDate/g;
|
||||
$line =~ s/FIXME-ADDRESS/$latexPostal/g;
|
||||
$line =~ s/FIXME-FULL-NAME/$latexDisplayName/g;
|
||||
print LETTER $line;
|
||||
}
|
||||
close LETTER;
|
||||
close MESSAGE;
|
||||
} else {
|
||||
open(MESSAGE, "<", $EMAIL_TEMPLATE);
|
||||
my @message;
|
||||
while (my $line = <MESSAGE> ) {
|
||||
|
@ -116,7 +166,6 @@ foreach my $supporterId (@supporterIds) {
|
|||
}
|
||||
close MESSAGE;
|
||||
my $emailTo = join(' ', @emails);
|
||||
my $displayName = $sp->getDisplayName($supporterId);
|
||||
my $fullEmailLine = "";
|
||||
foreach my $email (@emails) {
|
||||
$fullEmailLine .= ", " if ($fullEmailLine ne "");
|
||||
|
@ -133,11 +182,15 @@ foreach my $supporterId (@supporterIds) {
|
|||
print STDERR "Sending to $supporterId at $emailTo who expires on $expiresOn\n";
|
||||
print SENDMAIL "To: $fullEmailLine\n";
|
||||
print SENDMAIL @message;
|
||||
|
||||
close SENDMAIL;
|
||||
sleep 1;
|
||||
}
|
||||
$sp->addRequest({donorId => $supporterId, requestType => $REQUEST_NAME});
|
||||
}
|
||||
if ($isPaper) {
|
||||
close ENVELOPES;
|
||||
exit 0;
|
||||
}
|
||||
|
||||
my $subject = "Supporter lapsed report for $TODAY";
|
||||
my $per = ( ($lapsedCount / $totalSupporters) * 100.00);
|
||||
|
|
Loading…
Reference in a new issue