Skip to contentSkip to conversation

git send-email suppress-cc=self fixes

PATCH Superseded Michael S. Tsirkin 2 participants 18 messages Jun 15, 2016

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover git send-email suppress-cc=self fixes

This includes bugfixes related to handling of --suppress-cc=self flag. Tests are also included.

Changes from v1:
- tweak coding style in tests to address comments by Junio

Michael S. Tsirkin (6):
t/send-email.sh: add test for suppress-cc=self
send-email: fix suppress-cc=self on cccmd t/send-email: test suppress-cc=self on cccmd
send-email: make --suppress-cc=self sanitize input t/send-email: add test with quoted sender t/send-email: test suppress-cc=self with non-ascii

 git-send-email.perl   | 20 +++++++++------
 t/t9001-send-email.sh | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+), 8 deletions(-)
Signature · 1 line
MST
#1 lore raw

PATCH v2 1/6 t/send-email.sh: add test for suppress-cc=self

This adds a basic test for --suppress-cc=self
option of git send-email.

---
 t/t9001-send-email.sh | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
t/t9001-send-email.sh +43 -0
index ebd5c5d..e1a7f3e 100755
@@ -171,6 +171,49 @@ Result: OK
 EOF
 "
 
+test_suppress_self () {
+	test_commit $3 &&
+	test_when_finished "git reset --hard HEAD^" &&
+
+	write_script cccmd-sed <<-EOF &&
+		sed -n -e s/^cccmd--//p "\$1"
+	EOF
+
+	git commit --amend --author="$1 <$2>" -F - &&  
+	clean_fake_sendmail &&  
+	git format-patch --stdout -1 >"suppress-self-$3.patch" &&  
+
+	git send-email --from="$1 <$2>" \
+		[email protected] \
+		--cc-cmd=./cccmd-sed \
+		--suppress-cc=self \
+		--smtp-server="$(pwd)/fake.sendmail" \
+		suppress-self-$3.patch &&
+
+	mv msgtxt1 msgtxt1-$3 &&
+	sed -e '/^$/q' msgtxt1-$3 >"msghdr1-$3" &&
+	>"expected-no-cc-$3" &&
+
+	(grep '^Cc:' msghdr1-$3 >"actual-no-cc-$3";
+	 test_cmp expected-no-cc-$3 actual-no-cc-$3)
+}
+
+test_suppress_self_unquoted () {
+	test_suppress_self "$1" "$2" "unquoted-$3" <<-EOF
+		test suppress-cc.self unquoted-$3 with name $1 email $2
+
+		unquoted-$3
+
+		Cc: $1 <$2>
+		Signed-off-by: $1 <$2>
+	EOF
+}
+
+test_expect_success $PREREQ 'self name is suppressed' "
+	test_suppress_self_unquoted 'A U Thor' '[email protected]' \
+		'self_name_suppressed'
+"
+
 test_expect_success $PREREQ 'Show all headers' '
 	git send-email \
 		--dry-run \
Signature · 1 line
MST
#3 lore raw

PATCH v2 2/6 send-email: fix suppress-cc=self on cccmd

In reply to Michael S. Tsirkin

When cccmd is used, old-style suppress-from filter is applied by the newer suppress-cc=self isn't. Fix this up.

---
 git-send-email.perl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
