git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2] git-send-email.perl: improve detection of MIME encoded-words

From
Brandon Casey <drafnel@gmail.com>
Date
Jun 8, 2009, 00:25 UTC
Message-ID
<1244420758-5604-1-git-send-email-drafnel@gmail.com>
In-Reply-To
<ee63ef30906070945g62e94313r8b2a7128bde16f9d@mail.gmail.com>
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>
---

Here's a replacement patch which increases the range of excluded characters allowed as tokens so only ASCII characters are allowed (minus the other exclusions).

-brandon
 git-send-email.perl |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/git-send-email.perl b/git-send-email.perl
index 3d6a982..8a1a40d 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;
 	}
 
-- 
1.6.3.1.9.g95405b
Previous: Brandon CaseyNext: Brandon Casey
Message 4 of 5 in “git-send-email.perl: improve detection of MIME encoded-words”
  1. 1/2 git-send-email.perl: improve detection of MIME encoded-wordsBrandon Casey, Jun 7, 2009
  2. 2/2 send-email: use UTF-8 rather than utf-8 for consistencyBrandon Casey, Jun 7, 2009
  3. Brandon CaseyJun 7, 2009
  4. git-send-email.perl: improve detection of MIME encoded-wordsBrandon Casey, Jun 8, 2009
  5. Brandon CaseyJun 8, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.