{"thread":{"id":"28442","subject":"[PATCH] send-email: Honor multi-part email messages","startedAt":"2011-09-20T08:29:07Z","lastAt":"2013-01-24T19:11:55Z","messageCount":7,"participants":["Alexey Shumkin","Junio C Hamano","Shumkin Alexey"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"175845","messageId":"1316507347-6693-1-git-send-email-zapped@mail.ru","threadId":"28442","inReplyTo":null,"subject":"[PATCH] send-email: Honor multi-part email messages","fromName":"Alexey Shumkin","fromEmail":"zapped@mail.ru","sentAt":"2011-09-20T08:29:07Z","receivedAt":"2011-09-20T08:29:07Z","isPatch":true,"sender":{"key":"alex.crezoff@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1183752?v=4"},"body":"\"git format-patch --attach/--inline\" generates multi-part messages.\nEvery part of such messages can contain non-ASCII characters with its own\n\"Content-Type\" and \"Content-Transfer-Encoding\" headers.\nBut git-send-mail script interprets a patch-file as one-part message\nand does not recognize multi-part messages.\nSo already quoted printable email subject may be encoded as quoted printable\nagain. Due to this bug email subject looks corrupted in email clients.\n\nSigned-off-by: Alexey Shumkin <zapped@mail.ru>\n---\n git-send-email.perl   |    5 +++\n t/t9001-send-email.sh |   66 +++++++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 71 insertions(+), 0 deletions(-)\n\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex 98ab33a..1abf4a4 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -1403,12 +1403,17 @@ sub file_has_nonascii {\n \n sub body_or_subject_has_nonascii {\n \tmy $fn = shift;\n+\tmy $multipart = 0;\n \topen(my $fh, '<', $fn)\n \t\tor die \"unable to open $fn: $!\\n\";\n \twhile (my $line = <$fh>) {\n \t\tlast if $line =~ /^$/;\n+\t\tif ($line =~ /^Content-Type:\\s*multipart\\/mixed.*$/) {\n+\t\t\t$multipart = 1;\n+\t\t}\n \t\treturn 1 if $line =~ /^Subject.*[^[:ascii:]]/;\n \t}\n+\treturn 0 if $multipart;\n \twhile (my $line = <$fh>) {\n \t\treturn 1 if $line =~ /[^[:ascii:]]/;\n \t}\ndiff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh\nindex 579ddb7..151ad35 100755\n--- a/t/t9001-send-email.sh\n+++ b/t/t9001-send-email.sh\n@@ -1168,4 +1168,70 @@ test_expect_success $PREREQ '--force sends cover letter template anyway' '\n \ttest -n \"$(ls msgtxt*)\"\n '\n \n+test_expect_success $PREREQ 'setup multi-part message' '\n+cat >multi-part-email-using-8bit <<EOF\n+From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001\n+Message-Id: <bogus-message-id@example.com>\n+From: author@example.com\n+Date: Sat, 12 Jun 2010 15:53:58 +0200\n+Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=20?=\n+ =?UTF-8?q?=D1=84=D0=B0=D0=B9=D0=BB?=\n+MIME-Version: 1.0\n+Content-Type: multipart/mixed; boundary=\"------------123\"\n+\n+This is a multi-part message in MIME format.\n+--------------1.7.6.3.4.gf71f\n+Content-Type: text/plain; charset=UTF-8; format=fixed\n+Content-Transfer-Encoding: 8bit\n+\n+This is a message created with \"git format-patch --attach=123\"\n+---\n+ master   |    1 +\n+ файл |    1 +\n+ 2 files changed, 2 insertions(+), 0 deletions(-)\n+ create mode 100644 master\n+ create mode 100644 файл\n+\n+\n+--------------123\n+Content-Type: text/x-patch; name=\"0001-.patch\"\n+Content-Transfer-Encoding: 8bit\n+Content-Disposition: attachment; filename=\"0001-.patch\"\n+\n+diff --git a/master b/master\n+new file mode 100644\n+index 0000000..1f7391f\n+--- /dev/null\n++++ b/master\n+@@ -0,0 +1 @@\n++master\n+diff --git a/файл b/файл\n+new file mode 100644\n+index 0000000..44e5cfe\n+--- /dev/null\n++++ b/файл\n+@@ -0,0 +1 @@\n++содержимое файла\n+\n+--------------123--\n+EOF\n+'\n+\n+test_expect_success $PREREQ 'setup expect' '\n+cat >expected <<EOF\n+Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=20?= =?UTF-8?q?=D1=84=D0=B0=D0=B9=D0=BB?=\n+EOF\n+'\n+\n+test_expect_success $PREREQ '--attach/--inline also treats subject' '\n+\tclean_fake_sendmail &&\n+\techo bogus |\n+\tgit send-email --from=author@example.com --to=nobody@example.com \\\n+\t\t\t--smtp-server=\"$(pwd)/fake.sendmail\" \\\n+\t\t\t--8bit-encoding=UTF-8 \\\n+\t\t\tmulti-part-email-using-8bit >stdout &&\n+\tgrep \"Subject\" msgtxt1 >actual &&\n+\ttest_cmp expected actual\n+'\n+\n test_done\n-- \n1.7.6.3.4.gf71f\n"},{"id":"175882","messageId":"7v1uvb6mn9.fsf@alter.siamese.dyndns.org","threadId":"28442","inReplyTo":"1316507347-6693-1-git-send-email-zapped@mail.ru","subject":"Re: [PATCH] send-email: Honor multi-part email messages","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-09-20T19:26:18Z","receivedAt":"2011-09-20T19:26:18Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alexey Shumkin <zapped@mail.ru> writes:\n\n> diff --git a/git-send-email.perl b/git-send-email.perl\n> index 98ab33a..1abf4a4 100755\n> --- a/git-send-email.perl\n> +++ b/git-send-email.perl\n> @@ -1403,12 +1403,17 @@ sub file_has_nonascii {\n>  \n>  sub body_or_subject_has_nonascii {\n>  \tmy $fn = shift;\n> +\tmy $multipart = 0;\n>  \topen(my $fh, '<', $fn)\n>  \t\tor die \"unable to open $fn: $!\\n\";\n>  \twhile (my $line = <$fh>) {\n>  \t\tlast if $line =~ /^$/;\n> +\t\tif ($line =~ /^Content-Type:\\s*multipart\\/mixed.*$/) {\n> +\t\t\t$multipart = 1;\n> +\t\t}\n>  \t\treturn 1 if $line =~ /^Subject.*[^[:ascii:]]/;\n>  \t}\n> +\treturn 0 if $multipart;\n\nLooks as if you can lose the extra variable and return 0 immediately when\nyou find a line with that Content-Type inside the loop.\n\nWhat am I missing?\n"},{"id":"175892","messageId":"20110921001925.03a83d3a@zappedws","threadId":"28442","inReplyTo":"7v1uvb6mn9.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] send-email: Honor multi-part email messages","fromName":"Alexey Shumkin","fromEmail":"zapped@mail.ru","sentAt":"2011-09-20T20:19:25Z","receivedAt":"2011-09-20T20:19:25Z","isPatch":true,"sender":{"key":"alex.crezoff@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1183752?v=4"},"body":"> Alexey Shumkin <zapped@mail.ru> writes:\n> \n> > diff --git a/git-send-email.perl b/git-send-email.perl\n> > index 98ab33a..1abf4a4 100755\n> > --- a/git-send-email.perl\n> > +++ b/git-send-email.perl\n> > @@ -1403,12 +1403,17 @@ sub file_has_nonascii {\n> >  \n> >  sub body_or_subject_has_nonascii {\n> >  \tmy $fn = shift;\n> > +\tmy $multipart = 0;\n> >  \topen(my $fh, '<', $fn)\n> >  \t\tor die \"unable to open $fn: $!\\n\";\n> >  \twhile (my $line = <$fh>) {\n> >  \t\tlast if $line =~ /^$/;\n> > +\t\tif ($line\n> > =~ /^Content-Type:\\s*multipart\\/mixed.*$/) {\n> > +\t\t\t$multipart = 1;\n> > +\t\t}\n> >  \t\treturn 1 if $line =~ /^Subject.*[^[:ascii:]]/;\n> >  \t}\n> > +\treturn 0 if $multipart;\n> \n> Looks as if you can lose the extra variable and return 0 immediately\n> when you find a line with that Content-Type inside the loop.\nWell, as I understand \"current\" algorithm:\n1. It assumes that file is one-part email message\n2. Function searches non-ASCII characters in Subject header\n3. If none then it looks non-ASCII characters at message body\n\nmy changes are to skip looking at message body of a multi-part\nmessage as it has parts with their own Content-Type headers\n\nThe said above in details:\n1. To set flag when we meet Content-Type: multipart/mixed header\n2. After we processed all headers and did not found non-ASCII characters\nin a Subject we take a look at this flag and exit with 0\nif it is a multi-part message\n"},{"id":"207688","messageId":"20130124143816.7c33fc1c@ashu.dyn1.rarus.ru","threadId":"28442","inReplyTo":"20110921001925.03a83d3a@zappedws","subject":"Re: [PATCH] send-email: Honor multi-part email messages","fromName":"Alexey Shumkin","fromEmail":"alex.crezoff@gmail.com","sentAt":"2013-01-24T10:38:16Z","receivedAt":"2013-01-24T10:38:16Z","isPatch":true,"sender":{"key":"alex.crezoff@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1183752?v=4"},"body":"Bump\n"},{"id":"207698","messageId":"7v622mcuyb.fsf@alter.siamese.dyndns.org","threadId":"28442","inReplyTo":"20130124143816.7c33fc1c@ashu.dyn1.rarus.ru","subject":"Re: [PATCH] send-email: Honor multi-part email messages","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-01-24T18:11:24Z","receivedAt":"2013-01-24T18:11:24Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alexey Shumkin <alex.crezoff@gmail.com> writes:\n\n> Bump\n\nBump what???\n"},{"id":"207701","messageId":"CAEFUfsE-Ca=4jAyoaCtoeVYX0Etsn2Cj42OJm+nu4042JPJaBg@mail.gmail.com","threadId":"28442","inReplyTo":"7v622mcuyb.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] send-email: Honor multi-part email messages","fromName":"Shumkin Alexey","fromEmail":"alex.crezoff@gmail.com","sentAt":"2013-01-24T18:31:46Z","receivedAt":"2013-01-24T18:31:46Z","isPatch":true,"sender":{"key":"alex.crezoff@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1183752?v=4"},"body":"I've meant you did not reply to my last message in this thread\nhttp://thread.gmane.org/gmane.comp.version-control.git/181791\n\n2013/1/24 Junio C Hamano <gitster@pobox.com>\n>\n> Alexey Shumkin <alex.crezoff@gmail.com> writes:\n>\n> > Bump\n>\n> Bump what???\n"},{"id":"207702","messageId":"7vr4labdl0.fsf@alter.siamese.dyndns.org","threadId":"28442","inReplyTo":"CAEFUfsE-Ca=4jAyoaCtoeVYX0Etsn2Cj42OJm+nu4042JPJaBg@mail.gmail.com","subject":"Re: [PATCH] send-email: Honor multi-part email messages","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-01-24T19:11:55Z","receivedAt":"2013-01-24T19:11:55Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Shumkin Alexey <alex.crezoff@gmail.com> writes:\n\n> I've meant you did not reply to my last message in this thread\n> http://thread.gmane.org/gmane.comp.version-control.git/181791\n\nPlease repost the patch (with possible updates) for review when\nattempting to resurrect an ancient topic, instead of forcing people\nto hunt for an ancient message.\n\nI think your patch is wrong.  What happens when we see a Subject:\nline with a non-ascii on it that causes an early return of the loop\nbefore your new code has a chance to see Content-Type: header?\n"}]}