Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 908b360

Browse files
committed
Merge branch 'mt/send-email-cc-match-fix'
Logic git-send-email used to suppress cc mishandled names like "A U. Thor" <[email protected]>, where the human readable part needs to be quoted (the user input may not have the double quotes around the name, and comparison was done between quoted and unquoted strings). * mt/send-email-cc-match-fix: test-send-email: test for pre-sanitized self name t/send-email: test suppress-cc=self with non-ascii t/send-email: add test with quoted sender send-email: make --suppress-cc=self sanitize input t/send-email: test suppress-cc=self on cccmd send-email: fix suppress-cc=self on cccmd t/send-email.sh: add test for suppress-cc=self
2 parents 7a9cc7b + 1495266 commit 908b360

File tree

2 files changed

+90
-8
lines changed

2 files changed

+90
-8
lines changed

git-send-email.perl

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,11 @@ sub file_declares_8bit_cte {
745745
$sender = $repoauthor || $repocommitter || '';
746746
}
747747

748+
# $sender could be an already sanitized address
749+
# (e.g. sendemail.from could be manually sanitized by user).
750+
# But it's a no-op to run sanitize_address on an already sanitized address.
751+
$sender = sanitize_address($sender);
752+
748753
my $prompting = 0;
749754
if (!@initial_to && !defined $to_cmd) {
750755
my $to = ask("Who should the emails be sent to (if any)? ",
@@ -1098,10 +1103,9 @@ sub send_message {
10981103
if ($cc ne '') {
10991104
$ccline = "\nCc: $cc";
11001105
}
1101-
my $sanitized_sender = sanitize_address($sender);
11021106
make_message_id() unless defined($message_id);
11031107

1104-
my $header = "From: $sanitized_sender
1108+
my $header = "From: $sender
11051109
To: $to${ccline}
11061110
Subject: $subject
11071111
Date: $date
@@ -1118,7 +1122,7 @@ sub send_message {
11181122
}
11191123

11201124
my @sendmail_parameters = ('-i', @recipients);
1121-
my $raw_from = $sanitized_sender;
1125+
my $raw_from = $sender;
11221126
if (defined $envelope_sender && $envelope_sender ne "auto") {
11231127
$raw_from = $envelope_sender;
11241128
}
@@ -1293,8 +1297,9 @@ sub send_message {
12931297
}
12941298
elsif (/^From:\s+(.*)$/i) {
12951299
($author, $author_encoding) = unquote_rfc2047($1);
1300+
my $sauthor = sanitize_address($author);
12961301
next if $suppress_cc{'author'};
1297-
next if $suppress_cc{'self'} and $author eq $sender;
1302+
next if $suppress_cc{'self'} and $sauthor eq $sender;
12981303
printf("(mbox) Adding cc: %s from line '%s'\n",
12991304
$1, $_) unless $quiet;
13001305
push @cc, $1;
@@ -1308,7 +1313,9 @@ sub send_message {
13081313
}
13091314
elsif (/^Cc:\s+(.*)$/i) {
13101315
foreach my $addr (parse_address_line($1)) {
1311-
if (unquote_rfc2047($addr) eq $sender) {
1316+
my $qaddr = unquote_rfc2047($addr);
1317+
my $saddr = sanitize_address($qaddr);
1318+
if ($saddr eq $sender) {
13121319
next if ($suppress_cc{'self'});
13131320
} else {
13141321
next if ($suppress_cc{'cc'});
@@ -1355,7 +1362,8 @@ sub send_message {
13551362
chomp;
13561363
my ($what, $c) = ($1, $2);
13571364
chomp $c;
1358-
if ($c eq $sender) {
1365+
my $sc = sanitize_address($c);
1366+
if ($sc eq $sender) {
13591367
next if ($suppress_cc{'self'});
13601368
} else {
13611369
next if $suppress_cc{'sob'} and $what =~ /Signed-off-by/i;
@@ -1439,15 +1447,14 @@ sub send_message {
14391447
sub recipients_cmd {
14401448
my ($prefix, $what, $cmd, $file) = @_;
14411449

1442-
my $sanitized_sender = sanitize_address($sender);
14431450
my @addresses = ();
14441451
open my $fh, "-|", "$cmd \Q$file\E"
14451452
or die "($prefix) Could not execute '$cmd'";
14461453
while (my $address = <$fh>) {
14471454
$address =~ s/^\s*//g;
14481455
$address =~ s/\s*$//g;
14491456
$address = sanitize_address($address);
1450-
next if ($address eq $sanitized_sender and $suppress_from);
1457+
next if ($address eq $sender and $suppress_cc{'self'});
14511458
push @addresses, $address;
14521459
printf("($prefix) Adding %s: %s from: '%s'\n",
14531460
$what, $address, $cmd) unless $quiet;

t/t9001-send-email.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,81 @@ Result: OK
171171
EOF
172172
"
173173

174+
test_suppress_self () {
175+
test_commit $3 &&
176+
test_when_finished "git reset --hard HEAD^" &&
177+
178+
write_script cccmd-sed <<-EOF &&
179+
sed -n -e s/^cccmd--//p "\$1"
180+
EOF
181+
182+
git commit --amend --author="$1 <$2>" -F - &&
183+
clean_fake_sendmail &&
184+
git format-patch --stdout -1 >"suppress-self-$3.patch" &&
185+
186+
git send-email --from="$1 <$2>" \
187+
188+
--cc-cmd=./cccmd-sed \
189+
--suppress-cc=self \
190+
--smtp-server="$(pwd)/fake.sendmail" \
191+
suppress-self-$3.patch &&
192+
193+
mv msgtxt1 msgtxt1-$3 &&
194+
sed -e '/^$/q' msgtxt1-$3 >"msghdr1-$3" &&
195+
>"expected-no-cc-$3" &&
196+
197+
(grep '^Cc:' msghdr1-$3 >"actual-no-cc-$3";
198+
test_cmp expected-no-cc-$3 actual-no-cc-$3)
199+
}
200+
201+
test_suppress_self_unquoted () {
202+
test_suppress_self "$1" "$2" "unquoted-$3" <<-EOF
203+
test suppress-cc.self unquoted-$3 with name $1 email $2
204+
205+
unquoted-$3
206+
207+
cccmd--$1 <$2>
208+
209+
Cc: $1 <$2>
210+
Signed-off-by: $1 <$2>
211+
EOF
212+
}
213+
214+
test_suppress_self_quoted () {
215+
test_suppress_self "$1" "$2" "quoted-$3" <<-EOF
216+
test suppress-cc.self quoted-$3 with name $1 email $2
217+
218+
quoted-$3
219+
220+
cccmd--"$1" <$2>
221+
222+
Cc: $1 <$2>
223+
Cc: "$1" <$2>
224+
Signed-off-by: $1 <$2>
225+
Signed-off-by: "$1" <$2>
226+
EOF
227+
}
228+
229+
test_expect_success $PREREQ 'self name is suppressed' "
230+
test_suppress_self_unquoted 'A U Thor' '[email protected]' \
231+
'self_name_suppressed'
232+
"
233+
234+
test_expect_success $PREREQ 'self name with dot is suppressed' "
235+
test_suppress_self_quoted 'A U. Thor' '[email protected]' \
236+
'self_name_dot_suppressed'
237+
"
238+
239+
test_expect_success $PREREQ 'non-ascii self name is suppressed' "
240+
test_suppress_self_quoted 'Füñný Nâmé' '[email protected]' \
241+
'non_ascii_self_suppressed'
242+
"
243+
244+
test_expect_success $PREREQ 'sanitized self name is suppressed' "
245+
test_suppress_self_unquoted '\"A U. Thor\"' '[email protected]' \
246+
'self_name_sanitized_suppressed'
247+
"
248+
174249
test_expect_success $PREREQ 'Show all headers' '
175250
git send-email \
176251
--dry-run \

0 commit comments

Comments
 (0)