On Wed, 21 Apr 2010 22:04:39 -0700, Dirk Hohndel <hohndel@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@company.com> > + * "Last, First MI" <first.mi.last@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@example.com?) > + char *cleanauthor,*testauthor; I'd much rather see an underscore separating two words in a single identifier, (so clean_author, test_author). > + /* 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." */ 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? > + /* 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. -Carl