[PATCH] Clean up author display for some "Last, First" cases

Dirk Hohndel hohndel at infradead.org
Sat Apr 24 09:57:40 PDT 2010


On Sat, 24 Apr 2010 08:30:22 -0700, Carl Worth <cworth at cworth.org> wrote:
> On Wed, 21 Apr 2010 22:04:39 -0700, Dirk Hohndel <hohndel at infradead.org> wrote:
> > +/* clean up the uggly "Lastname, Firstname" format that some mail systems
> > + * (most notably, Exchange) are creating to be "Firstname Lastname" 
> > + * To make sure that we don't change other potential situations where a 
> > + * comma is in the name, we check that we match one of these patterns
> > + * "Last, First" <first.last at company.com>
> > + * "Last, First MI" <first.mi.last at company.com>
> 
> This is an interesting idea. We could make it a little more flexible by
> doing a regexp comparison of "first.*last" against the email address,
> (perhaps people have email addresses like carl_worth at example.com?)

I'll look into that. We actually had some discussion about this on IRC
and I was thinking of taking this feature to a new level... something
like: 
- by default we show names as they come in (least surprise)
- we offer to reverse Last, First
- we offer to shorten to FirstL
- we offer an alias map
So I could define that mail from "cworth at cworth.org" gets the author
listed as "cworth". Or as CarlW.

> > +    char *cleanauthor,*testauthor;
> 
> I'd much rather see an underscore separating two words in a single
> identifier, (so clean_author, test_author).

Happy to comply to your preferences in the future

> > +	/* let's assemble what we think is the correct name */
> > +	lname = comma - author;
> > +	fname = strlen(author) - lname - 2;
> > +	strncpy(cleanauthor, comma + 2, fname);
> > +	*(cleanauthor+fname) = ' ';
> > +	strncpy(cleanauthor + fname + 1, author, lname);
> > +	*(cleanauthor+fname+1+lname) = '\0';
> 
> The comment above, ("what we think is the correct name"), didn't help me
> understand what the code is doing. And the code is hard enough to follow
> that I could really use some help. Something like:
> 
> /* Break at comma and reverse: "Last, First etc." -> "First Last etc." */

Ok, I'll try to be more explicit in documenting algorithms

> Lots of little additions here and there so plenty of chance for an
> off-by-one. Do we have a test case for this yet?

Nope. Will do.

> > +	/* make a temporary copy and see if it matches the email */
> > +	testauthor = xstrdup(cleanauthor);
> 
> It would be preferable to use talloc functions consistently. (Existing
> occurrences of xstrdup in the code base are for the sake of
> talloc-unfriendly glib data structures like GHashTable.)
> 
> As is, testauthor is leaking.

Oops.

/D


More information about the notmuch mailing list