git-send-email.perl +1 -1
index bd13cc8..a138615 100755
@@ -1462,7 +1462,7 @@ sub recipients_cmd {
 		$address =~ s/^\s*//g;
 		$address =~ s/\s*$//g;
 		$address = sanitize_address($address);
-		next if ($address eq $sanitized_sender and $suppress_from);
+		next if ($address eq $sender and $suppress_cc{'self'});
 		push @addresses, $address;
 		printf("($prefix) Adding %s: %s from: '%s'\n",
 		       $what, $address, $cmd) unless $quiet;
Signature · 1 line
MST
#9 lore raw

PATCH v2 3/6 t/send-email: test suppress-cc=self on cccmd

In reply to Michael S. Tsirkin

Check that suppress-cc=self works when applied
to output of cccmd.

---
 t/t9001-send-email.sh | 2 ++
 1 file changed, 2 insertions(+)
t/t9001-send-email.sh +2 -0
index e1a7f3e..452b362 100755
@@ -204,6 +204,8 @@ test_suppress_self_unquoted () {
 
 		unquoted-$3
 
+		cccmd--$1 <$2>
+
 		Cc: $1 <$2>
 		Signed-off-by: $1 <$2>
 	EOF
Signature · 1 line
MST
#10 lore raw

PATCH v2 4/6 send-email: make --suppress-cc=self sanitize input

In reply to Michael S. Tsirkin

--suppress-cc=self fails to filter sender address in many cases where it needs to be sanitized in some way, for example quoted:
"A U. Thor" <[email protected]>
To fix, make send-email sanitize both sender and the address it is compared against.

---
 git-send-email.perl | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
git-send-email.perl +11 -7
index a138615..92df393 100755
@@ -760,6 +760,8 @@ if (!defined $sender) {
 	$sender = $repoauthor || $repocommitter || '';
 }
 
+$sender = sanitize_address($sender);
+
 my $prompting = 0;
 if (!@initial_to && !defined $to_cmd) {
 	my $to = ask("Who should the emails be sent to (if any)? ",
@@ -1113,10 +1115,9 @@ sub send_message {
 	if ($cc ne '') {
 		$ccline = "\nCc: $cc";
 	}
-	my $sanitized_sender = sanitize_address($sender);
 	make_message_id() unless defined($message_id);
 
-	my $header = "From: $sanitized_sender
+	my $header = "From: $sender
 To: $to${ccline}
 Subject: $subject
 Date: $date
@@ -1133,7 +1134,7 @@ X-Mailer: git-send-email $gitversion
 	}
 
 	my @sendmail_parameters = ('-i', @recipients);
-	my $raw_from = $sanitized_sender;
+	my $raw_from = $sender;
 	if (defined $envelope_sender && $envelope_sender ne "auto") {
 		$raw_from = $envelope_sender;
 	}
@@ -1308,8 +1309,9 @@ foreach my $t (@files) {
 			}
 			elsif (/^From:\s+(.*)$/i) {
 				($author, $author_encoding) = unquote_rfc2047($1);
+				my $sauthor = sanitize_address($author);
 				next if $suppress_cc{'author'};
-				next if $suppress_cc{'self'} and $author eq $sender;
+				next if $suppress_cc{'self'} and $sauthor eq $sender;
 				printf("(mbox) Adding cc: %s from line '%s'\n",
 					$1, $_) unless $quiet;
 				push @cc, $1;
@@ -1323,7 +1325,9 @@ foreach my $t (@files) {
 			}
 			elsif (/^Cc:\s+(.*)$/i) {
 				foreach my $addr (parse_address_line($1)) {
-					if (unquote_rfc2047($addr) eq $sender) {
+					my $qaddr = unquote_rfc2047($addr);
+					my $saddr = sanitize_address($qaddr);
+					if ($saddr eq $sender) {
 						next if ($suppress_cc{'self'});
 					} else {
 						next if ($suppress_cc{'cc'});
@@ -1370,7 +1374,8 @@ foreach my $t (@files) {
 			chomp;
 			my ($what, $c) = ($1, $2);
 			chomp $c;
-			if ($c eq $sender) {
+			my $sc = sanitize_address($c);
+			if ($sc eq $sender) {
 				next if ($suppress_cc{'self'});
 			} else {
 				next if $suppress_cc{'sob'} and $what =~ /Signed-off-by/i;
@@ -1454,7 +1459,6 @@ foreach my $t (@files) {
 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'";
Signature · 1 line
MST
#14 lore raw

PATCH v2 5/6 t/send-email: add test with quoted sender

In reply to Michael S. Tsirkin

add test where sender address needs to be quoted. Make sure --suppress-cc=self works well in this case.

---
 t/t9001-send-email.sh | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
t/t9001-send-email.sh +20 -0
index 452b362..42fb809 100755
@@ -211,11 +211,31 @@ test_suppress_self_unquoted () {
 	EOF
 }
 
+test_suppress_self_quoted () {
+	test_suppress_self "$1" "$2" "quoted-$3" <<-EOF
+		test suppress-cc.self quoted-$3 with name $1 email $2
+
+		quoted-$3
+
+		cccmd--"$1" <$2>
+
+		Cc: $1 <$2>
+		Cc: "$1" <$2>
+		Signed-off-by: $1 <$2>
+		Signed-off-by: "$1" <$2>
+	EOF
+}
+
 test_expect_success $PREREQ 'self name is suppressed' "
 	test_suppress_self_unquoted 'A U Thor' '[email protected]' \
 		'self_name_suppressed'
 "
 
+test_expect_success $PREREQ 'quoted self name is suppressed' "
+	test_suppress_self_quoted 'A U. Thor' '[email protected]' \
+		'self_name_suppressed'
+"
+
 test_expect_success $PREREQ 'Show all headers' '
 	git send-email \
 		--dry-run \
Signature · 1 line
MST
#15 lore raw

PATCH v2 6/6 t/send-email: test suppress-cc=self with non-ascii

In reply to Michael S. Tsirkin

test suppress-cc=self when sender is non-acsii

---
 t/t9001-send-email.sh | 5 +++++
 1 file changed, 5 insertions(+)
t/t9001-send-email.sh +5 -0
index 42fb809..430e8de 100755
@@ -236,6 +236,11 @@ test_expect_success $PREREQ 'quoted self name is suppressed' "
 		'self_name_suppressed'
 "
 
+test_expect_success $PREREQ 'non-ascii self name is suppressed' "
+	test_suppress_self_quoted 'Füñný Nâmé' '[email protected]' \
+		'non_ascii_self_suppressed'
+"
+
 test_expect_success $PREREQ 'Show all headers' '
 	git send-email \
 		--dry-run \
Signature · 1 line
MST
#2 lore raw

Re: [PATCH v2 1/6] t/send-email.sh: add test for suppress-cc=self

In reply to Michael S. Tsirkin
Quoted 15 lines · Michael S. Tsirkin

This adds a basic test for --suppress-cc=self
option of git send-email.

---
 t/t9001-send-email.sh | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
t/t9001-send-email.sh +0 -0
index ebd5c5d..e1a7f3e 100755
@@ -171,6 +171,49 @@ Result: OK
 EOF
 "

t/t9001-send-email.sh Result: OK · line 182

Quoted 10 lines
t/t9001-send-email.sh +9 -0
 
+test_suppress_self () {
+	test_commit $3 &&
+	test_when_finished "git reset --hard HEAD^" &&
+
+	write_script cccmd-sed <<-EOF &&
+		sed -n -e s/^cccmd--//p "\$1"
+	EOF
+
+	git commit --amend --author="$1 <$2>" -F - &&  

Ahh, this helper reads the log message from its standard input; nice.

Quoted 37 lines
t/t9001-send-email.sh +34 -0
+	clean_fake_sendmail &&  
+	git format-patch --stdout -1 >"suppress-self-$3.patch" &&  
+
+	git send-email --from="$1 <$2>" \
+		[email protected] \
+		--cc-cmd=./cccmd-sed \
+		--suppress-cc=self \
+		--smtp-server="$(pwd)/fake.sendmail" \
+		suppress-self-$3.patch &&
+
+	mv msgtxt1 msgtxt1-$3 &&
+	sed -e '/^$/q' msgtxt1-$3 >"msghdr1-$3" &&
+	>"expected-no-cc-$3" &&
+
+	(grep '^Cc:' msghdr1-$3 >"actual-no-cc-$3";
+	 test_cmp expected-no-cc-$3 actual-no-cc-$3)
+}
+
+test_suppress_self_unquoted () {
+	test_suppress_self "$1" "$2" "unquoted-$3" <<-EOF
+		test suppress-cc.self unquoted-$3 with name $1 email $2
+
+		unquoted-$3
+
+		Cc: $1 <$2>
+		Signed-off-by: $1 <$2>
+	EOF
+}
+
+test_expect_success $PREREQ 'self name is suppressed' "
+	test_suppress_self_unquoted 'A U Thor' '[email protected]' \
+		'self_name_suppressed'
+"
+
 test_expect_success $PREREQ 'Show all headers' '
 	git send-email \
 		--dry-run \
#4 lore raw

Re: [PATCH v2 2/6] send-email: fix suppress-cc=self on cccmd

In reply to Michael S. Tsirkin
Quoted 14 lines · Michael S. Tsirkin

When cccmd is used, old-style suppress-from filter is applied by the newer suppress-cc=self isn't. Fix this up.

---
 git-send-email.perl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
git-send-email.perl +0 -0
index bd13cc8..a138615 100755

git-send-email.perl sub recipients_cmd { · line 1465

Quoted 5 lines
git-send-email.perl +1 -1
@@ -1462,7 +1462,7 @@ sub recipients_cmd {
 		$address =~ s/^\s*//g;
 		$address =~ s/\s*$//g;
 		$address = sanitize_address($address);
-		next if ($address eq $sanitized_sender and $suppress_from);
+		next if ($address eq $sender and $suppress_cc{'self'});

If $suppress_from is defined, $suppress_cc{'self'} gets its value, so the latter half of this change is very understandable.

The original comparison uses $address that is "sanitized" (whose definition is roughly "mangled/quoted with rfc2047 etc to fit on To/Cc headers") against $sanitized_sender, which means for a

    $sender = 'Michael S. Tsirkin <[email protected]>';

we used

    $sanitized_sender = '"Michael S. Tsirkin" <[email protected]>';

for comparison, but the new code does not quote the $recipient_name part inside dq for the single dot after the middle name. Is this a desirable change?

Quoted 3 lines
git-send-email.perl +0 -0
 		push @addresses, $address;
 		printf("($prefix) Adding %s: %s from: '%s'\n",
 		       $what, $address, $cmd) unless $quiet;
#5 lore raw

Re: [PATCH v2 2/6] send-email: fix suppress-cc=self on cccmd

Quoted 31 lines · Junio C Hamano
Quoted 14 lines · Michael S. Tsirkin

When cccmd is used, old-style suppress-from filter is applied by the newer suppress-cc=self isn't. Fix this up.

---
 git-send-email.perl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
git-send-email.perl +0 -0
index bd13cc8..a138615 100755

git-send-email.perl sub recipients_cmd { · line 1465

Quoted 5 lines
git-send-email.perl +1 -1
@@ -1462,7 +1462,7 @@ sub recipients_cmd {
 		$address =~ s/^\s*//g;
 		$address =~ s/\s*$//g;
 		$address = sanitize_address($address);
-		next if ($address eq $sanitized_sender and $suppress_from);
+		next if ($address eq $sender and $suppress_cc{'self'});

If $suppress_from is defined, $suppress_cc{'self'} gets its value, so the latter half of this change is very understandable.

The original comparison uses $address that is "sanitized" (whose definition is roughly "mangled/quoted with rfc2047 etc to fit on To/Cc headers") against $sanitized_sender, which means for a

    $sender = 'Michael S. Tsirkin <[email protected]>';
Quoted 7 lines

we used

    $sanitized_sender = '"Michael S. Tsirkin" <[email protected]>';

for comparison, but the new code does not quote the $recipient_name part inside dq for the single dot after the middle name. Is this a desirable change?

What I tried to do here is split the changes to small chunks and I picked a chunk of a later patch in an earlier one by mistake.

So this is fixed up by patch 4/6
in the series, which redefines sender to have the sanitized value, everywhere.

I guess I'll have to repost moving this former chunk to patch 4.

Quoted 3 lines
Quoted 3 lines
git-send-email.perl +0 -0
 		push @addresses, $address;
 		printf("($prefix) Adding %s: %s from: '%s'\n",
 		       $what, $address, $cmd) unless $quiet;
#6 lore raw

Re: [PATCH v2 2/6] send-email: fix suppress-cc=self on cccmd

Quoted 7 lines · Michael S. Tsirkin

What I tried to do here is split the changes to small chunks and I picked a chunk of a later patch in an earlier one by mistake.

So this is fixed up by patch 4/6 in the series, which redefines sender to have the sanitized value, everywhere.

I guess I'll have to repost moving this former chunk to patch 4.

Yeah, that may be a good idea.

Thanks.

#7 lore raw

Re: [PATCH v2 2/6] send-email: fix suppress-cc=self on cccmd

Quoted 5 lines · Junio C Hamano
Quoted 3 lines · Michael S. Tsirkin

What I tried to do here is split the changes to small chunks and I picked a chunk of a later patch in an earlier one by mistake.

Quoted 8 lines
Quoted 4 lines

So this is fixed up by patch 4/6 in the series, which redefines sender to have the sanitized value, everywhere.

I guess I'll have to repost moving this former chunk to patch 4.

Yeah, that may be a good idea.

Thanks.

Or just smash 2+4 together ...
Confused. You are doing this or want me ot?

#8 lore raw

Re: [PATCH v2 2/6] send-email: fix suppress-cc=self on cccmd

Quoted 9 lines · Michael S. Tsirkin
Quoted 8 lines · Junio C Hamano
Quoted 6 lines · Michael S. Tsirkin

What I tried to do here is split the changes to small chunks and I picked a chunk of a later patch in an earlier one by mistake.

So this is fixed up by patch 4/6 in the series, which redefines sender to have the sanitized value, everywhere.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

I guess I'll have to repost moving this former chunk to patch 4.

Yeah, that may be a good idea.

Thanks.

Or just smash 2+4 together ...
Confused. You are doing this or want me ot?

Sorry, I was expecting you would do so, after saying "I'll have to repost" and I responded "Yeah, good idea".

#11 lore raw

Re: [PATCH v2 4/6] send-email: make --suppress-cc=self sanitize input

In reply to Michael S. Tsirkin
Quoted 8 lines · Michael S. Tsirkin

--suppress-cc=self fails to filter sender address in many cases where it needs to be sanitized in some way, for example quoted:
"A U. Thor" <[email protected]>
To fix, make send-email sanitize both sender and the address it is compared against.

---

OK, so you are getting rid of distinctions between sanitized_sender and sender, and $sender is now defined to be always "sanitized" form.

That change makes things consistent with respect to the question I had on [2/6].

I however wondered how this would affect those who have configured "sendemail.from" with an already "sanitized" address. That is, you may have used:

[sendemail]
from = "Michael S. Tsirkin" <[email protected]>

with the older and current versions of Git. I _think_ the safetly of this change relies on that it is a no-op to run sanitize_address on an already sanitized address (i.e. feeding the above example sendemail.from to sanitize_address gives back the same string), which holds true for all practical purposes, but it is a bit subtle.

Quoted 77 lines
 git-send-email.perl | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
git-send-email.perl +11 -7
index a138615..92df393 100755
@@ -760,6 +760,8 @@ if (!defined $sender) {
 	$sender = $repoauthor || $repocommitter || '';
 }
 
+$sender = sanitize_address($sender);
+
 my $prompting = 0;
 if (!@initial_to && !defined $to_cmd) {
 	my $to = ask("Who should the emails be sent to (if any)? ",
@@ -1113,10 +1115,9 @@ sub send_message {
 	if ($cc ne '') {
 		$ccline = "\nCc: $cc";
 	}
-	my $sanitized_sender = sanitize_address($sender);
 	make_message_id() unless defined($message_id);
 
-	my $header = "From: $sanitized_sender
+	my $header = "From: $sender
 To: $to${ccline}
 Subject: $subject
 Date: $date
@@ -1133,7 +1134,7 @@ X-Mailer: git-send-email $gitversion
 	}
 
 	my @sendmail_parameters = ('-i', @recipients);
-	my $raw_from = $sanitized_sender;
+	my $raw_from = $sender;
 	if (defined $envelope_sender && $envelope_sender ne "auto") {
 		$raw_from = $envelope_sender;
 	}
@@ -1308,8 +1309,9 @@ foreach my $t (@files) {
 			}
 			elsif (/^From:\s+(.*)$/i) {
 				($author, $author_encoding) = unquote_rfc2047($1);
+				my $sauthor = sanitize_address($author);
 				next if $suppress_cc{'author'};
-				next if $suppress_cc{'self'} and $author eq $sender;
+				next if $suppress_cc{'self'} and $sauthor eq $sender;
 				printf("(mbox) Adding cc: %s from line '%s'\n",
 					$1, $_) unless $quiet;
 				push @cc, $1;
@@ -1323,7 +1325,9 @@ foreach my $t (@files) {
 			}
 			elsif (/^Cc:\s+(.*)$/i) {
 				foreach my $addr (parse_address_line($1)) {
-					if (unquote_rfc2047($addr) eq $sender) {
+					my $qaddr = unquote_rfc2047($addr);
+					my $saddr = sanitize_address($qaddr);
+					if ($saddr eq $sender) {
 						next if ($suppress_cc{'self'});
 					} else {
 						next if ($suppress_cc{'cc'});
@@ -1370,7 +1374,8 @@ foreach my $t (@files) {
 			chomp;
 			my ($what, $c) = ($1, $2);
 			chomp $c;
-			if ($c eq $sender) {
+			my $sc = sanitize_address($c);
+			if ($sc eq $sender) {
 				next if ($suppress_cc{'self'});
 			} else {
 				next if $suppress_cc{'sob'} and $what =~ /Signed-off-by/i;
@@ -1454,7 +1459,6 @@ foreach my $t (@files) {
 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'";
#12 lore raw

Re: [PATCH v2 4/6] send-email: make --suppress-cc=self sanitize input

Quoted 22 lines · Junio C Hamano
Quoted 8 lines · Michael S. Tsirkin

--suppress-cc=self fails to filter sender address in many cases where it needs to be sanitized in some way, for example quoted:
"A U. Thor" <[email protected]>
To fix, make send-email sanitize both sender and the address it is compared against.

---

OK, so you are getting rid of distinctions between sanitized_sender and sender, and $sender is now defined to be always "sanitized" form.

That change makes things consistent with respect to the question I had on [2/6].

I however wondered how this would affect those who have configured "sendemail.from" with an already "sanitized" address. That is, you may have used:

Quoted 8 lines

[sendemail]
from = "Michael S. Tsirkin" <[email protected]>

with the older and current versions of Git. I _think_ the safetly of this change relies on that it is a no-op to run sanitize_address on an already sanitized address (i.e. feeding the above example sendemail.from to sanitize_address gives back the same string), which holds true for all practical purposes, but it is a bit subtle.

Yes, I think so too. So - what do you suggest?
Add a test?
Add a comment?
more?

Quoted 77 lines
Quoted 77 lines
 git-send-email.perl | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
git-send-email.perl +11 -7
index a138615..92df393 100755
@@ -760,6 +760,8 @@ if (!defined $sender) {
 	$sender = $repoauthor || $repocommitter || '';
 }
 
+$sender = sanitize_address($sender);
+
 my $prompting = 0;
 if (!@initial_to && !defined $to_cmd) {
 	my $to = ask("Who should the emails be sent to (if any)? ",
@@ -1113,10 +1115,9 @@ sub send_message {
 	if ($cc ne '') {
 		$ccline = "\nCc: $cc";
 	}
-	my $sanitized_sender = sanitize_address($sender);
 	make_message_id() unless defined($message_id);
 
-	my $header = "From: $sanitized_sender
+	my $header = "From: $sender
 To: $to${ccline}
 Subject: $subject
 Date: $date
@@ -1133,7 +1134,7 @@ X-Mailer: git-send-email $gitversion
 	}
 
 	my @sendmail_parameters = ('-i', @recipients);
-	my $raw_from = $sanitized_sender;
+	my $raw_from = $sender;
 	if (defined $envelope_sender && $envelope_sender ne "auto") {
 		$raw_from = $envelope_sender;
 	}
@@ -1308,8 +1309,9 @@ foreach my $t (@files) {
 			}
 			elsif (/^From:\s+(.*)$/i) {
 				($author, $author_encoding) = unquote_rfc2047($1);
+				my $sauthor = sanitize_address($author);
 				next if $suppress_cc{'author'};
-				next if $suppress_cc{'self'} and $author eq $sender;
+				next if $suppress_cc{'self'} and $sauthor eq $sender;
 				printf("(mbox) Adding cc: %s from line '%s'\n",
 					$1, $_) unless $quiet;
 				push @cc, $1;
@@ -1323,7 +1325,9 @@ foreach my $t (@files) {
 			}
 			elsif (/^Cc:\s+(.*)$/i) {
 				foreach my $addr (parse_address_line($1)) {
-					if (unquote_rfc2047($addr) eq $sender) {
+					my $qaddr = unquote_rfc2047($addr);
+					my $saddr = sanitize_address($qaddr);
+					if ($saddr eq $sender) {
 						next if ($suppress_cc{'self'});
 					} else {
 						next if ($suppress_cc{'cc'});
@@ -1370,7 +1374,8 @@ foreach my $t (@files) {
 			chomp;
 			my ($what, $c) = ($1, $2);
 			chomp $c;
-			if ($c eq $sender) {
+			my $sc = sanitize_address($c);
+			if ($sc eq $sender) {
 				next if ($suppress_cc{'self'});
 			} else {
 				next if $suppress_cc{'sob'} and $what =~ /Signed-off-by/i;
@@ -1454,7 +1459,6 @@ foreach my $t (@files) {
 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'";
#13 lore raw

Re: [PATCH v2 4/6] send-email: make --suppress-cc=self sanitize input

Quoted 4 lines · Michael S. Tsirkin

Yes, I think so too. So - what do you suggest?
Add a test?
Add a comment?
more?

Nothing major comes to my mind at this moment.

I guess it would be good to add a test or two to use "A U. Thor" example with and without end-user added quotes, but that can be done as a follow-up patch on top of this series (i.e. [PATCH 7/6]).

Thanks.

Quoted 77 lines
Quoted 77 lines
Quoted 77 lines
 git-send-email.perl | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
git-send-email.perl +11 -7
index a138615..92df393 100755
@@ -760,6 +760,8 @@ if (!defined $sender) {
 	$sender = $repoauthor || $repocommitter || '';
 }
 
+$sender = sanitize_address($sender);
+
 my $prompting = 0;
 if (!@initial_to && !defined $to_cmd) {
 	my $to = ask("Who should the emails be sent to (if any)? ",
@@ -1113,10 +1115,9 @@ sub send_message {
 	if ($cc ne '') {
 		$ccline = "\nCc: $cc";
 	}
-	my $sanitized_sender = sanitize_address($sender);
 	make_message_id() unless defined($message_id);
 
-	my $header = "From: $sanitized_sender
+	my $header = "From: $sender
 To: $to${ccline}
 Subject: $subject
 Date: $date
@@ -1133,7 +1134,7 @@ X-Mailer: git-send-email $gitversion
 	}
 
 	my @sendmail_parameters = ('-i', @recipients);
-	my $raw_from = $sanitized_sender;
+	my $raw_from = $sender;
 	if (defined $envelope_sender && $envelope_sender ne "auto") {
 		$raw_from = $envelope_sender;
 	}
@@ -1308,8 +1309,9 @@ foreach my $t (@files) {
 			}
 			elsif (/^From:\s+(.*)$/i) {
 				($author, $author_encoding) = unquote_rfc2047($1);
+				my $sauthor = sanitize_address($author);
 				next if $suppress_cc{'author'};
-				next if $suppress_cc{'self'} and $author eq $sender;
+				next if $suppress_cc{'self'} and $sauthor eq $sender;
 				printf("(mbox) Adding cc: %s from line '%s'\n",
 					$1, $_) unless $quiet;
 				push @cc, $1;
@@ -1323,7 +1325,9 @@ foreach my $t (@files) {
 			}
 			elsif (/^Cc:\s+(.*)$/i) {
 				foreach my $addr (parse_address_line($1)) {
-					if (unquote_rfc2047($addr) eq $sender) {
+					my $qaddr = unquote_rfc2047($addr);
+					my $saddr = sanitize_address($qaddr);
+					if ($saddr eq $sender) {
 						next if ($suppress_cc{'self'});
 					} else {
 						next if ($suppress_cc{'cc'});
@@ -1370,7 +1374,8 @@ foreach my $t (@files) {
 			chomp;
 			my ($what, $c) = ($1, $2);
 			chomp $c;
-			if ($c eq $sender) {
+			my $sc = sanitize_address($c);
+			if ($sc eq $sender) {
 				next if ($suppress_cc{'self'});
 			} else {
 				next if $suppress_cc{'sob'} and $what =~ /Signed-off-by/i;
@@ -1454,7 +1459,6 @@ foreach my $t (@files) {
 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'";
#17 lore raw
Quoted 6 lines · Junio C Hamano
Quoted 2 lines · Michael S. Tsirkin

This includes bugfixes related to handling of --suppress-cc=self flag. Tests are also included.

Thanks, will queue.

OK pls let me know if this means you intend to handle the rest of your comments yourself or if I need to fix anything.