{"thread":{"id":"28410","subject":"[PATCH] send-email: Honor multi-part email messages","startedAt":"2011-09-16T22:32:48Z","lastAt":"2011-09-16T22:32:48Z","messageCount":1,"participants":["Alexey Shumkin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"175674","messageId":"1316212368-334-1-git-send-email-zapped@mail.ru","threadId":"28410","inReplyTo":null,"subject":"[PATCH] send-email: Honor multi-part email messages","fromName":"Alexey Shumkin","fromEmail":"zapped@mail.ru","sentAt":"2011-09-16T22:32:48Z","receivedAt":"2011-09-16T22:32:48Z","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"}]}