Skip to content

Commit

Permalink
send-email: handle adjacent RFC 2047-encoded words properly
Browse files Browse the repository at this point in the history
The RFC says that they are to be concatenated after decoding (i.e. the
intervening whitespace is ignored).

Signed-off-by: Роман Донченко <dpb@corrigendum.ru>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Роман Донченко authored and Junio C Hamano committed Dec 15, 2014
1 parent 11f70a7 commit ab47e2a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
26 changes: 16 additions & 10 deletions git-send-email.perl
Original file line number Diff line number Diff line change
Expand Up @@ -912,17 +912,23 @@ sub make_message_id {
sub unquote_rfc2047 {
local ($_) = @_;
my $charset;
s{$re_encoded_word}{
$charset = $1;
my $encoding = $2;
my $text = $3;
if ($encoding eq 'q' || $encoding eq 'Q') {
$text =~ s/_/ /g;
$text =~ s/=([0-9A-F]{2})/chr(hex($1))/egi;
$text;
} else {
$&; # other encodings not supported yet
my $sep = qr/[ \t]+/;
s{$re_encoded_word(?:$sep$re_encoded_word)*}{
my @words = split $sep, $&;
foreach (@words) {
m/$re_encoded_word/;
$charset = $1;
my $encoding = $2;
my $text = $3;
if ($encoding eq 'q' || $encoding eq 'Q') {
$_ = $text;
s/_/ /g;
s/=([0-9A-F]{2})/chr(hex($1))/egi;
} else {
# other encodings not supported yet
}
}
join '', @words;
}eg;
return wantarray ? ($_, $charset) : $_;
}
Expand Down
7 changes: 7 additions & 0 deletions t/t9001-send-email.sh
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,13 @@ test_expect_success $PREREQ 'non-ascii self name is suppressed' "
'non_ascii_self_suppressed'
"

# This name is long enough to force format-patch to split it into multiple
# encoded-words, assuming it uses UTF-8 with the "Q" encoding.
test_expect_success $PREREQ 'long non-ascii self name is suppressed' "
test_suppress_self_quoted 'Ƒüñníęř €. Nâṁé' 'odd_?=mail@example.com' \
'long_non_ascii_self_suppressed'
"

test_expect_success $PREREQ 'sanitized self name is suppressed' "
test_suppress_self_unquoted '\"A U. Thor\"' 'author@example.com' \
'self_name_sanitized_suppressed'
Expand Down

0 comments on commit ab47e2a

Please sign in to comment.