{"thread":{"id":"38176","subject":"[PATCH v2 2/2] send-email: handle adjacent RFC 2047-encoded words properly","startedAt":"2014-12-14T15:59:46Z","lastAt":"2014-12-15T23:13:39Z","messageCount":3,"participants":["Роман Донченко","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":2},"messages":[{"id":"253683","messageId":"1418572787-2056-1-git-send-email-dpb@corrigendum.ru","threadId":"38176","inReplyTo":null,"subject":"[PATCH v2 1/2] send-email: align RFC 2047 decoding more closely with the spec","fromName":"Роман Донченко","fromEmail":"dpb@corrigendum.ru","sentAt":"2014-12-14T15:59:46Z","receivedAt":"2014-12-14T15:59:46Z","isPatch":true,"sender":{"key":"dpb@corrigendum.ru","avatar":"https://avatars.githubusercontent.com/u/2391761?v=4"},"body":"More specifically:\n\n* Add \"\\\" to the list of characters not allowed in a token (see RFC 2047\n  errata).\n\n* Share regexes between unquote_rfc2047 and is_rfc2047_quoted. Besides\n  removing duplication, this also makes unquote_rfc2047 more stringent.\n\n* Allow both \"q\" and \"Q\" to identify the encoding.\n\n* Allow lowercase hexadecimal digits in the \"Q\" encoding.\n\nAnd, more on the cosmetic side:\n\n* Change the \"encoded-text\" regex to exclude rather than include characters,\n  for clarity and consistency with \"token\".\n\nSigned-off-by: Роман Донченко <dpb@corrigendum.ru>\nAcked-by: Jeff King <peff@peff.net>\n---\n git-send-email.perl | 30 +++++++++++++++++++-----------\n 1 file changed, 19 insertions(+), 11 deletions(-)\n\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex 9949db0..d461ffb 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -145,6 +145,11 @@ my $have_mail_address = eval { require Mail::Address; 1 };\n my $smtp;\n my $auth;\n \n+# Regexes for RFC 2047 productions.\n+my $re_token = qr/[^][()<>@,;:\\\\\"\\/?.= \\000-\\037\\177-\\377]+/;\n+my $re_encoded_text = qr/[^? \\000-\\037\\177-\\377]+/;\n+my $re_encoded_word = qr/=\\?($re_token)\\?($re_token)\\?($re_encoded_text)\\?=/;\n+\n # Variables we fill in automatically, or via prompting:\n my (@to,$no_to,@initial_to,@cc,$no_cc,@initial_cc,@bcclist,$no_bcc,@xh,\n \t$initial_reply_to,$initial_subject,@files,\n@@ -913,15 +918,20 @@ $time = time - scalar $#files;\n \n sub unquote_rfc2047 {\n \tlocal ($_) = @_;\n-\tmy $encoding;\n-\ts{=\\?([^?]+)\\?q\\?(.*?)\\?=}{\n-\t\t$encoding = $1;\n-\t\tmy $e = $2;\n-\t\t$e =~ s/_/ /g;\n-\t\t$e =~ s/=([0-9A-F]{2})/chr(hex($1))/eg;\n-\t\t$e;\n+\tmy $charset;\n+\ts{$re_encoded_word}{\n+\t\t$charset = $1;\n+\t\tmy $encoding = $2;\n+\t\tmy $text = $3;\n+\t\tif ($encoding eq 'q' || $encoding eq 'Q') {\n+\t\t\t$text =~ s/_/ /g;\n+\t\t\t$text =~ s/=([0-9A-F]{2})/chr(hex($1))/egi;\n+\t\t\t$text;\n+\t\t} else {\n+\t\t\t$&; # other encodings not supported yet\n+\t\t}\n \t}eg;\n-\treturn wantarray ? ($_, $encoding) : $_;\n+\treturn wantarray ? ($_, $charset) : $_;\n }\n \n sub quote_rfc2047 {\n@@ -934,10 +944,8 @@ sub quote_rfc2047 {\n \n sub is_rfc2047_quoted {\n \tmy $s = shift;\n-\tmy $token = qr/[^][()<>@,;:\"\\/?.= \\000-\\037\\177-\\377]+/;\n-\tmy $encoded_text = qr/[!->@-~]+/;\n \tlength($s) <= 75 &&\n-\t$s =~ m/^(?:\"[[:ascii:]]*\"|=\\?$token\\?$token\\?$encoded_text\\?=)$/o;\n+\t$s =~ m/^(?:\"[[:ascii:]]*\"|$re_encoded_word)$/o;\n }\n \n sub subject_needs_rfc2047_quoting {\n-- \n2.1.1\n"},{"id":"253682","messageId":"1418572787-2056-2-git-send-email-dpb@corrigendum.ru","threadId":"38176","inReplyTo":"1418572787-2056-1-git-send-email-dpb@corrigendum.ru","subject":"[PATCH v2 2/2] send-email: handle adjacent RFC 2047-encoded words properly","fromName":"Роман Донченко","fromEmail":"dpb@corrigendum.ru","sentAt":"2014-12-14T15:59:47Z","receivedAt":"2014-12-14T15:59:47Z","isPatch":true,"sender":{"key":"dpb@corrigendum.ru","avatar":"https://avatars.githubusercontent.com/u/2391761?v=4"},"body":"The RFC says that they are to be concatenated after decoding (i.e. the\nintervening whitespace is ignored).\n\nSigned-off-by: Роман Донченко <dpb@corrigendum.ru>\nAcked-by: Jeff King <peff@peff.net>\n---\n git-send-email.perl   | 26 ++++++++++++++++----------\n t/t9001-send-email.sh |  7 +++++++\n 2 files changed, 23 insertions(+), 10 deletions(-)\n\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex d461ffb..7d5cc8a 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -919,17 +919,23 @@ $time = time - scalar $#files;\n sub unquote_rfc2047 {\n \tlocal ($_) = @_;\n \tmy $charset;\n-\ts{$re_encoded_word}{\n-\t\t$charset = $1;\n-\t\tmy $encoding = $2;\n-\t\tmy $text = $3;\n-\t\tif ($encoding eq 'q' || $encoding eq 'Q') {\n-\t\t\t$text =~ s/_/ /g;\n-\t\t\t$text =~ s/=([0-9A-F]{2})/chr(hex($1))/egi;\n-\t\t\t$text;\n-\t\t} else {\n-\t\t\t$&; # other encodings not supported yet\n+\tmy $sep = qr/[ \\t]+/;\n+\ts{$re_encoded_word(?:$sep$re_encoded_word)*}{\n+\t\tmy @words = split $sep, $&;\n+\t\tforeach (@words) {\n+\t\t\tm/$re_encoded_word/;\n+\t\t\t$charset = $1;\n+\t\t\tmy $encoding = $2;\n+\t\t\tmy $text = $3;\n+\t\t\tif ($encoding eq 'q' || $encoding eq 'Q') {\n+\t\t\t\t$_ = $text;\n+\t\t\t\ts/_/ /g;\n+\t\t\t\ts/=([0-9A-F]{2})/chr(hex($1))/egi;\n+\t\t\t} else {\n+\t\t\t\t# other encodings not supported yet\n+\t\t\t}\n \t\t}\n+\t\tjoin '', @words;\n \t}eg;\n \treturn wantarray ? ($_, $charset) : $_;\n }\ndiff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh\nindex 19a3ced..fa965ff 100755\n--- a/t/t9001-send-email.sh\n+++ b/t/t9001-send-email.sh\n@@ -240,6 +240,13 @@ test_expect_success $PREREQ 'non-ascii self name is suppressed' \"\n \t\t'non_ascii_self_suppressed'\n \"\n \n+# This name is long enough to force format-patch to split it into multiple\n+# encoded-words, assuming it uses UTF-8 with the \"Q\" encoding.\n+test_expect_success $PREREQ 'long non-ascii self name is suppressed' \"\n+\ttest_suppress_self_quoted 'Ƒüñníęř €. Nâṁé' 'odd_?=mail@example.com' \\\n+\t\t'long_non_ascii_self_suppressed'\n+\"\n+\n test_expect_success $PREREQ 'sanitized self name is suppressed' \"\n \ttest_suppress_self_unquoted '\\\"A U. Thor\\\"' 'author@example.com' \\\n \t\t'self_name_sanitized_suppressed'\n-- \n2.1.1\n"},{"id":"253718","messageId":"xmqqr3w0bj6k.fsf@gitster.dls.corp.google.com","threadId":"38176","inReplyTo":"1418572787-2056-1-git-send-email-dpb@corrigendum.ru","subject":"Re: [PATCH v2 1/2] send-email: align RFC 2047 decoding more closely with the spec","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-12-15T23:13:39Z","receivedAt":"2014-12-15T23:13:39Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks; queued both patches.\n"}]}