{"thread":{"id":"12860","subject":"[PATCH 1/2] send-email: specify content-type of --compose body","startedAt":"2008-03-25T23:02:25Z","lastAt":"2008-03-25T23:02:25Z","messageCount":1,"participants":["Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"73079","messageId":"20080325230225.GA17744@coredump.intra.peff.net","threadId":"12860","inReplyTo":null,"subject":"[PATCH 1/2] send-email: specify content-type of --compose body","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-03-25T23:02:25Z","receivedAt":"2008-03-25T23:02:25Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"If the compose message contains non-ascii characters, then\nwe assume it is in utf-8 and include the appropriate MIME\nheaders. If the user has already included a MIME-Version\nheader, then we assume they know what they are doing and\ndon't add any headers.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n git-send-email.perl   |   24 ++++++++++++++++++++++++\n t/t9001-send-email.sh |   44 ++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 68 insertions(+), 0 deletions(-)\n\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex 9e568bf..7c4f06c 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -520,8 +520,22 @@ EOT\n \topen(C,\"<\",$compose_filename)\n \t\tor die \"Failed to open $compose_filename : \" . $!;\n \n+\tmy $need_8bit_cte = file_has_nonascii($compose_filename);\n+\tmy $in_body = 0;\n \twhile(<C>) {\n \t\tnext if m/^GIT: /;\n+\t\tif (!$in_body && /^\\n$/) {\n+\t\t\t$in_body = 1;\n+\t\t\tif ($need_8bit_cte) {\n+\t\t\t\tprint C2 \"MIME-Version: 1.0\\n\",\n+\t\t\t\t\t \"Content-Type: text/plain; \",\n+\t\t\t\t\t   \"charset=utf-8\\n\",\n+\t\t\t\t\t \"Content-Transfer-Encoding: 8bit\\n\";\n+\t\t\t}\n+\t\t}\n+\t\tif (!$in_body && /^MIME-Version:/i) {\n+\t\t\t$need_8bit_cte = 0;\n+\t\t}\n \t\tprint C2 $_;\n \t}\n \tclose(C);\n@@ -958,3 +972,13 @@ sub validate_patch {\n \t}\n \treturn undef;\n }\n+\n+sub file_has_nonascii {\n+\tmy $fn = shift;\n+\topen(my $fh, '<', $fn)\n+\t\tor die \"unable to open $fn: $!\\n\";\n+\twhile (my $line = <$fh>) {\n+\t\treturn 1 if $line =~ /[^[:ascii:]]/;\n+\t}\n+\treturn 0;\n+}\ndiff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh\nindex c0973b4..e222c49 100755\n--- a/t/t9001-send-email.sh\n+++ b/t/t9001-send-email.sh\n@@ -166,4 +166,48 @@ test_expect_success 'second message is patch' '\n \tgrep \"Subject:.*Second\" msgtxt2\n '\n \n+test_expect_success '--compose adds MIME for utf8 body' '\n+\tclean_fake_sendmail &&\n+\t(echo \"#!/bin/sh\" &&\n+\t echo \"echo utf8 body: àéìöú >>\\$1\"\n+\t) >fake-editor-utf8 &&\n+\tchmod +x fake-editor-utf8 &&\n+\techo y | \\\n+\t  GIT_EDITOR=$(pwd)/fake-editor-utf8 \\\n+\t  GIT_SEND_EMAIL_NOTTY=1 \\\n+\t  git send-email \\\n+\t  --compose --subject foo \\\n+\t  --from=\"Example <nobody@example.com>\" \\\n+\t  --to=nobody@example.com \\\n+\t  --smtp-server=\"$(pwd)/fake.sendmail\" \\\n+\t  $patches &&\n+\tgrep \"^utf8 body\" msgtxt1 &&\n+\tgrep \"^Content-Type: text/plain; charset=utf-8\" msgtxt1\n+'\n+\n+test_expect_success '--compose respects user mime type' '\n+\tclean_fake_sendmail &&\n+\t(echo \"#!/bin/sh\" &&\n+\t echo \"(echo MIME-Version: 1.0\"\n+\t echo \" echo Content-Type: text/plain\\\\; charset=iso-8859-1\"\n+\t echo \" echo Content-Transfer-Encoding: 8bit\"\n+\t echo \" echo Subject: foo\"\n+\t echo \" echo \"\n+\t echo \" echo utf8 body: àéìöú) >\\$1\"\n+\t) >fake-editor-utf8-mime &&\n+\tchmod +x fake-editor-utf8-mime &&\n+\techo y | \\\n+\t  GIT_EDITOR=$(pwd)/fake-editor-utf8-mime \\\n+\t  GIT_SEND_EMAIL_NOTTY=1 \\\n+\t  git send-email \\\n+\t  --compose --subject foo \\\n+\t  --from=\"Example <nobody@example.com>\" \\\n+\t  --to=nobody@example.com \\\n+\t  --smtp-server=\"$(pwd)/fake.sendmail\" \\\n+\t  $patches &&\n+\tgrep \"^utf8 body\" msgtxt1 &&\n+\tgrep \"^Content-Type: text/plain; charset=iso-8859-1\" msgtxt1 &&\n+\t! grep \"^Content-Type: text/plain; charset=utf-8\" msgtxt1\n+'\n+\n test_done\n-- \n1.5.5.rc1.123.ge5f4e6\n"}]}