Skip to content

Commit b622d4d

Browse files
trastgitster
authored andcommitted
send-email: improve RFC2047 quote parsing
The RFC2047 unquoting, used to parse email addresses in From and Cc headers, is broken in several ways: * It erroneously substitutes ' ' for '_' in *the whole* header, even outside the quoted field. [Noticed by Christoph.] * It is too liberal in its matching, and happily matches the start of one quoted chunk against the end of another, or even just something that looks like such an end. [Noticed by Junio.] * It fundamentally cannot cope with encodings that are not a superset of ASCII, nor several (incompatible) encodings in the same header. This patch fixes the first two by doing a more careful decoding of the outer quoting (e.g. "=AB" to represent an octet whose value is 0xAB). Fixing the fundamental issues is left for a future, more intrusive, patch. Noticed-by: Christoph Miebach <[email protected]> Helped-by: Junio C Hamano <[email protected]> Signed-off-by: Thomas Rast <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d0f1ea6 commit b622d4d

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

git-send-email.perl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -862,11 +862,13 @@ sub make_message_id {
862862
sub unquote_rfc2047 {
863863
local ($_) = @_;
864864
my $encoding;
865-
if (s/=\?([^?]+)\?q\?(.*)\?=/$2/g) {
865+
s{=\?([^?]+)\?q\?(.*?)\?=}{
866866
$encoding = $1;
867-
s/_/ /g;
868-
s/=([0-9A-F]{2})/chr(hex($1))/eg;
869-
}
867+
my $e = $2;
868+
$e =~ s/_/ /g;
869+
$e =~ s/=([0-9A-F]{2})/chr(hex($1))/eg;
870+
$e;
871+
}eg;
870872
return wantarray ? ($_, $encoding) : $_;
871873
}
872874

t/t9001-send-email.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,19 @@ test_expect_success $PREREQ '--compose adds MIME for utf8 subject' '
841841
grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
842842
'
843843

844+
test_expect_success $PREREQ 'utf8 author is correctly passed on' '
845+
clean_fake_sendmail &&
846+
test_commit weird_author &&
847+
test_when_finished "git reset --hard HEAD^" &&
848+
git commit --amend --author "Füñný Nâmé <[email protected]>" &&
849+
git format-patch --stdout -1 >funny_name.patch &&
850+
git send-email --from="Example <[email protected]>" \
851+
852+
--smtp-server="$(pwd)/fake.sendmail" \
853+
funny_name.patch &&
854+
grep "^From: Füñný Nâmé <[email protected]>" msgtxt1
855+
'
856+
844857
test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
845858
echo master > master &&
846859
git add master &&

0 commit comments

Comments
 (0)