{"thread":{"id":"10572","subject":"[PATCH] Make git-mailinfo strip whitespace from the start of the mail file.","startedAt":"2007-11-01T21:05:39Z","lastAt":"2007-11-04T13:32:00Z","messageCount":7,"participants":["Simon Sasburg","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"57865","messageId":"1193951139-2312-1-git-send-email-Simon.Sasburg@gmail.com","threadId":"10572","inReplyTo":null,"subject":"[PATCH] Make git-mailinfo strip whitespace from the start of the mail file.","fromName":"Simon Sasburg","fromEmail":"simon.sasburg@gmail.com","sentAt":"2007-11-01T21:05:39Z","receivedAt":"2007-11-01T21:05:39Z","isPatch":true,"sender":{"key":"simon.sasburg@gmail.com","avatar":null},"body":"This allows you to use files gotten through gmail's web interface via its 'Show original' option.\n\nSigned-off-by: Simon Sasburg <Simon.Sasburg@gmail.com>\n---\nNote that this doesn't exactly follow RFC 2822 as far as i can see, but i don't know if git prefers to be strict or tolerant in these cases, so i'm sending the patch anyway.\n\nIt certaily helps me, even if just a little bit.\n\n builtin-mailinfo.c |    6 ++++++\n 1 files changed, 6 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-mailinfo.c b/builtin-mailinfo.c\nindex fb12248..5d4b6bf 100644\n--- a/builtin-mailinfo.c\n+++ b/builtin-mailinfo.c\n@@ -915,6 +915,7 @@ static void handle_info(void)\n static int mailinfo(FILE *in, FILE *out, int ks, const char *encoding,\n \t\t    const char *msg, const char *patch)\n {\n+\tint peek;\n \tkeep_subject = ks;\n \tmetainfo_charset = encoding;\n \tfin = in;\n@@ -935,6 +936,11 @@ static int mailinfo(FILE *in, FILE *out, int ks, const char *encoding,\n \tp_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(char *));\n \ts_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(char *));\n \n+\tdo {\n+\t\tpeek = fgetc(in);\n+\t} while (peek == ' ' || peek == '\\r' || peek == '\\n');\n+\tungetc(peek, in);\n+\n \t/* process the email header */\n \twhile (read_one_header_line(line, sizeof(line), fin))\n \t\tcheck_header(line, sizeof(line), p_hdr_data, 1);\n-- \n1.5.3.4.502.g37c97\n"},{"id":"57876","messageId":"7vd4utabx0.fsf@gitster.siamese.dyndns.org","threadId":"10572","inReplyTo":"1193951139-2312-1-git-send-email-Simon.Sasburg@gmail.com","subject":"Re: [PATCH] Make git-mailinfo strip whitespace from the start of the mail file.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-11-01T21:33:31Z","receivedAt":"2007-11-01T21:33:31Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Just to help me understand why this change is needed...\n\nAre you using mailinfo directly without splitting with mailsplit\nfirst?\n"},{"id":"57882","messageId":"981e6de60711011441n5bef772cuda381c539c0a2603@mail.gmail.com","threadId":"10572","inReplyTo":"7vd4utabx0.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] Make git-mailinfo strip whitespace from the start of the mail file.","fromName":"Simon Sasburg","fromEmail":"simon.sasburg@gmail.com","sentAt":"2007-11-01T21:41:01Z","receivedAt":"2007-11-01T21:41:01Z","isPatch":true,"sender":{"key":"simon.sasburg@gmail.com","avatar":null},"body":"> Just to help me understand why this change is needed...\n>\n> Are you using mailinfo directly without splitting with mailsplit\n> first?\n\nWell, when using gmail's web interface, when reading a mail, there is\nthis option to show the raw mail text (headers+body) with the 'show\noriginal' option.\n\nIf you do 'save as..' in your browser to save what you get with that,\nand try to do git-am on that file, it fails because it starts with\nsome whitespace.\n\nWith this patch git-am works on these files.\n\nSo, i'm not using mailsplit or any other mail tools at all, just my\nbrowser and git.\n"},{"id":"57887","messageId":"7vr6j98uw5.fsf@gitster.siamese.dyndns.org","threadId":"10572","inReplyTo":"981e6de60711011441n5bef772cuda381c539c0a2603@mail.gmail.com","subject":"Re: [PATCH] Make git-mailinfo strip whitespace from the start of the mail file.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-11-01T22:26:34Z","receivedAt":"2007-11-01T22:26:34Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Simon Sasburg\" <simon.sasburg@gmail.com> writes:\n\n>> Just to help me understand why this change is needed...\n>>\n>> Are you using mailinfo directly without splitting with mailsplit\n>> first?\n>\n> Well, when using gmail's web interface, when reading a mail, there is\n> this option to show the raw mail text (headers+body) with the 'show\n> original' option.\n>\n> If you do 'save as..' in your browser to save what you get with that,\n> and try to do git-am on that file, it fails because it starts with\n> some whitespace.\n>\n> With this patch git-am works on these files.\n>\n> So, i'm not using mailsplit or any other mail tools at all, just my\n> browser and git.\n\nAh, I meant \"git-mailsplit\", which is the command internally run\nby \"git-am\" to preprocess the file and to split it into\nindividual mail pieces to be fed to \"git-mailinfo\".\n\nThat may suggest the change is better done in git-mailsplit not\ngit-mailinfo.\n\nOr perhaps both.\n"},{"id":"57897","messageId":"1193957865-3904-1-git-send-email-Simon.Sasburg@gmail.com","threadId":"10572","inReplyTo":"7vr6j98uw5.fsf@gitster.siamese.dyndns.org","subject":"[PATCH] Make git-mailsplit strip whitespace from the start of the mailbox file.","fromName":"Simon Sasburg","fromEmail":"simon.sasburg@gmail.com","sentAt":"2007-11-01T22:57:45Z","receivedAt":"2007-11-01T22:57:45Z","isPatch":true,"sender":{"key":"simon.sasburg@gmail.com","avatar":null},"body":"Signed-off-by: Simon Sasburg <Simon.Sasburg@gmail.com>\n---\n\nAh, i see.\n\nWell, this patch also fixes the problem in my case.\n\n builtin-mailsplit.c |    6 ++++++\n 1 files changed, 6 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-mailsplit.c b/builtin-mailsplit.c\nindex 43fc373..3fdeb23 100644\n--- a/builtin-mailsplit.c\n+++ b/builtin-mailsplit.c\n@@ -164,6 +164,7 @@ static int split_mbox(const char *file, const char *dir, int allow_bare,\n {\n \tchar name[PATH_MAX];\n \tint ret = -1;\n+\tint peek;\n \n \tFILE *f = !strcmp(file, \"-\") ? stdin : fopen(file, \"r\");\n \tint file_done = 0;\n@@ -173,6 +174,11 @@ static int split_mbox(const char *file, const char *dir, int allow_bare,\n \t\tgoto out;\n \t}\n \n+\tdo {\n+\t\tpeek = fgetc(f);\n+\t} while (peek == ' ' || peek == '\\r' || peek == '\\n');\n+\tungetc(peek, f);\n+\n \tif (fgets(buf, sizeof(buf), f) == NULL) {\n \t\t/* empty stdin is OK */\n \t\tif (f != stdin) {\n-- \n1.5.3.4.504.gdf75-dirty\n"},{"id":"57940","messageId":"7v8x5h58qj.fsf@gitster.siamese.dyndns.org","threadId":"10572","inReplyTo":"1193951139-2312-1-git-send-email-Simon.Sasburg@gmail.com","subject":"Re: [PATCH] Make git-mailinfo strip whitespace from the start of the mail file.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-11-02T08:53:24Z","receivedAt":"2007-11-02T08:53:24Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Simon Sasburg <simon.sasburg@gmail.com> writes:\n\n> @@ -935,6 +936,11 @@ static int mailinfo(FILE *in, FILE *out, int ks, const char *encoding,\n>  \tp_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(char *));\n>  \ts_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(char *));\n>  \n> +\tdo {\n> +\t\tpeek = fgetc(in);\n> +\t} while (peek == ' ' || peek == '\\r' || peek == '\\n');\n> +\tungetc(peek, in);\n> +\n\nI wonder why this is not using isspace(peek).\n"},{"id":"58263","messageId":"1194183120-3660-1-git-send-email-Simon.Sasburg@gmail.com","threadId":"10572","inReplyTo":"7v8x5h58qj.fsf@gitster.siamese.dyndns.org","subject":"[PATCH] Make git-mailsplit strip whitespace from the start of the mailbox file.","fromName":"Simon Sasburg","fromEmail":"simon.sasburg@gmail.com","sentAt":"2007-11-04T13:32:00Z","receivedAt":"2007-11-04T13:32:00Z","isPatch":true,"sender":{"key":"simon.sasburg@gmail.com","avatar":null},"body":"This will allow it to handle the files gotten through gmail's web interface via its 'Show original' option.\nThese files contain the mail headers and the mail body, but start with some whitespace.\nNow you can give these files to git-am without having to remove the whitespace yourself.\n\nSigned-off-by: Simon Sasburg <Simon.Sasburg@gmail.com>\n---\n\nOn Nov 2, 2007 9:53 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> I wonder why this is not using isspace(peek).\n\nFixed.\n\nOn Nov 1, 2007 11:26 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Ah, I meant \"git-mailsplit\", which is the command internally run\n> by \"git-am\" to preprocess the file and to split it into\n> individual mail pieces to be fed to \"git-mailinfo\".\n> \n> That may suggest the change is better done in git-mailsplit not\n> git-mailinfo.\n\nThe files from gmail only contain 1 mail per file, but having git-mailspit\nmassage these into a proper file that git-mailinfo can parse seems like\na sane solution to me.\n\n builtin-mailsplit.c |    6 ++++++\n 1 files changed, 6 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-mailsplit.c b/builtin-mailsplit.c\nindex 43fc373..74b0470 100644\n--- a/builtin-mailsplit.c\n+++ b/builtin-mailsplit.c\n@@ -164,6 +164,7 @@ static int split_mbox(const char *file, const char *dir, int allow_bare,\n {\n \tchar name[PATH_MAX];\n \tint ret = -1;\n+\tint peek;\n \n \tFILE *f = !strcmp(file, \"-\") ? stdin : fopen(file, \"r\");\n \tint file_done = 0;\n@@ -173,6 +174,11 @@ static int split_mbox(const char *file, const char *dir, int allow_bare,\n \t\tgoto out;\n \t}\n \n+\tdo {\n+\t\tpeek = fgetc(f);\n+\t} while (isspace(peek));\n+\tungetc(peek, f);\n+\n \tif (fgets(buf, sizeof(buf), f) == NULL) {\n \t\t/* empty stdin is OK */\n \t\tif (f != stdin) {\n-- \n1.5.3.4.504.gdf75-dirty\n"}]}