Skip to content

Commit

Permalink
mailinfo: cleanup extra spaces for complex 'From:'
Browse files Browse the repository at this point in the history
currently for cases like

    From: A U Thor <a.u.thor@example.com> (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 <kirr@landau.phys.spbu.ru>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Kirill Smelkov authored and Junio C Hamano committed Feb 1, 2009
1 parent c0f6f67 commit 08e6710
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
19 changes: 15 additions & 4 deletions builtin-mailinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 <john.doe@xz>"
* 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 <john.doe@xz>" (a), or
* - "john.doe@xz (John Doe)" (b), or
* - "John (zzz) Doe <john.doe@xz> (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);
Expand Down
2 changes: 1 addition & 1 deletion t/t5100/info0001
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion t/t5100/rfc2047-info-0004
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Author: Nathaniel Borenstein (םולש ןב ילטפנ)
Author: Nathaniel Borenstein (םולש ןב ילטפנ)
Email: nsb@thumper.bellcore.com
Subject: Test of new header generator

4 changes: 2 additions & 2 deletions t/t5100/sample.mbox
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@


From nobody Mon Sep 17 00:00:00 2001
From: A
From: A (zzz)
U
Thor
<a.u.thor@example.com>
<a.u.thor@example.com> (Comment)
Date: Fri, 9 Jun 2006 00:44:16 -0700
Subject: [PATCH] a commit.

Expand Down

0 comments on commit 08e6710

Please sign in to comment.