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 52E7A4196F5 for ; Sat, 24 Apr 2010 11:21:21 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -1.9 X-Spam-Level: X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5 tests=[BAYES_00=-1.9] 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 eeqOwvzLE3W5 for ; Sat, 24 Apr 2010 11:21:19 -0700 (PDT) Received: from mail.hohndel.org (mail.hohndel.org [65.23.157.147]) by olra.theworths.org (Postfix) with ESMTP id D0950418C36 for ; Sat, 24 Apr 2010 11:21:15 -0700 (PDT) Received: by mail.hohndel.org (Postfix, from userid 112) id 89A08340FA; Sat, 24 Apr 2010 14:21:15 -0400 (EDT) Received: from x200.gr8dns.org (unknown [65.23.157.147]) by mail.hohndel.org (Postfix) with ESMTP id C117D340FE; Sat, 24 Apr 2010 14:21:01 -0400 (EDT) Received: by x200.gr8dns.org (Postfix, from userid 500) id 1CD92CC5A0; Sat, 24 Apr 2010 11:21:01 -0700 (PDT) From: Dirk Hohndel To: Subject: [PATCH 5/5] Simple attempt to display author names in a friendlier way Date: Sat, 24 Apr 2010 11:20:57 -0700 Message-Id: <1272133257-15708-6-git-send-email-hohndel@infradead.org> X-Mailer: git-send-email 1.6.6.1 In-Reply-To: <1272133257-15708-5-git-send-email-hohndel@infradead.org> References: <1272133257-15708-1-git-send-email-hohndel@infradead.org> <1272133257-15708-2-git-send-email-hohndel@infradead.org> <1272133257-15708-3-git-send-email-hohndel@infradead.org> <1272133257-15708-4-git-send-email-hohndel@infradead.org> <1272133257-15708-5-git-send-email-hohndel@infradead.org> 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 18:21:22 -0000 This patch only addresses the typical Outlook/Exchange case where we have "Last, First" or "Last, First MI" . In the future we should be more fexible as to the formats we recognize, but for now we address this one as it is the Exchange default setting and therefore the most common one. 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 c80bb26..b8be3e1 100644 --- a/lib/thread.cc +++ b/lib/thread.cc @@ -147,6 +147,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 *clean_author,*test_author; + const char *comma; + char *blank; + int fname,lname; + + clean_author = talloc_strdup(thread, author); + if (clean_author == 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(clean_author, comma + 2, fname); + *(clean_author+fname) = ' '; + strncpy(clean_author + fname + 1, author, lname); + *(clean_author+fname+1+lname) = '\0'; + /* make a temporary copy and see if it matches the email */ + test_author = talloc_strdup(thread,clean_author); + + blank=strchr(test_author,' '); + while (blank != NULL) { + *blank = '.'; + blank=strchr(test_author,' '); + } + if (strcasestr(from, test_author) == NULL) + /* we didn't identify this as part of the email address + * so let's punt and return the original author */ + strcpy (clean_author, author); + + } + return clean_author; +} + /* Add 'message' as a message that belongs to 'thread'. * * The 'thread' will talloc_steal the 'message' and hold onto a @@ -161,6 +206,7 @@ _thread_add_message (notmuch_thread_t *thread, InternetAddressList *list = NULL; InternetAddress *address; const char *from, *author; + char *clean_author; _notmuch_message_list_add_message (thread->message_list, talloc_steal (thread, message)); @@ -183,8 +229,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); + clean_author = _thread_cleanup_author (thread, author, from); + _thread_add_author (thread, clean_author); + notmuch_message_set_author (message, clean_author); } g_object_unref (G_OBJECT (list)); } -- 1.6.6.1