From 21802cd32805b19fa32e8e3594ee3914733d53d3 Mon Sep 17 00:00:00 2001 From: Stephen Boyd Date: Wed, 29 Sep 2010 00:26:44 -0700 Subject: [PATCH 1/2] send-email: Use To: headers in patch files It's a minor annoyance when you take the painstaking time to setup To: headers for each patch in a large series, and then go out to send the series with git-send-email and watch git ignore the To: headers in the patch files. Therefore, always add To: headers from a patch file to the To: headers for that message. Keep the prompt for the blanket To: header so as to not break scripts (and user expectations). This means even if a patch has a To: header, git will prompt for the To: address. Otherwise, we'll need to introduce interface breakage to either request the header for each patch missing a To: header or default the header to whatever To: address is found first (be it in a patch or from user input). Both of these options don't seem very obvious/useful. Reported-by: Viresh Kumar Signed-off-by: Stephen Boyd Tested-by: Viresh Kumar Signed-off-by: Junio C Hamano --- git-send-email.perl | 7 +++++++ t/t9001-send-email.sh | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/git-send-email.perl b/git-send-email.perl index e1f29a72a1..d6028ec7b4 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -1176,6 +1176,13 @@ sub send_message { $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) { diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index 71b3df9b55..294e31f7f0 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -947,6 +947,30 @@ test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' ' ! grep "RCPT TO:" stdout ' +test_expect_success $PREREQ 'patches To headers are used by default' ' + patch=`git format-patch -1 --to="bodies@example.com"` && + test_when_finished "rm $patch" && + git send-email \ + --dry-run \ + --from="Example " \ + --smtp-server relay.example.com \ + $patch >stdout && + grep "RCPT TO:" stdout +' + +test_expect_success $PREREQ 'patches To headers are appended to' ' + patch=`git format-patch -1 --to="bodies@example.com"` && + test_when_finished "rm $patch" && + git send-email \ + --dry-run \ + --from="Example " \ + --to=nobody@example.com \ + --smtp-server relay.example.com \ + $patch >stdout && + grep "RCPT TO:" stdout && + grep "RCPT TO:" stdout +' + test_expect_success $PREREQ 'setup expect' ' cat >email-using-8bit < Date: Mon, 4 Oct 2010 00:05:24 -0700 Subject: [PATCH 2/2] send-email: Don't leak To: headers between patches If the first patch in a series has a To: header in the file and the second patch in the series doesn't the address from the first patch will be part of the To: addresses in the second patch. Fix this by treating the to list like the cc list. Have an initial to list come from the command line, user input and config options. Then build up a to list from each patch and concatenate the two together before sending the patch. Finally, reset the list after sending each patch so the To: headers from a patch don't get used for the next one. Reported-by: Viresh Kumar Signed-off-by: Stephen Boyd Signed-off-by: Junio C Hamano --- git-send-email.perl | 18 ++++++++++-------- t/t9001-send-email.sh | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index d6028ec7b4..7f9eacd16c 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -138,7 +138,7 @@ sub format_2822_time { 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); @@ -213,7 +213,7 @@ sub do_edit { "smtpuser" => \$smtp_authuser, "smtppass" => \$smtp_authpass, "smtpdomain" => \$smtp_domain, - "to" => \@to, + "to" => \@initial_to, "cc" => \@initial_cc, "cccmd" => \$cc_cmd, "aliasfiletype" => \$aliasfiletype, @@ -271,7 +271,7 @@ sub 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, "no-to" => \$no_to, "cc=s" => \@initial_cc, "no-cc" => \$no_cc, @@ -409,7 +409,7 @@ sub read_config { # Verify the user input -foreach my $entry (@to) { +foreach my $entry (@initial_to) { die "Comma in --to entry: $entry'\n" unless $entry !~ m/,/; } @@ -711,9 +711,9 @@ ($) $prompting++; } -if (!@to) { +if (!@initial_to) { 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++; } @@ -731,8 +731,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); @@ -1136,6 +1136,7 @@ sub send_message { my $author_encoding; my $has_content_type; my $body_encoding; + @to = (); @cc = (); @xh = (); my $input_format = undef; @@ -1300,6 +1301,7 @@ sub send_message { ($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(); diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index 294e31f7f0..13d8d1a8b4 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -971,6 +971,21 @@ test_expect_success $PREREQ 'patches To headers are appended to' ' grep "RCPT TO:" stdout ' +test_expect_success $PREREQ 'To headers from files reset each patch' ' + patch1=`git format-patch -1 --to="bodies@example.com"` && + patch2=`git format-patch -1 --to="other@example.com" HEAD~` && + test_when_finished "rm $patch1 && rm $patch2" && + git send-email \ + --dry-run \ + --from="Example " \ + --to="nobody@example.com" \ + --smtp-server relay.example.com \ + $patch1 $patch2 >stdout && + test $(grep -c "RCPT TO:" stdout) = 1 && + test $(grep -c "RCPT TO:" stdout) = 2 && + test $(grep -c "RCPT TO:" stdout) = 1 +' + test_expect_success $PREREQ 'setup expect' ' cat >email-using-8bit <