Skip to content

Commit

Permalink
git-send-email.perl: improve detection of MIME encoded-words
Browse files Browse the repository at this point in the history
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 <drafnel@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Brandon Casey authored and Junio C Hamano committed Jun 9, 2009
1 parent cb319c3 commit a3a8262
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion git-send-email.perl
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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;
}

Expand Down

0 comments on commit a3a8262

Please sign in to comment.