From: Brandon Casey Date: Mon, 8 Jun 2009 00:25:58 +0000 (-0500) Subject: git-send-email.perl: improve detection of MIME encoded-words X-Git-Tag: v1.6.4-rc0~80 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=a3a8262bf6e2acbb1b61cc25be073713e183c766;p=git-core%2Fgit.git 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 = especials = "(" / ")" / "<" / ">" / "@" / "," / ";" / ":" / " <"> / "/" / "[" / "]" / "?" / "." / "=" encoded-text = And rfc822 defines CHARs and CTLs as: CHAR = ; ( 0-177, 0.-127.) CTL = ; ( 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 Signed-off-by: Junio C Hamano --- diff --git a/git-send-email.perl b/git-send-email.perl index 3d6a98218..8a1a40d18 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -772,6 +772,14 @@ sub quote_rfc2047 { return $_; } +sub is_rfc2047_quoted { + my $s = shift; + my $token = '[^][()<>@,;:"\/?.= \000-\037\177-\377]+'; + my $encoded_text = '[!->@-~]+'; + length($s) <= 75 && + $s =~ m/^(?:"[[:ascii:]]*"|=\?$token\?$token\?$encoded_text\?=)$/o; +} + # use the simplest quoting being able to handle the recipient sub sanitize_address { @@ -783,7 +791,7 @@ sub sanitize_address } # if recipient_name is already quoted, do nothing - if ($recipient_name =~ /^("[[:ascii:]]*"|=\?utf-8\?q\?.*\?=)$/) { + if (is_rfc2047_quoted($recipient_name)) { return $recipient; }