X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=git-send-email.perl;h=f68ed5a5d3208eb0669d7dc1289f40c567e077c7;hb=9cddf56ef13c8575ac0c68d82e6196e5b0a2900d;hp=5a0c4a8aefe8c1d5ea20ce783ff616c941535750;hpb=e9bf741b887aadd227557804d3560ebd07b1dd09;p=git.git diff --git a/git-send-email.perl b/git-send-email.perl index 5a0c4a8ae..f68ed5a5d 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -1,4 +1,4 @@ -#!/usr/bin/perl -w +#!/usr/bin/perl # # Copyright 2002,2005 Greg Kroah-Hartman # Copyright 2005 Ryan Anderson @@ -16,6 +16,7 @@ # and second line is the subject of the message. # +use 5.008; use strict; use warnings; use Term::ReadLine; @@ -61,6 +62,7 @@ git send-email [options] --envelope-sender * Email envelope sender. --smtp-server * Outgoing SMTP server to use. The port is optional. Default 'localhost'. + --smtp-server-option * Outgoing SMTP server option to use. --smtp-server-port * Outgoing SMTP server port. --smtp-user * Username for SMTP-AUTH. --smtp-pass * Password for SMTP-AUTH; not necessary. @@ -71,6 +73,7 @@ git send-email [options] Automating: --identity * Use the sendemail. options. + --to-cmd * Email To: via ` \$patch_path` --cc-cmd * Email Cc: via ` \$patch_path` --suppress-cc * author, self, sob, cc, cccmd, body, bodycc, all. --[no-]signed-off-by-cc * Send to Signed-off-by: addresses. Default on. @@ -137,7 +140,7 @@ my $smtp; my $auth; # 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); @@ -187,9 +190,11 @@ sub do_edit { } # Variables with corresponding config settings -my ($thread, $chain_reply_to, $suppress_from, $signed_off_by_cc, $cc_cmd); -my ($smtp_server, $smtp_server_port, $smtp_authuser, $smtp_encryption); -my ($identity, $aliasfiletype, @alias_files, @smtp_host_parts, $smtp_domain); +my ($thread, $chain_reply_to, $suppress_from, $signed_off_by_cc); +my ($to_cmd, $cc_cmd); +my ($smtp_server, $smtp_server_port, @smtp_server_options); +my ($smtp_authuser, $smtp_encryption); +my ($identity, $aliasfiletype, @alias_files, $smtp_domain); my ($validate, $confirm); my (@suppress_cc); my ($auto_8bit_encoding); @@ -210,10 +215,12 @@ my %config_bool_settings = ( my %config_settings = ( "smtpserver" => \$smtp_server, "smtpserverport" => \$smtp_server_port, + "smtpserveroption" => \@smtp_server_options, "smtpuser" => \$smtp_authuser, "smtppass" => \$smtp_authpass, - "smtpdomain" => \$smtp_domain, - "to" => \@to, + "smtpdomain" => \$smtp_domain, + "to" => \@initial_to, + "tocmd" => \$to_cmd, "cc" => \@initial_cc, "cccmd" => \$cc_cmd, "aliasfiletype" => \$aliasfiletype, @@ -271,7 +278,8 @@ $SIG{INT} = \&signal_handler; my $rc = GetOptions("sender|from=s" => \$sender, "in-reply-to=s" => \$initial_reply_to, "subject=s" => \$initial_subject, - "to=s" => \@to, + "to=s" => \@initial_to, + "to-cmd=s" => \$to_cmd, "no-to" => \$no_to, "cc=s" => \@initial_cc, "no-cc" => \$no_cc, @@ -279,6 +287,7 @@ my $rc = GetOptions("sender|from=s" => \$sender, "no-bcc" => \$no_bcc, "chain-reply-to!" => \$chain_reply_to, "smtp-server=s" => \$smtp_server, + "smtp-server-option=s" => \@smtp_server_options, "smtp-server-port=s" => \$smtp_server_port, "smtp-user=s" => \$smtp_authuser, "smtp-pass:s" => \$smtp_authpass, @@ -410,7 +419,7 @@ my ($repoauthor, $repocommitter); # Verify the user input -foreach my $entry (@to) { +foreach my $entry (@initial_to) { die "Comma in --to entry: $entry'\n" unless $entry !~ m/,/; } @@ -722,9 +731,9 @@ if (!defined $sender) { $prompting++; } -if (!@to) { +if (!@initial_to && !defined $to_cmd) { my $to = ask("Who should the emails be sent to? "); - push @to, parse_address_line($to) if defined $to; # sanitized/validated later + push @initial_to, parse_address_line($to) if defined $to; # sanitized/validated later $prompting++; } @@ -742,8 +751,8 @@ sub expand_one_alias { return $aliases{$alias} ? expand_aliases(@{$aliases{$alias}}) : $alias; } -@to = expand_aliases(@to); -@to = (map { sanitize_address($_) } @to); +@initial_to = expand_aliases(@initial_to); +@initial_to = (map { sanitize_address($_) } @initial_to); @initial_cc = expand_aliases(@initial_cc); @bcclist = expand_aliases(@bcclist); @@ -777,8 +786,8 @@ our ($message_id, %mail, $subject, $reply_to, $references, $message, sub extract_valid_address { my $address = shift; - my $local_part_regexp = '[^<>"\s@]+'; - my $domain_regexp = '[^.<>"\s@]+(?:\.[^.<>"\s@]+)+'; + my $local_part_regexp = qr/[^<>"\s@]+/; + my $domain_regexp = qr/[^.<>"\s@]+(?:\.[^.<>"\s@]+)+/; # check for a local address: return $address if ($address =~ /^($local_part_regexp)$/); @@ -819,7 +828,7 @@ sub make_message_id { last if (defined $du_part and $du_part ne ''); } if (not defined $du_part or $du_part eq '') { - use Sys::Hostname qw(); + require Sys::Hostname; $du_part = 'user@' . Sys::Hostname::hostname(); } my $message_id_template = "<%s-git-send-email-%s>"; @@ -852,8 +861,8 @@ sub quote_rfc2047 { sub is_rfc2047_quoted { my $s = shift; - my $token = '[^][()<>@,;:"\/?.= \000-\037\177-\377]+'; - my $encoded_text = '[!->@-~]+'; + my $token = qr/[^][()<>@,;:"\/?.= \000-\037\177-\377]+/; + my $encoded_text = qr/[!->@-~]+/; length($s) <= 75 && $s =~ m/^(?:"[[:ascii:]]*"|=\?$token\?$token\?$encoded_text\?=)$/o; } @@ -1026,6 +1035,8 @@ X-Mailer: git-send-email $gitversion } } + unshift (@sendmail_parameters, @smtp_server_options); + if ($dry_run) { # We don't want to send the email. } elsif ($smtp_server =~ m#^/#) { @@ -1035,7 +1046,7 @@ X-Mailer: git-send-email $gitversion exec($smtp_server, @sendmail_parameters) or die $!; } print $sm "$header\n$message"; - close $sm or die $?; + close $sm or die $!; } else { if (!defined $smtp_server) { @@ -1147,6 +1158,7 @@ foreach my $t (@files) { my $author_encoding; my $has_content_type; my $body_encoding; + @to = (); @cc = (); @xh = (); my $input_format = undef; @@ -1187,6 +1199,13 @@ foreach my $t (@files) { $1, $_) unless $quiet; push @cc, $1; } + elsif (/^To:\s+(.*)$/) { + foreach my $addr (parse_address_line($1)) { + printf("(mbox) Adding to: %s from line '%s'\n", + $addr, $_) unless $quiet; + push @to, sanitize_address($addr); + } + } elsif (/^Cc:\s+(.*)$/) { foreach my $addr (parse_address_line($1)) { if (unquote_rfc2047($addr) eq $sender) { @@ -1249,21 +1268,10 @@ foreach my $t (@files) { } 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(<$fh>) { - my $c = $_; - $c =~ s/^\s*//g; - $c =~ s/\n$//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; @@ -1304,6 +1312,7 @@ foreach my $t (@files) { ($confirm =~ /^(?:auto|compose)$/ && $compose && $message_num == 1)); $needs_confirm = "inform" if ($needs_confirm && $confirm_unconfigured && @cc); + @to = (@initial_to, @to); @cc = (@initial_cc, @cc); my $message_was_sent = send_message(); @@ -1321,6 +1330,29 @@ foreach my $t (@files) { $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 my $fh, "$cmd \Q$file\E |" + or die "($prefix) Could not execute '$cmd'"; + 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 {