{"thread":{"id":"9397","subject":"[PATCH] send-email: let sanitize_address_rfc822 do rfc2047 quoting","startedAt":"2007-08-05T20:09:08Z","lastAt":"2007-08-09T12:10:26Z","messageCount":5,"participants":["Uwe Kleine-König","Jakub Narebski"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"49939","messageId":"11863445481996-git-send-email-ukleinek@informatik.uni-freiburg.de","threadId":"9397","inReplyTo":null,"subject":"[PATCH] send-email: let sanitize_address_rfc822 do rfc2047 quoting","fromName":"Uwe Kleine-König","fromEmail":"ukleinek@informatik.uni-freiburg.de","sentAt":"2007-08-05T20:09:08Z","receivedAt":"2007-08-05T20:09:08Z","isPatch":true,"sender":{"key":"u.kleine-koenig@pengutronix.de","avatar":"https://gravatar.com/avatar/354b5e3ceb2806a2f1e1e382ac29ddbdad18288654da62b61eb13583a857eee7?d=mp&s=160"},"body":"Without this patch I'm not able to properly send emails as I have a\nnon-ascii character in my name.\n\nThe former version tried to fix-up the real name part with double quotes\nif it includes a '.'.  I removed this as rfc2047 can handle a dot, too.\n\nSigned-off-by: Uwe Kleine-König <ukleinek@informatik.uni-freiburg.de>\n---\nHello,\n\nI already sent a similar patch that was discussed a bit[1], but was not taken.\n\nThe list of allowed character was taken from Python's email package.\n\nComparing with the former version I removed the quoting as described in\nthe 2nd paragraph of the log and now I only test $recipient_name once.\n\nI will try to send this patch with next + this patch.  I think it should\nwork in principle, but --suppress-from is not honored.  I will take a\nlook on this issue later.\n\nBest regards\nUwe\n\n[1] http://thread.gmane.org/gmane.comp.version-control.git/52093\n\n git-send-email.perl |   23 +++++++++++++++++------\n 1 files changed, 17 insertions(+), 6 deletions(-)\n\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex f43f92f..5785e29 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -459,16 +459,27 @@ sub unquote_rfc2047 {\n \treturn \"$_\";\n }\n \n-# If an address contains a . in the name portion, the name must be quoted.\n+# The name part of an address must consist only of alnum chars, space and a few\n+# others.\n+# If it contains a \"forbidden\" char in the name port, quote it according to\n+# rfc2047.\n sub sanitize_address_rfc822\n {\n \tmy ($recipient) = @_;\n-\tmy ($recipient_name) = ($recipient =~ /^(.*?)\\s+</);\n-\tif ($recipient_name && $recipient_name =~ /\\./ && $recipient_name !~ /^\".*\"$/) {\n-\t\tmy ($name, $addr) = ($recipient =~ /^(.*?)(\\s+<.*)/);\n-\t\t$recipient = \"\\\"$name\\\"$addr\";\n+\tmy ($recipient_name, $recipient_addr) = ($recipient =~ /^(.*?)(\\s+<.*)/);\n+\n+\tif ($recipient_name) {\n+\t\tif ($recipient_name =~ /[^-a-zA-Z0-9!*+\\/ ]/ && $recipient_name !~ /=\\?utf-8\\?q?.*\\?=/) {\n+\t\t\t$recipient_name =~ s/([^-a-zA-Z0-9!*+\\/ ])/sprintf(\"=%02X\", ord($1))/eg;\n+\t\t\t$recipient_name =~ s/ /_/;\n+\t\t\t$recipient_name =~ s/(.*)/=\\?utf-8\\?q\\?$1\\?=/;\n+\t\t}\n+\n+\t\treturn \"$recipient_name$recipient_addr\";\n+\n+\t} else {\n+\t\treturn \"$recipient\";\n \t}\n-\treturn $recipient;\n }\n \n sub send_message\n-- \n1.5.3.rc3.13.g7ab3\n"},{"id":"49964","messageId":"f95pie$8lv$1@sea.gmane.org","threadId":"9397","inReplyTo":"11863445481996-git-send-email-ukleinek@informatik.uni-freiburg.de","subject":"Re: [PATCH] send-email: let sanitize_address_rfc822 do rfc2047 quoting","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2007-08-06T00:21:35Z","receivedAt":"2007-08-06T00:21:35Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"[Uwe Kleine-König <ukleinek@informatik.uni-freiburg.de>,\n git@vger.kernel.org]\n\nUwe Kleine-König wrote:\n\n> Without this patch I'm not able to properly send emails as I have a\n> non-ascii character in my name.\n\nNice.\n\n> The former version tried to fix-up the real name part with double quotes\n> if it includes a '.'.  I removed this as rfc2047 can handle a dot, too.\n\nNot nice. I'd rather use double quotes if rfc2047 is not needed.\nIt means:\n - no quotes for us-ascii name, without '.'\n - quotes for us-ascii name with '.' and perhaps other forbidden characters\n   like '\"' or something\n - full rfc2047 quoting if name contains characters outside us-ascii.\n\n-- \nJakub Narebski\nWarsaw, Poland\nShadeHawk on #git\n"},{"id":"49995","messageId":"20070806083341.GA6625@informatik.uni-freiburg.de","threadId":"9397","inReplyTo":"f95pie$8lv$1@sea.gmane.org","subject":"Re: [PATCH] send-email: let sanitize_address_rfc822 do rfc2047 quoting","fromName":"Uwe Kleine-König","fromEmail":"ukleinek@informatik.uni-freiburg.de","sentAt":"2007-08-06T08:33:42Z","receivedAt":"2007-08-06T08:33:42Z","isPatch":true,"sender":{"key":"u.kleine-koenig@pengutronix.de","avatar":"https://gravatar.com/avatar/354b5e3ceb2806a2f1e1e382ac29ddbdad18288654da62b61eb13583a857eee7?d=mp&s=160"},"body":"Hello Jakub,\n\nJakub Narebski wrote:\n> > The former version tried to fix-up the real name part with double quotes\n> > if it includes a '.'.  I removed this as rfc2047 can handle a dot, too.\n> \n> Not nice. I'd rather use double quotes if rfc2047 is not needed.\n> It means:\n>  - no quotes for us-ascii name, without '.'\n>  - quotes for us-ascii name with '.' and perhaps other forbidden characters\n>    like '\"' or something\n>  - full rfc2047 quoting if name contains characters outside us-ascii.\nWell, that is OK for me, too.  I just thought to do just one thing that\nis able to handle all cases.  So the code is easier to read and most of\nthe time you don't see the quoted result anyhow.\n\nI will follow up with a new version later that will leave the second\npart out.  I don't know which chars can be quoted by \"...\", is it more\nthan .?\n\nBest regards\nUwe\n\n-- \nUwe Kleine-König\n\nhttp://www.google.com/search?q=1+stone%3D\n"},{"id":"50043","messageId":"11864324902764-git-send-email-ukleinek@informatik.uni-freiburg.de","threadId":"9397","inReplyTo":"20070806083341.GA6625@informatik.uni-freiburg.de","subject":"[PATCH] send-email: teach sanitize_address to do rfc2047 quoting","fromName":"Uwe Kleine-König","fromEmail":"ukleinek@informatik.uni-freiburg.de","sentAt":"2007-08-06T20:34:50Z","receivedAt":"2007-08-06T20:34:50Z","isPatch":true,"sender":{"key":"u.kleine-koenig@pengutronix.de","avatar":"https://gravatar.com/avatar/354b5e3ceb2806a2f1e1e382ac29ddbdad18288654da62b61eb13583a857eee7?d=mp&s=160"},"body":"Without this patch I'm not able to properly send emails as I have a\nnon-ascii character in my name.\n\nI removed the _rfc822 suffix from the function name as it now does more\nthan rfc822 quoting.\n\nI dug through rfc822 to do the double quoting right.  Only if that is not\npossible rfc2047 quoting is applied.\n\nSigned-off-by: Uwe Kleine-König <ukleinek@informatik.uni-freiburg.de>\nCc: Jakub Narebski <jnareb@gmail.com>\n---\nAs Jakub critizied now the \"easiest\" quoting is done.\n\n git-send-email.perl |   39 +++++++++++++++++++++++++++++----------\n 1 files changed, 29 insertions(+), 10 deletions(-)\n\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex f43f92f..39e433b 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -289,7 +289,7 @@ sub expand_aliases {\n }\n \n @to = expand_aliases(@to);\n-@to = (map { sanitize_address_rfc822($_) } @to);\n+@to = (map { sanitize_address($_) } @to);\n @initial_cc = expand_aliases(@initial_cc);\n @bcclist = expand_aliases(@bcclist);\n \n@@ -459,22 +459,41 @@ sub unquote_rfc2047 {\n \treturn \"$_\";\n }\n \n-# If an address contains a . in the name portion, the name must be quoted.\n-sub sanitize_address_rfc822\n+# use the simplest quoting being able to handle the recipient\n+sub sanitize_address\n {\n \tmy ($recipient) = @_;\n-\tmy ($recipient_name) = ($recipient =~ /^(.*?)\\s+</);\n-\tif ($recipient_name && $recipient_name =~ /\\./ && $recipient_name !~ /^\".*\"$/) {\n-\t\tmy ($name, $addr) = ($recipient =~ /^(.*?)(\\s+<.*)/);\n-\t\t$recipient = \"\\\"$name\\\"$addr\";\n+\tmy ($recipient_name, $recipient_addr) = ($recipient =~ /^(.*?)\\s*(<.*)/);\n+\n+\tif (not $recipient_name) {\n+\t\treturn \"$recipient\";\n+\t}\n+\n+\t# if recipient_name is already quoted, do nothing\n+\tif ($recipient_name =~ /^(\".*\"|=\\?utf-8\\?q\\?.*\\?=)$/) {\n+\t\treturn $recipient;\n+\t}\n+\n+\t# rfc2047 is needed if a non-ascii char is included\n+\tif ($recipient_name =~ /[^[:ascii:]]/) {\n+\t\t$recipient_name =~ s/([^-a-zA-Z0-9!*+\\/])/sprintf(\"=%02X\", ord($1))/eg;\n+\t\t$recipient_name =~ s/(.*)/=\\?utf-8\\?q\\?$1\\?=/;\n \t}\n-\treturn $recipient;\n+\n+\t# double quotes are needed if specials or CTLs are included\n+\telsif ($recipient_name =~ /[][()<>@,;:\\\\\".\\000-\\037\\177]/) {\n+\t\t$recipient_name =~ s/([\"\\\\\\r])/\\\\$1/;\n+\t\t$recipient_name = \"\\\"$recipient_name\\\"\";\n+\t}\n+\n+\treturn \"$recipient_name $recipient_addr\";\n+\n }\n \n sub send_message\n {\n \tmy @recipients = unique_email_list(@to);\n-\t@cc = (map { sanitize_address_rfc822($_) } @cc);\n+\t@cc = (map { sanitize_address($_) } @cc);\n \tmy $to = join (\",\\n\\t\", @recipients);\n \t@recipients = unique_email_list(@recipients,@cc,@bcclist);\n \t@recipients = (map { extract_valid_address($_) } @recipients);\n@@ -489,7 +508,7 @@ sub send_message\n \tif ($cc ne '') {\n \t\t$ccline = \"\\nCc: $cc\";\n \t}\n-\t$from = sanitize_address_rfc822($from);\n+\t$from = sanitize_address($from);\n \tmake_message_id();\n \n \tmy $header = \"From: $from\n-- \n1.5.3.rc3.13.g7ab3\n"},{"id":"50315","messageId":"20070809121026.GA3068@cassiopeia","threadId":"9397","inReplyTo":"11864324902764-git-send-email-ukleinek@informatik.uni-freiburg.de","subject":"Re: [PATCH] send-email: teach sanitize_address to do rfc2047 quoting","fromName":"Uwe Kleine-König","fromEmail":"ukleinek@informatik.uni-freiburg.de","sentAt":"2007-08-09T12:10:26Z","receivedAt":"2007-08-09T12:10:26Z","isPatch":true,"sender":{"key":"u.kleine-koenig@pengutronix.de","avatar":"https://gravatar.com/avatar/354b5e3ceb2806a2f1e1e382ac29ddbdad18288654da62b61eb13583a857eee7?d=mp&s=160"},"body":"Hello Junio,\n\nthanks for taking that patch in next (as 5b56aaa29e), but my name got\nscrambled once again in a strange way.\n\nPlease correct me if I'm wrong, but I think this time it happened\ncompletely on your side.\n\nThe mail I got returned from the list looks good and\nhttp://article.gmane.org/gmane.comp.version-control.git/55172 looks\nright, too.\n\nStrange enough my name is right in your What's in git.git (stable) mail.\n(http://article.gmane.org/gmane.comp.version-control.git/55221)\n\nI have still another problem with send-email.  I will try to come up\nwith a fix before 1.5.3.\n\nBest regards\nUwe\n\n-- \nUwe Kleine-König\n\nexit vi, lesson II:\n: w q ! <CR>\n\nNB: write the current file\n"}]}