{"thread":{"id":"31568","subject":"Content-Type handling","startedAt":"2012-09-17T16:34:13Z","lastAt":"2012-09-17T22:28:11Z","messageCount":3,"participants":["Tomas Cohen Arazi","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"199246","messageId":"CABZfb=UhKRREMG_XNJHDJHwbwroi5TKWwgQH-Ge1BDJETizG2Q@mail.gmail.com","threadId":"31568","inReplyTo":null,"subject":"Content-Type handling","fromName":"Tomas Cohen Arazi","fromEmail":"tomascohen@gmail.com","sentAt":"2012-09-17T16:34:13Z","receivedAt":"2012-09-17T16:34:13Z","isPatch":false,"sender":{"key":"tomascohen@gmail.com","avatar":null},"body":"Hi, I'm not sure it is a bug, but we used:\n\ngit config --global format.headers \"Content-Type: text/plain; charset=\\\"utf-8\\\"\"\n\nand recently (perhaps an Ubuntu default setup issue) the content-type\nis being automatically set, the result is that patches contain this:\n\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\nContent-Type: text/plain; charset=\"utf-8\"\n\nThis might not be the problem, but when I apply the patch I get this:\n\nfatal: cannot convert from UTF-8utf-8 to UTF-8\n\nwhich looks like a bug. Not sure it hasn't been reported before, but I\nthink it should take one of the content-type specifications and not\nappend both. I couldn't find a place to looks for previous bug reports\nto check, so forgive me if this is not the right place to report it.\n\nRegards\nTo+\n"},{"id":"199254","messageId":"7vy5k8va90.fsf@alter.siamese.dyndns.org","threadId":"31568","inReplyTo":"CABZfb=UhKRREMG_XNJHDJHwbwroi5TKWwgQH-Ge1BDJETizG2Q@mail.gmail.com","subject":"Re*: Content-Type handling","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-09-17T17:18:19Z","receivedAt":"2012-09-17T17:18:19Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Tomas Cohen Arazi <tomascohen@gmail.com> writes:\n\n> Hi, I'm not sure it is a bug, but we used:\n>\n> git config --global format.headers \"Content-Type: text/plain; charset=\\\"utf-8\\\"\"\n>\n> and recently (perhaps an Ubuntu default setup issue) the content-type\n> is being automatically set, the result is that patches contain this:\n>\n> Content-Type: text/plain; charset=UTF-8\n> Content-Transfer-Encoding: 8bit\n> Content-Type: text/plain; charset=\"utf-8\"\n>\n> This might not be the problem, but when I apply the patch I get this:\n>\n> fatal: cannot convert from UTF-8utf-8 to UTF-8\n>\n> which looks like a bug. Not sure it hasn't been reported before, but I\n> think it should take one of the content-type specifications and not\n> append both. I couldn't find a place to looks for previous bug reports\n> to check, so forgive me if this is not the right place to report it.\n\nWhat I think is happening is:\n\n * ancient \"git format-patch\" did not add appropriate content-type\n   headers, and that bug was fixed in more recent versions.\n\n * while waiting for the bug to get fixed, the user worked around by\n   having her own format.headers to work it around.\n\n * the user upgraded to a newer version of git without the bug.\n\n * Git trusts that the user knows better than git itself, and it\n   adds format.headers to whatever it needs to have in the message.\n   As a message with more than one content-type: is invalid, the\n   handcrafted format.headers used to be used as a workaround should\n   be removed, but it hasn't been.\n\n * Then the receiving end (mailinfo) gets confused by the invalid\n   input.\n\n\nAt least, a patch line this may alleviate the symptom.  It seems\nthat we assumed we won't see multiple charset=\"...\" so the parser,\nstarting from an empty charset, simply appended whatever it found\nin the message, instead of overwriting the old value it had.  The\nother user of the function this patch touches always makes sure the\n\"attr\" strbuf is empty before calling the function, and wouldn't\nhave been confused by multiple occurrences of the same header, and\nthis patch should not affect it, either.\n\n builtin/mailinfo.c | 5 ++---\n 1 file changed, 2 insertions(+), 3 deletions(-)\n\ndiff --git i/builtin/mailinfo.c w/builtin/mailinfo.c\nindex b691b77..2b3f4d9 100644\n--- i/builtin/mailinfo.c\n+++ w/builtin/mailinfo.c\n@@ -160,10 +160,9 @@ static int slurp_attr(const char *line, const char *name, struct strbuf *attr)\n \tconst char *ends, *ap = strcasestr(line, name);\n \tsize_t sz;\n \n-\tif (!ap) {\n-\t\tstrbuf_setlen(attr, 0);\n+\tstrbuf_setlen(attr, 0);\n+\tif (!ap)\n \t\treturn 0;\n-\t}\n \tap += strlen(name);\n \tif (*ap == '\"') {\n \t\tap++;\n"},{"id":"199305","messageId":"7vsjagqnev.fsf@alter.siamese.dyndns.org","threadId":"31568","inReplyTo":"7vy5k8va90.fsf@alter.siamese.dyndns.org","subject":"[PATCH] mailinfo: do not concatenate charset= attribute values from mime headers","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-09-17T22:28:11Z","receivedAt":"2012-09-17T22:28:11Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Content-type: text/plain; charset=UTF-8\" header should not appear\ntwice in the input, but it is always better to gracefully deal with\nsuch a case.  The current code concatenates the value to the values\nwe have seen previously, producing nonsense such as \"utf8UTF-8\".\n\nInstead of concatenating, forget the previous value and use the last\nvalue we see.\n\nReported-by: Tomas Cohen Arazi\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\n * I think this is the right thing to do after all.  Thanks for\n   bringing the issue up, Tomas.\n\n builtin/mailinfo.c  |  5 ++---\n t/t5100-mailinfo.sh |  2 +-\n t/t5100/info0017    |  5 +++++\n t/t5100/msg0017     |  2 ++\n t/t5100/patch0017   |  6 ++++++\n t/t5100/sample.mbox | 16 ++++++++++++++++\n 6 files changed, 32 insertions(+), 4 deletions(-)\n create mode 100644 t/t5100/info0017\n create mode 100644 t/t5100/msg0017\n create mode 100644 t/t5100/patch0017\n\ndiff --git a/builtin/mailinfo.c b/builtin/mailinfo.c\nindex eaf9e15..dd8b67c 100644\n--- a/builtin/mailinfo.c\n+++ b/builtin/mailinfo.c\n@@ -160,10 +160,9 @@ static int slurp_attr(const char *line, const char *name, struct strbuf *attr)\n \tconst char *ends, *ap = strcasestr(line, name);\n \tsize_t sz;\n \n-\tif (!ap) {\n-\t\tstrbuf_setlen(attr, 0);\n+\tstrbuf_setlen(attr, 0);\n+\tif (!ap)\n \t\treturn 0;\n-\t}\n \tap += strlen(name);\n \tif (*ap == '\"') {\n \t\tap++;\ndiff --git a/t/t5100-mailinfo.sh b/t/t5100-mailinfo.sh\nindex 81904d9..3e64a7a 100755\n--- a/t/t5100-mailinfo.sh\n+++ b/t/t5100-mailinfo.sh\n@@ -11,7 +11,7 @@ test_expect_success 'split sample box' \\\n \t'git mailsplit -o. \"$TEST_DIRECTORY\"/t5100/sample.mbox >last &&\n \tlast=`cat last` &&\n \techo total is $last &&\n-\ttest `cat last` = 16'\n+\ttest `cat last` = 17'\n \n check_mailinfo () {\n \tmail=$1 opt=$2\ndiff --git a/t/t5100/info0017 b/t/t5100/info0017\nnew file mode 100644\nindex 0000000..d2bc89f\n--- /dev/null\n+++ b/t/t5100/info0017\n@@ -0,0 +1,5 @@\n+Author: A U Thor\n+Email: a.u.thor@example.com\n+Subject: A E I O U\n+Date: Mon, 17 Sep 2012 14:23:44 -0700\n+\ndiff --git a/t/t5100/msg0017 b/t/t5100/msg0017\nnew file mode 100644\nindex 0000000..2ee0900\n--- /dev/null\n+++ b/t/t5100/msg0017\n@@ -0,0 +1,2 @@\n+New content here\n+\ndiff --git a/t/t5100/patch0017 b/t/t5100/patch0017\nnew file mode 100644\nindex 0000000..35cf84c\n--- /dev/null\n+++ b/t/t5100/patch0017\n@@ -0,0 +1,6 @@\n+diff --git a/foo b/foo\n+index e69de29..d95f3ad 100644\n+--- a/foo\n++++ b/foo\n+@@ -0,0 +1 @@\n++New content\ndiff --git a/t/t5100/sample.mbox b/t/t5100/sample.mbox\nindex de10312..fcc0e0d 100644\n--- a/t/t5100/sample.mbox\n+++ b/t/t5100/sample.mbox\n@@ -683,3 +683,19 @@ index e69de29..d95f3ad 100644\n @@ -0,0 +1 @@\n +content\n \n+From nobody Mon Sep 17 00:00:00 2001\n+From: A U Thor <a.u.thor@example.com>\n+Subject: A E I O U\n+Date: Mon, 17 Sep 2012 14:23:44 -0700\n+MIME-Version: 1.0\n+Content-Type: text/plain; charset=\"iso-2022-jp\"\n+Content-type: text/plain; charset=\"UTF-8\"\n+\n+New content here\n+\n+diff --git a/foo b/foo\n+index e69de29..d95f3ad 100644\n+--- a/foo\n++++ b/foo\n+@@ -0,0 +1 @@\n++New content\n-- \n1.7.12.556.gb90bb19\n"}]}