{"thread":{"id":"12670","subject":"[PATCH] Add MIME information to outgoing email","startedAt":"2008-03-13T16:40:19Z","lastAt":"2008-04-10T18:47:03Z","messageCount":25,"participants":["Samuel Tardieu","Jeff King","Junio C Hamano","Brian Swetland","Teemu Likonen","Jay Soffian","Jan Hudec"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"71959","messageId":"1205426419-4594-1-git-send-email-sam@rfc1149.net","threadId":"12670","inReplyTo":null,"subject":"[PATCH] Add MIME information to outgoing email","fromName":"Samuel Tardieu","fromEmail":"sam@rfc1149.net","sentAt":"2008-03-13T16:40:19Z","receivedAt":"2008-03-13T16:40:19Z","isPatch":true,"sender":{"key":"sam@rfc1149.net","avatar":"https://avatars.githubusercontent.com/u/44656?v=4"},"body":"Add MIME-Version/Content-Type/Content-Transfer-Encoding headers in\nmessages generated with git-format-patch. Without it, messages generated\nwithout using --attach or --inline didn't have any content type information.\n\nI got hit with this problem yesterday when sending a patch to linux-kernel\nwith a commit message containing the name \"Pádraig\" in it. Moreover,\nthe mailing-list software added an incorrect ISO-8859-1 encoding information\nwhich mangled Pádraig's name.\n\nSigned-off-by: Samuel Tardieu <sam@rfc1149.net>\n---\n log-tree.c |   11 ++++++++++-\n 1 files changed, 10 insertions(+), 1 deletions(-)\n\ndiff --git a/log-tree.c b/log-tree.c\nindex 608f697..0dacf63 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -198,7 +198,16 @@ void log_write_email_headers(struct rev_info *opt, const char *name,\n \t\t\t opt->no_inline ? \"attachment\" : \"inline\",\n \t\t\t name);\n \t\topt->diffopt.stat_sep = buffer;\n-\t}\n+\t} else {\n+\t\tstatic char buffer[1024];\n+\t\tsnprintf(buffer, sizeof(buffer) - 1,\n+\t\t\t \"%s\"\n+\t\t\t \"MIME-Version: 1.0\\n\"\n+\t\t\t \"Content-Type: text/plain; charset=UTF-8; format=fixed\\n\"\n+\t\t\t \"Content-Transfer-Encoding: 8bit\\n\",\n+\t\t\t extra_headers ? extra_headers : \"\");\n+\t\textra_headers = buffer;\n+\t};\n \t*subject_p = subject;\n \t*extra_headers_p = extra_headers;\n }\n-- \n1.5.4.4.653.g7cf1e.dirty\n"},{"id":"71960","messageId":"20080313170016.GA3439@sigill.intra.peff.net","threadId":"12670","inReplyTo":"1205426419-4594-1-git-send-email-sam@rfc1149.net","subject":"Re: [PATCH] Add MIME information to outgoing email","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-03-13T17:00:16Z","receivedAt":"2008-03-13T17:00:16Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Mar 13, 2008 at 05:40:19PM +0100, Samuel Tardieu wrote:\n\n> Add MIME-Version/Content-Type/Content-Transfer-Encoding headers in\n> messages generated with git-format-patch. Without it, messages generated\n> without using --attach or --inline didn't have any content type information.\n> \n> I got hit with this problem yesterday when sending a patch to linux-kernel\n> with a commit message containing the name \"Pádraig\" in it. Moreover,\n> the mailing-list software added an incorrect ISO-8859-1 encoding information\n> which mangled Pádraig's name.\n\nIt's supposed to handle this automatically if the commit message\ncontains non-ascii characters. What version of git were you using?\n\n-Peff\n"},{"id":"71962","messageId":"2008-03-13-18-14-36+trackit+sam@rfc1149.net","threadId":"12670","inReplyTo":"20080313170016.GA3439@sigill.intra.peff.net","subject":"Re: [PATCH] Add MIME information to outgoing email","fromName":"Samuel Tardieu","fromEmail":"sam@rfc1149.net","sentAt":"2008-03-13T17:14:36Z","receivedAt":"2008-03-13T17:14:36Z","isPatch":true,"sender":{"key":"sam@rfc1149.net","avatar":"https://avatars.githubusercontent.com/u/44656?v=4"},"body":"On 13/03, Jeff King wrote:\n\n| It's supposed to handle this automatically if the commit message\n| contains non-ascii characters. What version of git were you using?\n\nA version from \"next\" from March 8:\nea6cde37d54121c5a1e1da51e1cd5cf27bfa3904 (+ 1 unrelated patch)\n\nE.g, does \"git format-patch a1eebf~1..a1eebf\" add MIME headers for you\nwithout my patch?\n"},{"id":"71982","messageId":"7vhcfaxxxk.fsf@gitster.siamese.dyndns.org","threadId":"12670","inReplyTo":"1205426419-4594-1-git-send-email-sam@rfc1149.net","subject":"Re: [PATCH] Add MIME information to outgoing email","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-03-13T18:48:23Z","receivedAt":"2008-03-13T18:48:23Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Samuel Tardieu <sam@rfc1149.net> writes:\n\n> Add MIME-Version/Content-Type/Content-Transfer-Encoding headers in\n> messages generated with git-format-patch. Without it, messages generated\n> without using --attach or --inline didn't have any content type information.\n\nIsn't that job for send-email (or user's MUA)?  I really do not think we\nwant to clutter format-patch output any more than necessary.\n"},{"id":"71985","messageId":"2008-03-13-20-05-55+trackit+sam@rfc1149.net","threadId":"12670","inReplyTo":"7vhcfaxxxk.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] Add MIME information to outgoing email","fromName":"Samuel Tardieu","fromEmail":"sam@rfc1149.net","sentAt":"2008-03-13T19:05:55Z","receivedAt":"2008-03-13T19:05:55Z","isPatch":true,"sender":{"key":"sam@rfc1149.net","avatar":"https://avatars.githubusercontent.com/u/44656?v=4"},"body":"On 13/03, Junio C Hamano wrote:\n\n| Samuel Tardieu <sam@rfc1149.net> writes:\n| \n| > Add MIME-Version/Content-Type/Content-Transfer-Encoding headers in\n| > messages generated with git-format-patch. Without it, messages generated\n| > without using --attach or --inline didn't have any content type information.\n| \n| Isn't that job for send-email (or user's MUA)?  I really do not think we\n| want to clutter format-patch output any more than necessary.\n\nOnly format-patch knows what encoding has been used by itself to\ngenerate the message. Doing it at any later stage would have to guess\nwhat the correct charset is.\n"},{"id":"72065","messageId":"20080314112139.GA12846@bulgaria.corp.google.com","threadId":"12670","inReplyTo":"2008-03-13-20-05-55+trackit+sam@rfc1149.net","subject":"Re: [PATCH] Add MIME information to outgoing email","fromName":"Brian Swetland","fromEmail":"swetland@google.com","sentAt":"2008-03-14T11:21:39Z","receivedAt":"2008-03-14T11:21:39Z","isPatch":true,"sender":{"key":"swetland@google.com","avatar":"https://gravatar.com/avatar/b26b7c772097c55d8febb0fc027dd2ef577a05994a321819f49ab3c9153ac8b1?d=mp&s=160"},"body":"[Samuel Tardieu <sam@rfc1149.net>]\n> On 13/03, Junio C Hamano wrote:\n> \n> | Samuel Tardieu <sam@rfc1149.net> writes:\n> | \n> | > Add MIME-Version/Content-Type/Content-Transfer-Encoding headers in\n> | > messages generated with git-format-patch. Without it, messages generated\n> | > without using --attach or --inline didn't have any content type information.\n> | \n> | Isn't that job for send-email (or user's MUA)?  I really do not think we\n> | want to clutter format-patch output any more than necessary.\n> \n> Only format-patch knows what encoding has been used by itself to\n> generate the message. Doing it at any later stage would have to guess\n> what the correct charset is.\n\nWhen the encoded string is entirely ascii except for one or two characters\n(such as occurs in a lot of patches I handle from people with names\nnot represented in plain ascii) guessing later on seems to run pretty\nhigh risk of guessing wrong.\n\nI've taken to manually adding UTF-8 content-type/transfer-encoding\nheaders to avoid the routine mangling of my coworkers' names and\nwould welcome a change to do this automatically.\n\nConsidering that UTF-8 is the expected default encoding (right?) for\ngit metadata, it seems to be the sane thing to indicate if the default\nis unchanged.\n\nBrian\n\n> \n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n"},{"id":"72066","messageId":"2008-03-14-12-57-06+trackit+sam@rfc1149.net","threadId":"12670","inReplyTo":"20080314112139.GA12846@bulgaria.corp.google.com","subject":"Re: [PATCH] Add MIME information to outgoing email","fromName":"Samuel Tardieu","fromEmail":"sam@rfc1149.net","sentAt":"2008-03-14T11:57:06Z","receivedAt":"2008-03-14T11:57:06Z","isPatch":true,"sender":{"key":"sam@rfc1149.net","avatar":"https://avatars.githubusercontent.com/u/44656?v=4"},"body":"On 14/03, Brian Swetland wrote:\n\n| > Only format-patch knows what encoding has been used by itself to\n| > generate the message. Doing it at any later stage would have to guess\n| > what the correct charset is.\n| \n| When the encoded string is entirely ascii except for one or two characters\n| (such as occurs in a lot of patches I handle from people with names\n| not represented in plain ascii) guessing later on seems to run pretty\n| high risk of guessing wrong.\n| [...]\n| Considering that UTF-8 is the expected default encoding (right?) for\n| git metadata, it seems to be the sane thing to indicate if the default\n| is unchanged.\n\nYup.\n"},{"id":"72078","messageId":"20080314132949.GC2932@coredump.intra.peff.net","threadId":"12670","inReplyTo":"2008-03-13-18-14-36+trackit+sam@rfc1149.net","subject":"Re: [PATCH] Add MIME information to outgoing email","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-03-14T13:29:49Z","receivedAt":"2008-03-14T13:29:49Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Mar 13, 2008 at 06:14:36PM +0100, Samuel Tardieu wrote:\n\n> | It's supposed to handle this automatically if the commit message\n> | contains non-ascii characters. What version of git were you using?\n> \n> A version from \"next\" from March 8:\n> ea6cde37d54121c5a1e1da51e1cd5cf27bfa3904 (+ 1 unrelated patch)\n\nHmm, that is certainly recent enough.\n\n> E.g, does \"git format-patch a1eebf~1..a1eebf\" add MIME headers for you\n> without my patch?\n\nSorry, I don't have that commit. What repo is it in?\n\nIt does work for me with this simple test:\n\n  mkdir repo && cd repo && git init\n  echo content >file && git add file && git commit -m one\n  echo more >>file && git commit -a -m 'two\n\n  utf8 body: ñ'\n  git format-patch HEAD^\n  cat 0001-two.patch\n\nI get:\n\n-- >8 --\nFrom a9e3222c0dca0a2b1e1a53ab9b7a7526ed359b79 Mon Sep 17 00:00:00 2001\nFrom: Jeff King <peff@peff.net>\nDate: Fri, 14 Mar 2008 09:27:30 -0400\nSubject: [PATCH] two\nMIME-Version: 1.0\nContent-Type: text/plain; charset=utf-8\nContent-Transfer-Encoding: 8bit\n\nutf8 body: ñ\n---\n file |    1 +\n 1 files changed, 1 insertions(+), 0 deletions(-)\n\ndiff --git a/file b/file\nindex d95f3ad..94b334d 100644\n--- a/file\n+++ b/file\n@@ -1 +1,2 @@\n content\n+more\n-- \n1.5.4.4.553.g83e84.dirty\n-- 8< --\n\nSo I assume there is some bug in git that is being triggered by the\ncommit you mention.\n\n-Peff\n"},{"id":"72079","messageId":"2008-03-14-14-40-22+trackit+sam@rfc1149.net","threadId":"12670","inReplyTo":"20080314132949.GC2932@coredump.intra.peff.net","subject":"Re: [PATCH] Add MIME information to outgoing email","fromName":"Samuel Tardieu","fromEmail":"sam@rfc1149.net","sentAt":"2008-03-14T13:40:22Z","receivedAt":"2008-03-14T13:40:22Z","isPatch":true,"sender":{"key":"sam@rfc1149.net","avatar":"https://avatars.githubusercontent.com/u/44656?v=4"},"body":"On 14/03, Jeff King wrote:\n\n| Sorry, I don't have that commit. What repo is it in?\n\nJunio's \"next\" branch.\n\n| So I assume there is some bug in git that is being triggered by the\n| commit you mention.\n\nMaybe, that's why I'd be interested by the behaviour you get with it.\n"},{"id":"72080","messageId":"20080314134600.GA3968@coredump.intra.peff.net","threadId":"12670","inReplyTo":"2008-03-14-14-40-22+trackit+sam@rfc1149.net","subject":"Re: [PATCH] Add MIME information to outgoing email","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-03-14T13:46:01Z","receivedAt":"2008-03-14T13:46:01Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Mar 14, 2008 at 02:40:22PM +0100, Samuel Tardieu wrote:\n\n> | Sorry, I don't have that commit. What repo is it in?\n> \n> Junio's \"next\" branch.\n\nAh, sorry, for some reason I couldn't find it before. I must have\ntypo'd it.\n\nYes, it works fine for me:\n\n$ git-format-patch a1eebf~1..a1eebf\n0001-git.el-find-the-git-status-buffer-whatever-its-name.patch\n$ head 0001*\nFrom a1eebfb3a90b6c240afd1a32cfebe6ee5dbd72c5 Mon Sep 17 00:00:00 2001\nFrom: =?utf-8?q?R=C3=A9mi=20Vanicat?= <vanicat@debian.org>\nDate: Fri, 29 Feb 2008 19:28:19 +0100\nSubject: [PATCH] git.el: find the git-status buffer whatever its name is\nMIME-Version: 1.0\nContent-Type: text/plain; charset=utf-8\nContent-Transfer-Encoding: 8bit\n\ngit-status used the buffer name to find git-status buffers, and that\ncan fail if the buffer has another name, for example when multiple\n\n\n-Peff\n"},{"id":"72081","messageId":"2008-03-14-14-50-48+trackit+sam@rfc1149.net","threadId":"12670","inReplyTo":"20080314134600.GA3968@coredump.intra.peff.net","subject":"Re: [PATCH] Add MIME information to outgoing email","fromName":"Samuel Tardieu","fromEmail":"sam@rfc1149.net","sentAt":"2008-03-14T13:50:48Z","receivedAt":"2008-03-14T13:50:48Z","isPatch":true,"sender":{"key":"sam@rfc1149.net","avatar":"https://avatars.githubusercontent.com/u/44656?v=4"},"body":"On 14/03, Jeff King wrote:\n\n| Yes, it works fine for me:\n\nAhhhhh, found it. It looks like you have no format.headers configuration\nvariable, do you?\n"},{"id":"72086","messageId":"20080314143536.GA5362@coredump.intra.peff.net","threadId":"12670","inReplyTo":"2008-03-14-14-50-48+trackit+sam@rfc1149.net","subject":"Re: [PATCH] Add MIME information to outgoing email","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-03-14T14:35:36Z","receivedAt":"2008-03-14T14:35:36Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Mar 14, 2008 at 02:50:48PM +0100, Samuel Tardieu wrote:\n\n> | Yes, it works fine for me:\n> \n> Ahhhhh, found it. It looks like you have no format.headers configuration\n> variable, do you?\n\nNo, I don't. Having peeked a few days ago at the pretty-printing code,\nthat is almost certainly the problem (I think the extra_headers\nparameter is overloaded to handle both of these conditions). Can you\nwork up a patch?\n\n-Peff\n"},{"id":"72088","messageId":"2008-03-14-15-40-29+trackit+sam@rfc1149.net","threadId":"12670","inReplyTo":"20080314143536.GA5362@coredump.intra.peff.net","subject":"Re: [PATCH] Add MIME information to outgoing email","fromName":"Samuel Tardieu","fromEmail":"sam@rfc1149.net","sentAt":"2008-03-14T14:40:29Z","receivedAt":"2008-03-14T14:40:29Z","isPatch":true,"sender":{"key":"sam@rfc1149.net","avatar":"https://avatars.githubusercontent.com/u/44656?v=4"},"body":"On 14/03, Jeff King wrote:\n\n| No, I don't. Having peeked a few days ago at the pretty-printing code,\n| that is almost certainly the problem (I think the extra_headers\n| parameter is overloaded to handle both of these conditions). Can you\n| work up a patch?\n\nSure, but not before some time, I am quite busy with urgent work right\nnow. If you want to beat me at it, be my guest :)\n"},{"id":"72106","messageId":"7v4pb9qnuu.fsf@gitster.siamese.dyndns.org","threadId":"12670","inReplyTo":"20080313170016.GA3439@sigill.intra.peff.net","subject":"Re: [PATCH] Add MIME information to outgoing email","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-03-14T16:20:09Z","receivedAt":"2008-03-14T16:20:09Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> On Thu, Mar 13, 2008 at 05:40:19PM +0100, Samuel Tardieu wrote:\n>\n>> Add MIME-Version/Content-Type/Content-Transfer-Encoding headers in\n>> messages generated with git-format-patch. Without it, messages generated\n>> without using --attach or --inline didn't have any content type information.\n>> \n>> I got hit with this problem yesterday when sending a patch to linux-kernel\n>> with a commit message containing the name \"Pádraig\" in it. Moreover,\n>> the mailing-list software added an incorrect ISO-8859-1 encoding information\n>> which mangled Pádraig's name.\n>\n> It's supposed to handle this automatically if the commit message\n> contains non-ascii characters. What version of git were you using?\n\nYou are right.  The call-chain looks like this:\n\n    log_tree_diff_flush()\n     show_log()\n      log_write_email_headers()     writes mbox From\n      pretty_print_commit()\n                                    check commit log if it is pure ascii\n       pp_header()\n        pp_user_info()              writes RFC2822 From:\n       pp_title_line()              writes RFC2822 Subject:\n                                    writes MIME-Version: and friends if needed\n       pp_remainder()               writes the remainder of the log message\n      append_signoff()\n     printf(\"---\\n\")\n     diff_flush()                   writes the patch\n\nAt the beginning of pretty_print_commit() we look at the log and if it is\nnot ascii we pass that information down to pp_title_line() which is\nresponsible for writing MIME header at the appropriate place.\n\nIf your patch itself has some non-ASCII material, and if your commit log\nmessage is pure ASCII, the above would end up not writing MIME at all.  If\nyour commit log message is non ASCII, then we will mark it as if the\nentire message is in the encoding of the log in pp_title_line().  This\nmight look like a problem, but it is not something non multipart output of\nformat-patch should even try to cater to.  The payload (i.e. the patch)\nout of git has always been uninterpreted sequence of bytes (and it is not\ngoing to change).\n\nA patch to i18n po/ files for example could contain patches to different\nfiles encoded in KOI-8, BIG5, EUC-JP and UTF-8 at the same time.  There is\nno way to say \"text/plain; charset=X\" for such a payload (because there is\nno single charset used in such a patch), and git simply does not know nor\ncare about what encoding each file is in.  The output from git marks only\nthe part git knows the encoding about (i.e. the commit log message).\n\nHaving said all that, I notice that addition of format.headers variable\n(which I think is a later invention) was done not quite correctly.  In the\ncallchain above, pretty_print_commit() function checks the commit log but\nit is meant to do so only when we haven't emitted MIME Content-Type:\n(because the user told us to do multipart), and \"after_subject\" parameter\nwas getting passed around for it (and its callees) to detect exactly that.\nBut format.headers misused that variable to carry its contents along ---\nthere needs a way to pass \"have we said MIME-Version crap already\"\nseparately.\n"},{"id":"72135","messageId":"7vbq5hoy48.fsf_-_@gitster.siamese.dyndns.org","threadId":"12670","inReplyTo":"7v4pb9qnuu.fsf@gitster.siamese.dyndns.org","subject":"Re* [PATCH] Add MIME information to outgoing email","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-03-14T20:21:27Z","receivedAt":"2008-03-14T20:21:27Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Having said all that, I notice that addition of format.headers variable\n> (which I think is a later invention) was done not quite correctly.  In the\n> callchain above, pretty_print_commit() function checks the commit log but\n> it is meant to do so only when we haven't emitted MIME Content-Type:\n> (because the user told us to do multipart), and \"after_subject\" parameter\n> was getting passed around for it (and its callees) to detect exactly that.\n> But format.headers misused that variable to carry its contents along ---\n> there needs a way to pass \"have we said MIME-Version crap already\"\n> separately.\n\nI think the real culprit was the way the \"after_subject\" was added to the\ncallchain (it had loaded semantics -- \"here is what we want to say after\nemitting Subject: line\" and \"have we done any MIME yet?\"), not the poor\nguy who did format.headers.\n\nIn any case, this patch would hopefully separate the two.  The old\n\"plain_non_ascii\" parameter is now need_8bit_ct_header and now can have\none of three values:\n\n -1 : we've already done MIME crap so never add extra header to say this\n      is 8bit;\n\n 0  : we haven't done MIME and we have not seen anything that is 8bit yet.\n\n 1  : we haven't done MIME and we have seen something that is 8bit.\n      pp_title_line() needs to add MIME header.\n\n(As with any other patches I send during my lunchtime, this is untested).\n\n---\n\n builtin-log.c |    6 ++++--\n commit.h      |    4 ++--\n log-tree.c    |   15 ++++++++++++---\n log-tree.h    |    4 +++-\n pretty.c      |   24 +++++++++++-------------\n 5 files changed, 32 insertions(+), 21 deletions(-)\n\ndiff --git a/builtin-log.c b/builtin-log.c\nindex d983cbc..4b1b34f 100644\n--- a/builtin-log.c\n+++ b/builtin-log.c\n@@ -662,6 +662,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,\n \tint i;\n \tconst char *encoding = \"utf-8\";\n \tstruct diff_options opts;\n+\tint need_8bit_ct_header = 0;\n \n \tif (rev->commit_format != CMIT_FMT_EMAIL)\n \t\tdie(\"Cover letter needs email format\");\n@@ -672,7 +673,8 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,\n \n \thead_sha1 = sha1_to_hex(head->object.sha1);\n \n-\tlog_write_email_headers(rev, head_sha1, &subject_start, &extra_headers);\n+\tlog_write_email_headers(rev, head_sha1, &subject_start, &extra_headers,\n+\t\t\t\t&need_8bit_ct_header);\n \n \tcommitter = git_committer_info(0);\n \n@@ -681,7 +683,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,\n \tpp_user_info(NULL, CMIT_FMT_EMAIL, &sb, committer, DATE_RFC2822,\n \t\t     encoding);\n \tpp_title_line(CMIT_FMT_EMAIL, &msg, &sb, subject_start, extra_headers,\n-\t\t      encoding, 0);\n+\t\t      encoding, need_8bit_ct_header);\n \tpp_remainder(CMIT_FMT_EMAIL, &msg, &sb, 0);\n \tprintf(\"%s\\n\", sb.buf);\n \ndiff --git a/commit.h b/commit.h\nindex a1e9591..0907a78 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -70,7 +70,7 @@ extern void pretty_print_commit(enum cmit_fmt fmt, const struct commit*,\n                                 struct strbuf *,\n                                 int abbrev, const char *subject,\n                                 const char *after_subject, enum date_mode,\n-\t\t\t\tint non_ascii_present);\n+\t\t\t\tint need_8bit_ct_header);\n void pp_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb,\n \t\t   const char *line, enum date_mode dmode,\n \t\t   const char *encoding);\n@@ -80,7 +80,7 @@ void pp_title_line(enum cmit_fmt fmt,\n \t\t   const char *subject,\n \t\t   const char *after_subject,\n \t\t   const char *encoding,\n-\t\t   int plain_non_ascii);\n+\t\t   int need_8bit_ct_header);\n void pp_remainder(enum cmit_fmt fmt,\n \t\t  const char **msg_p,\n \t\t  struct strbuf *sb,\ndiff --git a/log-tree.c b/log-tree.c\nindex 608f697..f2ce32a 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -138,10 +138,14 @@ static int has_non_ascii(const char *s)\n }\n \n void log_write_email_headers(struct rev_info *opt, const char *name,\n-\t\t\t     const char **subject_p, const char **extra_headers_p)\n+\t\t\t     const char **subject_p,\n+\t\t\t     const char **extra_headers_p,\n+\t\t\t     int *need_8bit_ct_header_p)\n {\n \tconst char *subject = NULL;\n \tconst char *extra_headers = opt->extra_headers;\n+\n+\t*need_8bit_ct_header_p = 0; /* unknown */\n \tif (opt->total > 0) {\n \t\tstatic char buffer[64];\n \t\tsnprintf(buffer, sizeof(buffer),\n@@ -169,6 +173,7 @@ void log_write_email_headers(struct rev_info *opt, const char *name,\n \tif (opt->mime_boundary) {\n \t\tstatic char subject_buffer[1024];\n \t\tstatic char buffer[1024];\n+\t\t*need_8bit_ct_header_p = -1; /* NEVER */\n \t\tsnprintf(subject_buffer, sizeof(subject_buffer) - 1,\n \t\t\t \"%s\"\n \t\t\t \"MIME-Version: 1.0\\n\"\n@@ -212,6 +217,7 @@ void show_log(struct rev_info *opt, const char *sep)\n \tint abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40;\n \tconst char *extra;\n \tconst char *subject = NULL, *extra_headers = opt->extra_headers;\n+\tint need_8bit_ct_header = 0;\n \n \topt->loginfo = NULL;\n \tif (!opt->verbose_header) {\n@@ -255,7 +261,8 @@ void show_log(struct rev_info *opt, const char *sep)\n \n \tif (opt->commit_format == CMIT_FMT_EMAIL) {\n \t\tlog_write_email_headers(opt, sha1_to_hex(commit->object.sha1),\n-\t\t\t\t\t&subject, &extra_headers);\n+\t\t\t\t\t&subject, &extra_headers,\n+\t\t\t\t\t&need_8bit_ct_header);\n \t} else if (opt->commit_format != CMIT_FMT_USERFORMAT) {\n \t\tfputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), stdout);\n \t\tif (opt->commit_format != CMIT_FMT_ONELINE)\n@@ -299,9 +306,11 @@ void show_log(struct rev_info *opt, const char *sep)\n \t * And then the pretty-printed message itself\n \t */\n \tstrbuf_init(&msgbuf, 0);\n+\tif (need_8bit_ct_header >= 0)\n+\t\tneed_8bit_ct_header = has_non_ascii(opt->add_signoff);\n \tpretty_print_commit(opt->commit_format, commit, &msgbuf,\n \t\t\t    abbrev, subject, extra_headers, opt->date_mode,\n-\t\t\t    has_non_ascii(opt->add_signoff));\n+\t\t\t    need_8bit_ct_header);\n \n \tif (opt->add_signoff)\n \t\tappend_signoff(&msgbuf, opt->add_signoff);\ndiff --git a/log-tree.h b/log-tree.h\nindex 0cc9344..69c1c4b 100644\n--- a/log-tree.h\n+++ b/log-tree.h\n@@ -14,6 +14,8 @@ int log_tree_opt_parse(struct rev_info *, const char **, int);\n void show_log(struct rev_info *opt, const char *sep);\n void show_decorations(struct commit *commit);\n void log_write_email_headers(struct rev_info *opt, const char *name,\n-\t\t\t     const char **subject_p, const char **extra_headers_p);\n+\t\t\t     const char **subject_p,\n+\t\t\t     const char **extra_headers_p,\n+\t\t\t     int *need_8bit_ct_header_p);\n \n #endif\ndiff --git a/pretty.c b/pretty.c\nindex 703f521..7a5b115 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -636,7 +636,7 @@ void pp_title_line(enum cmit_fmt fmt,\n \t\t   const char *subject,\n \t\t   const char *after_subject,\n \t\t   const char *encoding,\n-\t\t   int plain_non_ascii)\n+\t\t   int need_8bit_ct_header)\n {\n \tstruct strbuf title;\n \n@@ -669,7 +669,7 @@ void pp_title_line(enum cmit_fmt fmt,\n \t}\n \tstrbuf_addch(sb, '\\n');\n \n-\tif (plain_non_ascii) {\n+\tif (need_8bit_ct_header > 0) {\n \t\tconst char *header_fmt =\n \t\t\t\"MIME-Version: 1.0\\n\"\n \t\t\t\"Content-Type: text/plain; charset=%s\\n\"\n@@ -718,9 +718,9 @@ void pp_remainder(enum cmit_fmt fmt,\n }\n \n void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,\n-\t\t\t\t  struct strbuf *sb, int abbrev,\n-\t\t\t\t  const char *subject, const char *after_subject,\n-\t\t\t\t  enum date_mode dmode, int plain_non_ascii)\n+\t\t\t struct strbuf *sb, int abbrev,\n+\t\t\t const char *subject, const char *after_subject,\n+\t\t\t enum date_mode dmode, int need_8bit_ct_header)\n {\n \tunsigned long beginning_of_body;\n \tint indent = 4;\n@@ -746,13 +746,11 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,\n \tif (fmt == CMIT_FMT_ONELINE || fmt == CMIT_FMT_EMAIL)\n \t\tindent = 0;\n \n-\t/* After-subject is used to pass in Content-Type: multipart\n-\t * MIME header; in that case we do not have to do the\n-\t * plaintext content type even if the commit message has\n-\t * non 7-bit ASCII character.  Otherwise, check if we need\n-\t * to say this is not a 7-bit ASCII.\n+\t/*\n+\t * We need to check and emit Content-type: to mark it\n+\t * as 8-bit if we haven't done so.\n \t */\n-\tif (fmt == CMIT_FMT_EMAIL && !after_subject) {\n+\tif (fmt == CMIT_FMT_EMAIL && need_8bit_ct_header == 0) {\n \t\tint i, ch, in_body;\n \n \t\tfor (in_body = i = 0; (ch = msg[i]); i++) {\n@@ -765,7 +763,7 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,\n \t\t\t\t\tin_body = 1;\n \t\t\t}\n \t\t\telse if (non_ascii(ch)) {\n-\t\t\t\tplain_non_ascii = 1;\n+\t\t\t\tneed_8bit_ct_header = 1;\n \t\t\t\tbreak;\n \t\t\t}\n \t\t}\n@@ -790,7 +788,7 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,\n \t/* These formats treat the title line specially. */\n \tif (fmt == CMIT_FMT_ONELINE || fmt == CMIT_FMT_EMAIL)\n \t\tpp_title_line(fmt, &msg, sb, subject,\n-\t\t\t      after_subject, encoding, plain_non_ascii);\n+\t\t\t      after_subject, encoding, need_8bit_ct_header);\n \n \tbeginning_of_body = sb->len;\n \tif (fmt != CMIT_FMT_ONELINE)\n"},{"id":"72141","messageId":"20080314212707.GA1027@coredump.intra.peff.net","threadId":"12670","inReplyTo":"7vbq5hoy48.fsf_-_@gitster.siamese.dyndns.org","subject":"Re: Re* [PATCH] Add MIME information to outgoing email","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-03-14T21:27:07Z","receivedAt":"2008-03-14T21:27:07Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Mar 14, 2008 at 01:21:27PM -0700, Junio C Hamano wrote:\n\n> I think the real culprit was the way the \"after_subject\" was added to the\n> callchain (it had loaded semantics -- \"here is what we want to say after\n> emitting Subject: line\" and \"have we done any MIME yet?\"), not the poor\n> guy who did format.headers.\n> \n> In any case, this patch would hopefully separate the two.  The old\n> \"plain_non_ascii\" parameter is now need_8bit_ct_header and now can have\n> one of three values:\n\nI was just about to submit a patch splitting after_subject into\n\"mime_headers\" and \"extra_headers\".\n\nI noticed another bug while doing mine: we are sometimes not strict\n_enough_ in squelching headers. A patch made with \"-s --attach\" when the\nsignoff has non-ascii characters would end up with duplicated MIME\nheaders. Your patch handles this fine.\n\nI think your approach is a little nicer. Here is the test case I wrote\nfor my patch. It covers the original problem and the one I mentioned\nabove; both fail with current master but pass with your patch.\n\n---\ndiff --git a/t/t4021-format-patch-signer-mime.sh b/t/t4021-format-patch-signer-mime.sh\nindex 67a70fa..9bc47a5 100755\n--- a/t/t4021-format-patch-signer-mime.sh\n+++ b/t/t4021-format-patch-signer-mime.sh\n@@ -38,5 +38,13 @@ test_expect_success 'format with non ASCII signer name' '\n \n '\n \n+test_expect_success 'attach and signoff do not duplicate mime headers' '\n+\n+\tGIT_COMMITTER_NAME=\"\u001b$B$O$^$N\u001b(B \u001b$B$U$K$*$&\u001b(B\" \\\n+\tgit format-patch -s --stdout -1 --attach >output &&\n+\ttest `grep -ci ^MIME-Version: output` = 1\n+\n+'\n+\n test_done\n \ndiff --git a/t/t4028-format-patch-mime-headers.sh b/t/t4028-format-patch-mime-headers.sh\nnew file mode 100755\nindex 0000000..204ba67\n--- /dev/null\n+++ b/t/t4028-format-patch-mime-headers.sh\n@@ -0,0 +1,30 @@\n+#!/bin/sh\n+\n+test_description='format-patch mime headers and extra headers do not conflict'\n+. ./test-lib.sh\n+\n+test_expect_success 'create commit with utf-8 body' '\n+\techo content >file &&\n+\tgit add file &&\n+\tgit commit -m one &&\n+\techo more >>file &&\n+\tgit commit -a -m \"two\n+\n+\tutf-8 body: ñ\"\n+'\n+\n+test_expect_success 'patch has mime headers' '\n+\trm -f 0001-two.patch &&\n+\tgit format-patch HEAD^ &&\n+\tgrep -i \"content-type: text/plain; charset=utf-8\" 0001-two.patch\n+'\n+\n+test_expect_success 'patch has mime and extra headers' '\n+\trm -f 0001-two.patch &&\n+\tgit config format.headers \"x-foo: bar\" &&\n+\tgit format-patch HEAD^ &&\n+\tgrep -i \"x-foo: bar\" 0001-two.patch &&\n+\tgrep -i \"content-type: text/plain; charset=utf-8\" 0001-two.patch\n+'\n+\n+test_done\n"},{"id":"73057","messageId":"200803252031.17017.tlikonen@iki.fi","threadId":"12670","inReplyTo":"7vhcfaxxxk.fsf@gitster.siamese.dyndns.org","subject":"MIME headers in introductory message (git send-email --compose)","fromName":"Teemu Likonen","fromEmail":"tlikonen@iki.fi","sentAt":"2008-03-25T18:31:16Z","receivedAt":"2008-03-25T18:31:16Z","isPatch":false,"sender":{"key":"tlikonen@iki.fi","avatar":null},"body":"Junio C Hamano kirjoitti:\n\n> Samuel Tardieu <sam@rfc1149.net> writes:\n> > Add MIME-Version/Content-Type/Content-Transfer-Encoding headers in\n> > messages generated with git-format-patch. Without it, messages\n> > generated without using --attach or --inline didn't have any\n> > content type information.\n>\n> Isn't that job for send-email (or user's MUA)?  I really do not think\n> we want to clutter format-patch output any more than necessary.\n\nBy the way, 'git send-email --compose' does not add MIME headers to \nintroductory message. All non-Ascii chars will output something \nundefined in receivers' end.\n\nI guess the right way would be to detect user's charset (locale) and add \nappropriate MIME headers. Also, the Subject field should be encoded if \nit contains non-Ascii characters.\n"},{"id":"73061","messageId":"76718490803251217q27ae4381h298ec6de8a4d965a@mail.gmail.com","threadId":"12670","inReplyTo":"200803252031.17017.tlikonen@iki.fi","subject":"Re: MIME headers in introductory message (git send-email --compose)","fromName":"Jay Soffian","fromEmail":"jaysoffian@gmail.com","sentAt":"2008-03-25T19:17:10Z","receivedAt":"2008-03-25T19:17:10Z","isPatch":false,"sender":{"key":"jaysoffian@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155970?v=4"},"body":"On Tue, Mar 25, 2008 at 2:31 PM, Teemu Likonen <tlikonen@iki.fi> wrote:\n> Junio C Hamano kirjoitti:\n>\n>  > Samuel Tardieu <sam@rfc1149.net> writes:\n>  > > Add MIME-Version/Content-Type/Content-Transfer-Encoding headers in\n>  > > messages generated with git-format-patch. Without it, messages\n>  > > generated without using --attach or --inline didn't have any\n>  > > content type information.\n>  >\n>  > Isn't that job for send-email (or user's MUA)?  I really do not think\n>  > we want to clutter format-patch output any more than necessary.\n>\n>  By the way, 'git send-email --compose' does not add MIME headers to\n>  introductory message. All non-Ascii chars will output something\n>  undefined in receivers' end.\n>\n>  I guess the right way would be to detect user's charset (locale) and add\n>  appropriate MIME headers. Also, the Subject field should be encoded if\n>  it contains non-Ascii characters.\n\nI stuck this in my config and it works-for-me:\n\n[format]\n\theaders = \\\n\"MIME-Version: 1.0\\n\\\nContent-Type: text/plain; charset=UTF-8\\n\\\nContent-Transfer-Encoding: 8bit\\n\"\n\nShrug. (Never tried putting non-ascii in the subject tho.)\n\nj.\n"},{"id":"73072","messageId":"7vhceuleeu.fsf@gitster.siamese.dyndns.org","threadId":"12670","inReplyTo":"76718490803251217q27ae4381h298ec6de8a4d965a@mail.gmail.com","subject":"Re: MIME headers in introductory message (git send-email --compose)","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-03-25T20:47:05Z","receivedAt":"2008-03-25T20:47:05Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Jay Soffian\" <jaysoffian@gmail.com> writes:\n\n> I stuck this in my config and it works-for-me:\n>\n> [format]\n> \theaders = \\\n> \"MIME-Version: 1.0\\n\\\n> Content-Type: text/plain; charset=UTF-8\\n\\\n> Content-Transfer-Encoding: 8bit\\n\"\n\nI suspect that you shouldn't do this.  This would badly interfere both\nwith existing format-patch behaviour that adds these MIME-Version and\nContent-Type headers by looking at the contents, and with recent\nformat-patch fix 6bf4f1b (format-patch: generate MIME header as needed\neven when there is format.header, 2008-03-14) to make the detection based\non contents (and presense of format.headers).\n"},{"id":"73073","messageId":"76718490803251359y53b505e4u781ded6df5364650@mail.gmail.com","threadId":"12670","inReplyTo":"7vhceuleeu.fsf@gitster.siamese.dyndns.org","subject":"Re: MIME headers in introductory message (git send-email --compose)","fromName":"Jay Soffian","fromEmail":"jaysoffian@gmail.com","sentAt":"2008-03-25T20:59:31Z","receivedAt":"2008-03-25T20:59:31Z","isPatch":false,"sender":{"key":"jaysoffian@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155970?v=4"},"body":"On Tue, Mar 25, 2008 at 4:47 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> \"Jay Soffian\" <jaysoffian@gmail.com> writes:\n>\n>  > I stuck this in my config and it works-for-me:\n>  >\n>  > [format]\n>  >       headers = \\\n>  > \"MIME-Version: 1.0\\n\\\n>  > Content-Type: text/plain; charset=UTF-8\\n\\\n>  > Content-Transfer-Encoding: 8bit\\n\"\n>\n>  I suspect that you shouldn't do this.  This would badly interfere both\n>  with existing format-patch behaviour that adds these MIME-Version and\n>  Content-Type headers by looking at the contents, and with recent\n>  format-patch fix 6bf4f1b (format-patch: generate MIME header as needed\n>  even when there is format.header, 2008-03-14) to make the detection based\n>  on contents (and presense of format.headers).\n\nFair enough. But I never send out a patch w/o looking at it in an editor\nfirst so I would've caught that. Thanks for the heads-up though.\n\nj.\n"},{"id":"73076","messageId":"20080325215614.GA5189@coredump.intra.peff.net","threadId":"12670","inReplyTo":"7vhceuleeu.fsf@gitster.siamese.dyndns.org","subject":"Re: MIME headers in introductory message (git send-email --compose)","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-03-25T21:56:15Z","receivedAt":"2008-03-25T21:56:15Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Mar 25, 2008 at 01:47:05PM -0700, Junio C Hamano wrote:\n\n> > I stuck this in my config and it works-for-me:\n> >\n> > [format]\n> > \theaders = \\\n> > \"MIME-Version: 1.0\\n\\\n> > Content-Type: text/plain; charset=UTF-8\\n\\\n> > Content-Transfer-Encoding: 8bit\\n\"\n> \n> I suspect that you shouldn't do this.  This would badly interfere both\n> with existing format-patch behaviour that adds these MIME-Version and\n> Content-Type headers by looking at the contents, and with recent\n> format-patch fix 6bf4f1b (format-patch: generate MIME header as needed\n> even when there is format.header, 2008-03-14) to make the detection based\n> on contents (and presense of format.headers).\n\nYes, I can confirm that that is problematic without even testing.  The\nwhole point of 6bf4f1b was that we _should_ add MIME headers even if the\nuser has set format.headers.\n\nWe could be more clever about parsing format.headers and mark the \"we\nhave already added MIME\" flag (I think we already have to do such\nparsing because of to/cc magic). But I have to wonder what the real goal\nis here. There has sometimes been a call for \"please add MIME headers\nunconditionally\"; maybe that is an option that people would like.\n\n-Peff\n"},{"id":"73078","messageId":"20080325220743.GA5248@coredump.intra.peff.net","threadId":"12670","inReplyTo":"20080325215614.GA5189@coredump.intra.peff.net","subject":"Re: MIME headers in introductory message (git send-email --compose)","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-03-25T22:07:43Z","receivedAt":"2008-03-25T22:07:43Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Mar 25, 2008 at 05:56:14PM -0400, Jeff King wrote:\n\n> We could be more clever about parsing format.headers and mark the \"we\n> have already added MIME\" flag (I think we already have to do such\n> parsing because of to/cc magic). But I have to wonder what the real goal\n\nI started on this out of curiosity, and it _is_ really simple, but it's\nalso wrong.  It can't be right to set your MIME headers statically\nbecause some options (like --attach) might cause us to have to put in\n_different_ MIME headers. So we are left with either conflicting\nheaders, disallowing --attach, ignoring some of your format.headers, or\npossibly picking out those headers and making them part of the header of\nthat patch part of the multipart. All of which seem a bit ugly to me.\n\nIf this is something people really want, I think just adding an \"always\nadd mime headers\" option makes the most sense.\n\n-Peff\n"},{"id":"73081","messageId":"20080325230649.GA5273@coredump.intra.peff.net","threadId":"12670","inReplyTo":"200803252031.17017.tlikonen@iki.fi","subject":"Re: MIME headers in introductory message (git send-email --compose)","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-03-25T23:06:49Z","receivedAt":"2008-03-25T23:06:49Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Mar 25, 2008 at 08:31:16PM +0200, Teemu Likonen wrote:\n\n> By the way, 'git send-email --compose' does not add MIME headers to \n> introductory message. All non-Ascii chars will output something \n> undefined in receivers' end.\n> \n> I guess the right way would be to detect user's charset (locale) and add \n> appropriate MIME headers. Also, the Subject field should be encoded if \n> it contains non-Ascii characters.\n\nI just posted some patches to fix this; however, they always encode as\nutf-8. I'm not sure what is the best way to find the user's encoding.\nAIUI, locale environment variables are not enough, since, e.g., \"en_US\"\ncould come in iso8859-1 and utf-8 flavors. Is there a portable way to\nfigure this out? Should we be pulling it from .git/config? Neither the\ncommitEncoding nor the logOutputEncoding really makes sense to reuse.\n\n-Peff\n"},{"id":"73099","messageId":"76718490803251946t2640a8d2ga1e68ad06405c076@mail.gmail.com","threadId":"12670","inReplyTo":"20080325230649.GA5273@coredump.intra.peff.net","subject":"Re: MIME headers in introductory message (git send-email --compose)","fromName":"Jay Soffian","fromEmail":"jaysoffian@gmail.com","sentAt":"2008-03-26T02:46:42Z","receivedAt":"2008-03-26T02:46:42Z","isPatch":false,"sender":{"key":"jaysoffian@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155970?v=4"},"body":"On Tue, Mar 25, 2008 at 7:06 PM, Jeff King <peff@peff.net> wrote:\n> On Tue, Mar 25, 2008 at 08:31:16PM +0200, Teemu Likonen wrote:\n>\n>  > By the way, 'git send-email --compose' does not add MIME headers to\n>  > introductory message. All non-Ascii chars will output something\n>  > undefined in receivers' end.\n>  >\n>  > I guess the right way would be to detect user's charset (locale) and add\n>  > appropriate MIME headers. Also, the Subject field should be encoded if\n>  > it contains non-Ascii characters.\n>\n>  I just posted some patches to fix this; however, they always encode as\n>  utf-8. I'm not sure what is the best way to find the user's encoding.\n>  AIUI, locale environment variables are not enough, since, e.g., \"en_US\"\n>  could come in iso8859-1 and utf-8 flavors. Is there a portable way to\n>  figure this out? Should we be pulling it from .git/config?\n\nI think so. There's no reason the message encoding necessarily matches the\nlocale anyway. There are ways to guess, but I think .git/config is sanest\nwith UTF-8 as the default.\n\nj.\n"},{"id":"74089","messageId":"20080410184703.GA14912@efreet.light.src","threadId":"12670","inReplyTo":"20080325230649.GA5273@coredump.intra.peff.net","subject":"Re: MIME headers in introductory message (git send-email --compose)","fromName":"Jan Hudec","fromEmail":"bulb@ucw.cz","sentAt":"2008-04-10T18:47:03Z","receivedAt":"2008-04-10T18:47:03Z","isPatch":false,"sender":{"key":"bulb@ucw.cz","avatar":null},"body":"On Tue, Mar 25, 2008 at 19:06:49 -0400, Jeff King wrote:\n> On Tue, Mar 25, 2008 at 08:31:16PM +0200, Teemu Likonen wrote:\n> \n> > By the way, 'git send-email --compose' does not add MIME headers to \n> > introductory message. All non-Ascii chars will output something \n> > undefined in receivers' end.\n> > \n> > I guess the right way would be to detect user's charset (locale) and add \n> > appropriate MIME headers. Also, the Subject field should be encoded if \n> > it contains non-Ascii characters.\n> \n> I just posted some patches to fix this; however, they always encode as\n> utf-8. I'm not sure what is the best way to find the user's encoding.\n> AIUI, locale environment variables are not enough, since, e.g., \"en_US\"\n> could come in iso8859-1 and utf-8 flavors. Is there a portable way to\n> figure this out? Should we be pulling it from .git/config? Neither the\n> commitEncoding nor the logOutputEncoding really makes sense to reuse.\n\nThe portable way is to use the locale environment variables, but you have to\nread them via the libc locale interface. You set the LC_CTYPE locale category\nvia setlocale (which will consult LC_CTYPE, LC_ALL and LANG environment AND\nthe locale database) and than ask for charset using nl_langinfo(CODESET).\nTo do the equivalent from the shell, call `locale charmap`. From perl, either\nuse langinfo in I18N::Langinfo, or just use the ':locale' IO stream option\nprovided by encoding pragma to read the file in unicode no matter what the\nlocale encoding was (this is perl 5.8.<something> -- in older one, you'd have\nto use I18N::Langinfo anyway).\n\n-- \n\t\t\t\t\t\t Jan 'Bulb' Hudec <bulb@ucw.cz>\n"}]}