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 <viresh.kumar@st.com> Signed-off-by: Stephen Boyd <bebarino@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stephen Boyd committed
Oct 4, 2010 at 00:05 UTC
3c3bb51c3b205a6838b022896c9323d4b25bf392
2 files changed
+25
-8
git-send-email.perl
+10
-8
@@ -138,7 +138,7 @@ sub unique_email_list(@);
138
sub cleanup_compose_files();
139
140
# Variables we fill in automatically, or via prompting:
141
-my (@to,$no_to,@cc,$no_cc,@initial_cc,@bcclist,$no_bcc,@xh,
141
+my (@to,$no_to,@initial_to,@cc,$no_cc,@initial_cc,@bcclist,$no_bcc,@xh,
142
$initial_reply_to,$initial_subject,@files,
143
$author,$sender,$smtp_authpass,$annotate,$compose,$time);
144
@@ -213,7 +213,7 @@ my %config_settings = (
213
"smtpuser" => \$smtp_authuser,
214
"smtppass" => \$smtp_authpass,
215
"smtpdomain" => \$smtp_domain,
216
- "to" => \@to,
216
+ "to" => \@initial_to,
217
"cc" => \@initial_cc,
218
"cccmd" => \$cc_cmd,
219
"aliasfiletype" => \$aliasfiletype,
@@ -271,7 +271,7 @@ $SIG{INT} = \&signal_handler;
271
my $rc = GetOptions("sender|from=s" => \$sender,
272
"in-reply-to=s" => \$initial_reply_to,
273
"subject=s" => \$initial_subject,
274
- "to=s" => \@to,
274
+ "to=s" => \@initial_to,
275
"no-to" => \$no_to,
276
"cc=s" => \@initial_cc,
277
"no-cc" => \$no_cc,
@@ -409,7 +409,7 @@ my ($repoauthor, $repocommitter);
409
410
# Verify the user input
411
412
-foreach my $entry (@to) {
412
+foreach my $entry (@initial_to) {
413
die "Comma in --to entry: $entry'\n" unless $entry !~ m/,/;
414
}
415
@@ -711,9 +711,9 @@ if (!defined $sender) {
711
$prompting++;
712
}
713
714
-if (!@to) {
714
+if (!@initial_to) {
715
my $to = ask("Who should the emails be sent to? ");
716
- push @to, parse_address_line($to) if defined $to; # sanitized/validated later
716
+ push @initial_to, parse_address_line($to) if defined $to; # sanitized/validated later
717
$prompting++;
718
}
719
@@ -731,8 +731,8 @@ sub expand_one_alias {
731
return $aliases{$alias} ? expand_aliases(@{$aliases{$alias}}) : $alias;
732
}
733
734
-@to = expand_aliases(@to);
735
-@to = (map { sanitize_address($_) } @to);
734
+@initial_to = expand_aliases(@initial_to);
735
+@initial_to = (map { sanitize_address($_) } @initial_to);
736
@initial_cc = expand_aliases(@initial_cc);
737
@bcclist = expand_aliases(@bcclist);
738
@@ -1136,6 +1136,7 @@ foreach my $t (@files) {
1136
my $author_encoding;
1137
my $has_content_type;
1138
my $body_encoding;
1139
+ @to = ();
1140
@cc = ();
1141
@xh = ();
1142
my $input_format = undef;
@@ -1300,6 +1301,7 @@ foreach my $t (@files) {
1301
($confirm =~ /^(?:auto|compose)$/ && $compose && $message_num == 1));
1302
$needs_confirm = "inform" if ($needs_confirm && $confirm_unconfigured && @cc);
1303
1304
+ @to = (@initial_to, @to);
1305
@cc = (@initial_cc, @cc);
1306
1307
my $message_was_sent = send_message();
t/t9001-send-email.sh
+15
@@ -971,6 +971,21 @@ test_expect_success $PREREQ 'patches To headers are appended to' '
971
grep "RCPT TO:<nobody@example.com>" stdout
972
'
973
974
+test_expect_success $PREREQ 'To headers from files reset each patch' '
975
+ patch1=`git format-patch -1 --to="bodies@example.com"` &&
976
+ patch2=`git format-patch -1 --to="other@example.com" HEAD~` &&
977
+ test_when_finished "rm $patch1 && rm $patch2" &&
978
+ git send-email \
979
+ --dry-run \
980
+ --from="Example <nobody@example.com>" \
981
+ --to="nobody@example.com" \
982
+ --smtp-server relay.example.com \
983
+ $patch1 $patch2 >stdout &&
984
+ test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
985
+ test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
986
+ test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
987
+'
988
+
989
test_expect_success $PREREQ 'setup expect' '
990
cat >email-using-8bit <<EOF
991
From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001