Skip to content

Commit 08e6710

Browse files
navytuxgitster
authored andcommitted
mailinfo: cleanup extra spaces for complex 'From:'
currently for cases like From: A U Thor <[email protected]> (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c0f6f67 commit 08e6710

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

builtin-mailinfo.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ static struct strbuf **p_hdr_data, **s_hdr_data;
2929
#define MAX_HDR_PARSED 10
3030
#define MAX_BOUNDARIES 5
3131

32+
static void cleanup_space(struct strbuf *sb);
33+
34+
3235
static void get_sane_name(struct strbuf *out, struct strbuf *name, struct strbuf *email)
3336
{
3437
struct strbuf *src = name;
@@ -109,11 +112,19 @@ static void handle_from(const struct strbuf *from)
109112
strbuf_add(&email, at, el);
110113
strbuf_remove(&f, at - f.buf, el + (at[el] ? 1 : 0));
111114

112-
/* The remainder is name. It could be "John Doe <john.doe@xz>"
113-
* or "john.doe@xz (John Doe)", but we have removed the
114-
* email part, so trim from both ends, possibly removing
115-
* the () pair at the end.
115+
/* The remainder is name. It could be
116+
*
117+
* - "John Doe <john.doe@xz>" (a), or
118+
* - "john.doe@xz (John Doe)" (b), or
119+
* - "John (zzz) Doe <john.doe@xz> (Comment)" (c)
120+
*
121+
* but we have removed the email part, so
122+
*
123+
* - remove extra spaces which could stay after email (case 'c'), and
124+
* - trim from both ends, possibly removing the () pair at the end
125+
* (cases 'a' and 'b').
116126
*/
127+
cleanup_space(&f);
117128
strbuf_trim(&f);
118129
if (f.buf[0] == '(' && f.len && f.buf[f.len - 1] == ')') {
119130
strbuf_remove(&f, 0, 1);

t/t5100/info0001

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Author: A U Thor
1+
Author: A (zzz) U Thor (Comment)
22
33
Subject: a commit.
44
Date: Fri, 9 Jun 2006 00:44:16 -0700

t/t5100/rfc2047-info-0004

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Author: Nathaniel Borenstein (םולש ןב ילטפנ)
1+
Author: Nathaniel Borenstein (םולש ןב ילטפנ)
22
33
Subject: Test of new header generator
44

t/t5100/sample.mbox

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33

44
From nobody Mon Sep 17 00:00:00 2001
5-
From: A
5+
From: A (zzz)
66
U
77
Thor
8-
8+
<[email protected]> (Comment)
99
Date: Fri, 9 Jun 2006 00:44:16 -0700
1010
Subject: [PATCH] a commit.
1111

0 commit comments

Comments
 (0)