From: Kirill Smelkov Date: Sun, 1 Feb 2009 17:45:05 +0000 (+0300) Subject: mailinfo: cleanup extra spaces for complex 'From:' X-Git-Tag: v1.6.2-rc0~40 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=08e6710f76165f79cfa3cde9b10bb051fb0d0dc9;p=git.git mailinfo: cleanup extra spaces for complex 'From:' currently for cases like From: A U Thor (Comment) mailinfo extracts the following 'Author:' field: Author: A U Thor (Comment) ^^ which has two extra spaces left in there after removed email part. I think this is wrong so here is a fix. Signed-off-by: Kirill Smelkov Signed-off-by: Junio C Hamano --- diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c index d4dc23a36..2789ccdf7 100644 --- a/builtin-mailinfo.c +++ b/builtin-mailinfo.c @@ -29,6 +29,9 @@ static struct strbuf **p_hdr_data, **s_hdr_data; #define MAX_HDR_PARSED 10 #define MAX_BOUNDARIES 5 +static void cleanup_space(struct strbuf *sb); + + static void get_sane_name(struct strbuf *out, struct strbuf *name, struct strbuf *email) { struct strbuf *src = name; @@ -109,11 +112,19 @@ static void handle_from(const struct strbuf *from) strbuf_add(&email, at, el); strbuf_remove(&f, at - f.buf, el + (at[el] ? 1 : 0)); - /* The remainder is name. It could be "John Doe " - * or "john.doe@xz (John Doe)", but we have removed the - * email part, so trim from both ends, possibly removing - * the () pair at the end. + /* The remainder is name. It could be + * + * - "John Doe " (a), or + * - "john.doe@xz (John Doe)" (b), or + * - "John (zzz) Doe (Comment)" (c) + * + * but we have removed the email part, so + * + * - remove extra spaces which could stay after email (case 'c'), and + * - trim from both ends, possibly removing the () pair at the end + * (cases 'a' and 'b'). */ + cleanup_space(&f); strbuf_trim(&f); if (f.buf[0] == '(' && f.len && f.buf[f.len - 1] == ')') { strbuf_remove(&f, 0, 1); diff --git a/t/t5100/info0001 b/t/t5100/info0001 index 8c052777e..f951538ac 100644 --- a/t/t5100/info0001 +++ b/t/t5100/info0001 @@ -1,4 +1,4 @@ -Author: A U Thor +Author: A (zzz) U Thor (Comment) Email: a.u.thor@example.com Subject: a commit. Date: Fri, 9 Jun 2006 00:44:16 -0700 diff --git a/t/t5100/rfc2047-info-0004 b/t/t5100/rfc2047-info-0004 index 0ca7ff052..f67a90a97 100644 --- a/t/t5100/rfc2047-info-0004 +++ b/t/t5100/rfc2047-info-0004 @@ -1,4 +1,4 @@ -Author: Nathaniel Borenstein (םולש ןב ילטפנ) +Author: Nathaniel Borenstein (םולש ןב ילטפנ) Email: nsb@thumper.bellcore.com Subject: Test of new header generator diff --git a/t/t5100/sample.mbox b/t/t5100/sample.mbox index 85df55f2c..c5ad206b4 100644 --- a/t/t5100/sample.mbox +++ b/t/t5100/sample.mbox @@ -2,10 +2,10 @@ From nobody Mon Sep 17 00:00:00 2001 -From: A +From: A (zzz) U Thor - + (Comment) Date: Fri, 9 Jun 2006 00:44:16 -0700 Subject: [PATCH] a commit.