Re: [RFC] git-send-email: do not double-escape quotes from mutt

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [RFC] git-send-email: do not double-escape quotes from mutt

From: Junio C Hamano <hidden>
Date: 2016-06-15 23:07:34

Eric Wong [off-list ref] writes:
-			 # commas delimit multiple addresses
-			$aliases{$alias} = [ split_addrs($addr) ];
+			# commas delimit multiple addresses
+			my @addr = split_addrs($addr);
+
+			# quotes may be escaped in the file,
+			# remove them if paired so we do not
+			# double-escape them later.
+			s/^\\"(.*)\\"/"$1"/g foreach @addr;
+			$aliases{$alias} = \@addr
Can one address have two or more double-quoted string pieces in it?
If that is possible, (.*) above might want to become (.*?) or even
([^"]*) to make it less greedy, perhaps?
quoted hunk
 		}}},
 	mailrc => sub { my $fh = shift; while (<$fh>) {
 		if (/^alias\s+(\S+)\s+(.*)$/) {
diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
index 3c49536..834d91a 100755
--- a/t/t9001-send-email.sh
+++ b/t/t9001-send-email.sh
@@ -1527,6 +1527,21 @@ test_expect_success $PREREQ 'cccover adds Cc to all mail' '
 	test_cover_addresses "Cc"
 '
 
+test_expect_success $PREREQ 'escaped quotes in sendemail.aliasfiletype=mutt' '
+	clean_fake_sendmail &&
+	echo "alias sbd \\\"Dot U. Sir\\\" <somebody@example.org>" >.mutt &&
+	git config --replace-all sendemail.aliasesfile "$(pwd)/.mutt" &&
+	git config sendemail.aliasfiletype mutt &&
+	git send-email \
+		--from="Example <nobody@example.com>" \
+		--to=sbd \
+		--smtp-server="$(pwd)/fake.sendmail" \
+		outdir/0001-*.patch \
+		2>errors >out &&
+	grep "^!somebody@example\.org!$" commandline1 &&
+	grep -F "To: \"Dot U. Sir\" <somebody@example.org>" out
+'
+
 test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' '
 	clean_fake_sendmail &&
 	echo "alias sbd  somebody@example.org" >.mailrc &&

Re: [RFC] git-send-email: do not double-escape quotes from mutt

From: Eric Wong <hidden>
Date: 2016-06-15 23:07:34

Junio C Hamano [off-list ref] wrote:
Eric Wong [off-list ref] writes:
quoted
-			 # commas delimit multiple addresses
-			$aliases{$alias} = [ split_addrs($addr) ];
+			# commas delimit multiple addresses
+			my @addr = split_addrs($addr);
+
+			# quotes may be escaped in the file,
+			# remove them if paired so we do not
+			# double-escape them later.
+			s/^\\"(.*)\\"/"$1"/g foreach @addr;
+			$aliases{$alias} = \@addr
Can one address have two or more double-quoted string pieces in it?
If that is possible, (.*) above might want to become (.*?) or even
([^"]*) to make it less greedy, perhaps?
Yes.  Apparently it's possible to have a double-quote inside the name,
too.  mutt understands both of the following:

alias qn \"Q. N\\\"ame\" [off-list ref]   # becomes "Q. N\"ame"
alias dq \"Dub O.\" \"Q\" [off-list ref]  # becomes "Dub O. Q"

The "qn" case can be taken care of using a simpler replacement
on top my original RFC:
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -530,7 +530,7 @@ my %parse_alias = (
 			# quotes may be escaped in the file,
 			# remove them if paired so we do not
 			# double-escape them later.
-			s/^\\"(.*?)\\"/"$1"/g foreach @addr;
+			s/\\"/"/g foreach @addr;
 			$aliases{$alias} = \@addr
 		}}},
 	mailrc => sub { my $fh = shift; while (<$fh>) {
But I'm not sure how to handle the "dq" case or if that even
happens in practice, as attempting to save an alias with "Dub O." "Q"
in the From: header, mutt shortens it to the expected \"Dub O. Q\"
without extra quotes.

Saving "qn" round trips, so the \\\" in the middle is preserved.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help