Skip to content

Commit a3a8262

Browse files
drafnelgitster
authored andcommitted
git-send-email.perl: improve detection of MIME encoded-words
According to rfc2047, an encoded word has the following form: encoded-word = "=?" charset "?" encoding "?" encoded-text "?=" charset = token encoding = token token = <Any CHAR except SPACE, CTLs, and especials> especials = "(" / ")" / "<" / ">" / "@" / "," / ";" / ":" / " <"> / "/" / "[" / "]" / "?" / "." / "=" encoded-text = <Any printable ASCII character other than "?" or SPACE> And rfc822 defines CHARs and CTLs as: CHAR = <any ASCII character> ; ( 0-177, 0.-127.) CTL = <any ASCII control ; ( 0- 37, 0.- 31.) character and DEL> ; ( 177, 127.) The original code only detected rfc2047 encoded strings when the charset was UTF-8. This patch generalizes the matching expression and breaks the check for an rfc2047 encoded string into its own function. There's no real functional change, since any properly rfc2047 encoded string would have fallen through the remaining 'if' statements and been returned unchanged. Signed-off-by: Brandon Casey <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cb319c3 commit a3a8262

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

git-send-email.perl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,14 @@ sub quote_rfc2047 {
772772
return $_;
773773
}
774774

775+
sub is_rfc2047_quoted {
776+
my $s = shift;
777+
my $token = '[^][()<>@,;:"\/?.= \000-\037\177-\377]+';
778+
my $encoded_text = '[!->@-~]+';
779+
length($s) <= 75 &&
780+
$s =~ m/^(?:"[[:ascii:]]*"|=\?$token\?$token\?$encoded_text\?=)$/o;
781+
}
782+
775783
# use the simplest quoting being able to handle the recipient
776784
sub sanitize_address
777785
{
@@ -783,7 +791,7 @@ sub sanitize_address
783791
}
784792

785793
# if recipient_name is already quoted, do nothing
786-
if ($recipient_name =~ /^("[[:ascii:]]*"|=\?utf-8\?q\?.*\?=)$/) {
794+
if (is_rfc2047_quoted($recipient_name)) {
787795
return $recipient;
788796
}
789797

0 commit comments

Comments
 (0)