Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 9E5F74196F2 for ; Sat, 24 Apr 2010 08:30:23 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -2.89 X-Spam-Level: X-Spam-Status: No, score=-2.89 tagged_above=-999 required=5 tests=[ALL_TRUSTED=-1, BAYES_00=-1.9, T_MIME_NO_TEXT=0.01] autolearn=ham Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zax3JtkQ3MKv; Sat, 24 Apr 2010 08:30:22 -0700 (PDT) Received: from yoom.home.cworth.org (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 7E68E431FC1; Sat, 24 Apr 2010 08:30:22 -0700 (PDT) Received: by yoom.home.cworth.org (Postfix, from userid 1000) id 2D45E568DEC; Sat, 24 Apr 2010 08:30:22 -0700 (PDT) From: Carl Worth To: Dirk Hohndel , notmuch Subject: Re: [PATCH] Clean up author display for some "Last, First" cases In-Reply-To: References: User-Agent: Notmuch/0.2-188-g9757095 (http://notmuchmail.org) Emacs/23.1.1 (i486-pc-linux-gnu) Date: Sat, 24 Apr 2010 08:30:22 -0700 Message-ID: <87mxwshnqp.fsf@yoom.home.cworth.org> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 Apr 2010 15:30:23 -0000 --=-=-= Content-Transfer-Encoding: quoted-printable On Wed, 21 Apr 2010 22:04:39 -0700, Dirk Hohndel wr= ote: > +/* clean up the uggly "Lastname, Firstname" format that some mail systems > + * (most notably, Exchange) are creating to be "Firstname Lastname"=20 > + * To make sure that we don't change other potential situations where a= =20 > + * comma is in the name, we check that we match one of these patterns > + * "Last, First" > + * "Last, First MI" 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 =3D comma - author; > + fname =3D strlen(author) - lname - 2; > + strncpy(cleanauthor, comma + 2, fname); > + *(cleanauthor+fname) =3D ' '; > + strncpy(cleanauthor + fname + 1, author, lname); > + *(cleanauthor+fname+1+lname) =3D '\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 =3D 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. =2DCarl --=-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iD8DBQFL0w6O6JDdNq8qSWgRAjn0AJ99uMKCZiebcaR5Z9iZ2C+xgPbgWgCgonzU EUZRUe/OixCkPORuRUXLJBE= =lQPx -----END PGP SIGNATURE----- --=-=-=--