Skip to content

Commit 8796ff7

Browse files
committed
Merge branch 'sb/send-email-use-to-from-input'
* sb/send-email-use-to-from-input: send-email: Don't leak To: headers between patches send-email: Use To: headers in patch files Conflicts: git-send-email.perl
2 parents 9b73ce7 + 3c3bb51 commit 8796ff7

File tree

2 files changed

+56
-8
lines changed

2 files changed

+56
-8
lines changed

git-send-email.perl

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ sub format_2822_time {
143143
sub cleanup_compose_files();
144144

145145
# Variables we fill in automatically, or via prompting:
146-
my (@to,$no_to,@cc,$no_cc,@initial_cc,@bcclist,$no_bcc,@xh,
146+
my (@to,$no_to,@initial_to,@cc,$no_cc,@initial_cc,@bcclist,$no_bcc,@xh,
147147
$initial_reply_to,$initial_subject,@files,
148148
$author,$sender,$smtp_authpass,$annotate,$compose,$time);
149149

@@ -222,7 +222,7 @@ sub do_edit {
222222
"smtpuser" => \$smtp_authuser,
223223
"smtppass" => \$smtp_authpass,
224224
"smtpdomain" => \$smtp_domain,
225-
"to" => \@to,
225+
"to" => \@initial_to,
226226
"tocmd" => \$to_cmd,
227227
"cc" => \@initial_cc,
228228
"cccmd" => \$cc_cmd,
@@ -281,7 +281,7 @@ sub signal_handler {
281281
my $rc = GetOptions("sender|from=s" => \$sender,
282282
"in-reply-to=s" => \$initial_reply_to,
283283
"subject=s" => \$initial_subject,
284-
"to=s" => \@to,
284+
"to=s" => \@initial_to,
285285
"to-cmd=s" => \$to_cmd,
286286
"no-to" => \$no_to,
287287
"cc=s" => \@initial_cc,
@@ -422,7 +422,7 @@ sub read_config {
422422

423423
# Verify the user input
424424

425-
foreach my $entry (@to) {
425+
foreach my $entry (@initial_to) {
426426
die "Comma in --to entry: $entry'\n" unless $entry !~ m/,/;
427427
}
428428

@@ -734,9 +734,9 @@ ($)
734734
$prompting++;
735735
}
736736

737-
if (!@to && !defined $to_cmd) {
737+
if (!@initial_to && !defined $to_cmd) {
738738
my $to = ask("Who should the emails be sent to? ");
739-
push @to, parse_address_line($to) if defined $to; # sanitized/validated later
739+
push @initial_to, parse_address_line($to) if defined $to; # sanitized/validated later
740740
$prompting++;
741741
}
742742

@@ -754,8 +754,8 @@ sub expand_one_alias {
754754
return $aliases{$alias} ? expand_aliases(@{$aliases{$alias}}) : $alias;
755755
}
756756

757-
@to = expand_aliases(@to);
758-
@to = (map { sanitize_address($_) } @to);
757+
@initial_to = expand_aliases(@initial_to);
758+
@initial_to = (map { sanitize_address($_) } @initial_to);
759759
@initial_cc = expand_aliases(@initial_cc);
760760
@bcclist = expand_aliases(@bcclist);
761761

@@ -1161,6 +1161,7 @@ sub send_message {
11611161
my $author_encoding;
11621162
my $has_content_type;
11631163
my $body_encoding;
1164+
@to = ();
11641165
@cc = ();
11651166
@xh = ();
11661167
my $input_format = undef;
@@ -1201,6 +1202,13 @@ sub send_message {
12011202
$1, $_) unless $quiet;
12021203
push @cc, $1;
12031204
}
1205+
elsif (/^To:\s+(.*)$/) {
1206+
foreach my $addr (parse_address_line($1)) {
1207+
printf("(mbox) Adding to: %s from line '%s'\n",
1208+
$addr, $_) unless $quiet;
1209+
push @to, sanitize_address($addr);
1210+
}
1211+
}
12041212
elsif (/^Cc:\s+(.*)$/) {
12051213
foreach my $addr (parse_address_line($1)) {
12061214
if (unquote_rfc2047($addr) eq $sender) {
@@ -1307,6 +1315,7 @@ sub send_message {
13071315
($confirm =~ /^(?:auto|compose)$/ && $compose && $message_num == 1));
13081316
$needs_confirm = "inform" if ($needs_confirm && $confirm_unconfigured && @cc);
13091317

1318+
@to = (@initial_to, @to);
13101319
@cc = (@initial_cc, @cc);
13111320

13121321
my $message_was_sent = send_message();

t/t9001-send-email.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,45 @@ test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
965965
! grep "RCPT TO:<[email protected]>" stdout
966966
'
967967

968+
test_expect_success $PREREQ 'patches To headers are used by default' '
969+
patch=`git format-patch -1 --to="[email protected]"` &&
970+
test_when_finished "rm $patch" &&
971+
git send-email \
972+
--dry-run \
973+
--from="Example <[email protected]>" \
974+
--smtp-server relay.example.com \
975+
$patch >stdout &&
976+
grep "RCPT TO:<[email protected]>" stdout
977+
'
978+
979+
test_expect_success $PREREQ 'patches To headers are appended to' '
980+
patch=`git format-patch -1 --to="[email protected]"` &&
981+
test_when_finished "rm $patch" &&
982+
git send-email \
983+
--dry-run \
984+
--from="Example <[email protected]>" \
985+
986+
--smtp-server relay.example.com \
987+
$patch >stdout &&
988+
grep "RCPT TO:<[email protected]>" stdout &&
989+
grep "RCPT TO:<[email protected]>" stdout
990+
'
991+
992+
test_expect_success $PREREQ 'To headers from files reset each patch' '
993+
patch1=`git format-patch -1 --to="[email protected]"` &&
994+
patch2=`git format-patch -1 --to="[email protected]" HEAD~` &&
995+
test_when_finished "rm $patch1 && rm $patch2" &&
996+
git send-email \
997+
--dry-run \
998+
--from="Example <[email protected]>" \
999+
1000+
--smtp-server relay.example.com \
1001+
$patch1 $patch2 >stdout &&
1002+
test $(grep -c "RCPT TO:<[email protected]>" stdout) = 1 &&
1003+
test $(grep -c "RCPT TO:<[email protected]>" stdout) = 2 &&
1004+
test $(grep -c "RCPT TO:<[email protected]>" stdout) = 1
1005+
'
1006+
9681007
test_expect_success $PREREQ 'setup expect' '
9691008
cat >email-using-8bit <<EOF
9701009
From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001

0 commit comments

Comments
 (0)