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 C938E4196F2 for ; Wed, 21 Apr 2010 22:04:41 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -4.2 X-Spam-Level: X-Spam-Status: No, score=-4.2 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3] 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 n3q5qp4yKwbT for ; Wed, 21 Apr 2010 22:04:40 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34]) by olra.theworths.org (Postfix) with ESMTP id 94394431FC1 for ; Wed, 21 Apr 2010 22:04:40 -0700 (PDT) Received: from localhost ([::1] helo=x200.gr8dns.org) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1O4oae-0001Wr-4D for notmuch@notmuchmail.org; Thu, 22 Apr 2010 05:04:40 +0000 Received: by x200.gr8dns.org (Postfix, from userid 500) id 7B4A9C0214; Wed, 21 Apr 2010 22:04:39 -0700 (PDT) From: Dirk Hohndel To: notmuch Subject: [PATCH] Clean up author display for some "Last, First" cases Date: Wed, 21 Apr 2010 22:04:39 -0700 Message-ID: User-Agent: notmuch 0.2-52-ga28d2fe (Emacs 23.1.1/i386-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org See http://www.infradead.org/rpr.html 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: Thu, 22 Apr 2010 05:04:41 -0000 We specifically check if this is one of these two patterns: "Last, First" "Last, First MI" If this is the case, we rewrite the author name in a more reader friendly manner Signed-off-by: Dirk Hohndel --- lib/thread.cc | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 49 insertions(+), 2 deletions(-) diff --git a/lib/thread.cc b/lib/thread.cc index baa0d7f..7e72114 100644 --- a/lib/thread.cc +++ b/lib/thread.cc @@ -144,6 +144,51 @@ _thread_move_matched_author (notmuch_thread_t *thread, return; } +/* 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" + * "Last, First MI" + */ +char * +_thread_cleanup_author (notmuch_thread_t *thread, + const char *author, const char *from) +{ + char *cleanauthor,*testauthor; + const char *comma; + char *blank; + int fname,lname; + + cleanauthor = talloc_strdup(thread, author); + if (cleanauthor == NULL) + return NULL; + comma = strchr(author,','); + if (comma) { + /* 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'; + /* make a temporary copy and see if it matches the email */ + testauthor = xstrdup(cleanauthor); + + blank=strchr(testauthor,' '); + while (blank != NULL) { + *blank = '.'; + blank=strchr(testauthor,' '); + } + if (strcasestr(from, testauthor) == NULL) + /* we didn't identify this as part of the email address + * so let's punt and return the original author */ + strcpy (cleanauthor, author); + + } + return cleanauthor; +} + /* Add 'message' as a message that belongs to 'thread'. * * The 'thread' will talloc_steal the 'message' and hold onto a @@ -158,6 +203,7 @@ _thread_add_message (notmuch_thread_t *thread, InternetAddressList *list; InternetAddress *address; const char *from, *author; + char *cleanauthor; _notmuch_message_list_add_message (thread->message_list, talloc_steal (thread, message)); @@ -178,8 +224,9 @@ _thread_add_message (notmuch_thread_t *thread, mailbox = INTERNET_ADDRESS_MAILBOX (address); author = internet_address_mailbox_get_addr (mailbox); } - _thread_add_author (thread, author); - notmuch_message_set_author (message, author); + cleanauthor = _thread_cleanup_author (thread, author, from); + _thread_add_author (thread, cleanauthor); + notmuch_message_set_author (message, cleanauthor); } g_object_unref (G_OBJECT (list)); } -- 1.6.6.1 -- Dirk Hohndel Intel Open Source Technology Center