my $smtp;
my $auth;
- sub unique_email_list(@);
- sub cleanup_compose_files();
-
# Variables we fill in automatically, or via prompting:
-my (@to,$no_to,@cc,$no_cc,@initial_cc,@bcclist,$no_bcc,@xh,
+my (@to,$no_to,@initial_to,@cc,$no_cc,@initial_cc,@bcclist,$no_bcc,@xh,
$initial_reply_to,$initial_subject,@files,
$author,$sender,$smtp_authpass,$annotate,$compose,$time);
$c, $_) unless $quiet;
}
}
- close F;
+ close $fh;
- if (defined $cc_cmd && !$suppress_cc{'cccmd'}) {
- open my $fh, "$cc_cmd \Q$t\E |"
- or die "(cc-cmd) Could not execute '$cc_cmd'";
- while(my $c = <$fh>) {
- chomp $c;
- $c =~ s/^\s*//g;
- next if ($c eq $sender and $suppress_from);
- push @cc, $c;
- printf("(cc-cmd) Adding cc: %s from: '%s'\n",
- $c, $cc_cmd) unless $quiet;
- }
- close $fh
- or die "(cc-cmd) failed to close pipe to '$cc_cmd'";
- }
+ push @to, recipients_cmd("to-cmd", "to", $to_cmd, $t)
+ if defined $to_cmd;
+ push @cc, recipients_cmd("cc-cmd", "cc", $cc_cmd, $t)
+ if defined $cc_cmd && !$suppress_cc{'cccmd'};
if ($broken_encoding{$t} && !$has_content_type) {
$has_content_type = 1;
$message_id = undef;
}
- open(F, "$cmd \Q$file\E |")
+# Execute a command (e.g. $to_cmd) to get a list of email addresses
+# and return a results array
+sub recipients_cmd {
+ my ($prefix, $what, $cmd, $file) = @_;
+
+ my $sanitized_sender = sanitize_address($sender);
+ my @addresses = ();
- while(<F>) {
- my $address = $_;
++ open my $fh, "$cmd \Q$file\E |"
+ or die "($prefix) Could not execute '$cmd'";
- close F
++ while (my $address = <$fh>) {
+ $address =~ s/^\s*//g;
+ $address =~ s/\s*$//g;
+ $address = sanitize_address($address);
+ next if ($address eq $sanitized_sender and $suppress_from);
+ push @addresses, $address;
+ printf("($prefix) Adding %s: %s from: '%s'\n",
+ $what, $address, $cmd) unless $quiet;
+ }
++ close $fh
+ or die "($prefix) failed to close pipe to '$cmd'";
+ return @addresses;
+}
+
cleanup_compose_files();
- sub cleanup_compose_files() {
+ sub cleanup_compose_files {
unlink($compose_filename, $compose_filename . ".final") if $compose;
}