From: Junio C Hamano Date: Wed, 27 Oct 2010 05:02:52 +0000 (-0700) Subject: Merge branch 'ab/send-email-perl' X-Git-Tag: v1.7.4-rc0~160 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=7ebee44167fc25b975f5543472c851ab1840af1b;p=git.git Merge branch 'ab/send-email-perl' * ab/send-email-perl: send-email: extract_valid_address use qr// regexes send-email: is_rfc2047_quoted use qr// regexes send-email: use Perl idioms in while loop send-email: make_message_id use "require" instead of "use" send-email: send_message die on $!, not $? send-email: use (?:) instead of () if no match variables are needed send-email: sanitize_address use qq["foo"], not "\"foo\"" send-email: sanitize_address use $foo, not "$foo" send-email: use \E***\Q instead of \*\*\* send-email: cleanup_compose_files doesn't need a prototype send-email: unique_email_list doesn't need a prototype send-email: file_declares_8bit_cte doesn't need a prototype send-email: get_patch_subject doesn't need a prototype send-email: use lexical filehandles during sending send-email: use lexical filehandles for $compose send-email: use lexical filehandle for opendir Conflicts: git-send-email.perl --- 7ebee44167fc25b975f5543472c851ab1840af1b diff --cc git-send-email.perl index f304ef913,db17aae02..f68ed5a5d --- a/git-send-email.perl +++ b/git-send-email.perl @@@ -139,11 -136,8 +139,8 @@@ my $have_mail_address = eval { require 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); @@@ -1269,12 -1247,22 +1266,12 @@@ foreach my $t (@files) $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; @@@ -1333,33 -1320,9 +1330,32 @@@ $message_id = undef; } +# 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 = (); - open(F, "$cmd \Q$file\E |") ++ open my $fh, "$cmd \Q$file\E |" + or die "($prefix) Could not execute '$cmd'"; - while() { - my $address = $_; ++ 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 F ++ 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; }