From 4520c1595dfa9dfc3c32679ce7be145b817971ed Mon Sep 17 00:00:00 2001 From: Andrew Ruthven Date: Mon, 14 Sep 2009 11:11:09 +1000 Subject: [PATCH] Bit a bit more verbose, add Cc. --- merge.pl | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/merge.pl b/merge.pl index 7d07ac6..2037e98 100755 --- a/merge.pl +++ b/merge.pl @@ -41,7 +41,7 @@ die "Sorry, where is the template file?" unless -f $template; # A little big of prep. -my $csv = Text::CSV_XS->new(); +my $csv = Text::CSV_XS->new({ binary => 1 }); my $tt = Template->new(); my $tmplData = undef; @@ -71,7 +71,7 @@ while (my $cols = $csv->getline_hr($IN) ) { last unless %$cols; if ($verbose) { - print "Template variables:\n"; + print "\n\nTemplate variables:\n"; for my $key (sort keys %$cols) { print "$key: $cols->{$key}\n"; } @@ -81,7 +81,7 @@ while (my $cols = $csv->getline_hr($IN) ) { # Do the merge. my $out; if (! $tt->process(\$tmplData->{'body'}, $cols, \$out)) { - warn "Failed to process template: $tt->error()"; + warn "Failed to process template: " . $tt->error(); warn "Template: $tmplData->{'body'}\n" if $verbose; @@ -95,10 +95,13 @@ while (my $cols = $csv->getline_hr($IN) ) { print "\n\n"; } + my $bcc = $tmplData->{'bcc'}; + my $cc = $tmplData->{'cc'}; if ($send) { # If we're sending email, then send it, optionally with a BCC. print "Sending to $cols->{'email'}" . - ($tmplData->{'bcc'} ? " bcc $tmplData->{'bcc'} " : '') . "\n"; + ($bcc ? "\n BCC " . (ref($bcc) eq 'ARRAY' ? join(", ", @{$bcc}) : $bcc) . " " : '') . + ($cc ? "\n cC " . (ref($cc) eq 'ARRAY' ? join(", ", @{$cc}) : $cc) . " " : '') . "\n"; my @emails = ( $cols->{'email'} ); @@ -107,6 +110,7 @@ while (my $cols = $csv->getline_hr($IN) ) { From => $tmplData->{'from'}, Subject => $tmplData->{'subject'}, Bcc => $tmplData->{'bcc'}, + Cc => $tmplData->{'bc'}, Encoding=> "quoted-printable", Data => $out ); @@ -114,8 +118,9 @@ while (my $cols = $csv->getline_hr($IN) ) { $mail->send('sendmail'); } else { # Say who we want to send to. - print "Want to send to $cols->{'email'}" . - ($tmplData->{'bcc'} ? " bcc $tmplData->{'bcc'} " : '') . "\n"; + print "Want to send to: $cols->{'email'}" . + ($bcc ? "\n BCC " . (ref($bcc) eq 'ARRAY' ? join(", ", @{$bcc}) : $bcc) . " " : '') . + ($cc ? "\n CC " . (ref($cc) eq 'ARRAY' ? join(", ", @{$cc}) : $cc) . " " : '') . "\n"; } } -- 2.30.2