use Text::CSV_XS;
use MIME::Entity;
use MIME::Types;
+use Mail::GnuPG;
my $dir = undef;
my $vars = "";
's|send' => \$send,
);
+# Allow a lone directory on the command line.
+$dir ||= shift;
+
# If we're given a directory then look for the merge files in there.
if (defined $dir) {
$vars = "$dir/merge.csv"
}
}
+# If we've been asked to use encryption, set things up
+my $mg;
+if ($tmplData->{'encrypt'}) {
+ $mg = new Mail::GnuPG;
+}
+
my $IN = new FileHandle;
open($IN, $vars)
|| die "Failed to open $vars for reading: $!\n";
unless grep {/$tmplData->{'attachment_col'}/} @$headers;
}
+my @gpg_failed_addresses;
+
while (my $cols = $csv->getline_hr($IN) ) {
last unless %$cols;
);
}
- $mail->send('sendmail');
+ for my $extra (qw/cc bcc/) {
+ push @emails, $tmplData->{$extra}
+ if defined $tmplData->{$extra};
+ }
+
+ my $ret = $mg->mime_encrypt($mail, @emails)
+ if defined $mg;
+
+ if (! defined $mg || $ret == 0) {
+ $ret = $mg->mime_sign($mail, $tmplData->{'from'})
+ if defined $mg;
+
+ if (! defined $mg || $ret == 0) {
+ $mail->send('sendmail');
+ } else {
+ die "Sorry, gpg sign error: " . join(", ", @{ $mg->{last_message} }) . "\n";
+ }
+ } else {
+ warn "Sorry, gpg encrypt error: " . join(", ", @{ $mg->{last_message} }) . "\n";
+ push @gpg_failed_addresses, @emails;
+ }
} else {
# Say who we want to send to.
print "Want to send to: $email_address" .