--- /dev/null
+Return-Path: <BATV+bbc4756b788e67be553a+2433+infradead.org+hohndel@bombadil.srs.infradead.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id C938E4196F2\r
+ for <notmuch@notmuchmail.org>; Wed, 21 Apr 2010 22:04:41 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -4.2\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-4.2 tagged_above=-999 required=5\r
+ tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3] autolearn=ham\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id n3q5qp4yKwbT for <notmuch@notmuchmail.org>;\r
+ Wed, 21 Apr 2010 22:04:40 -0700 (PDT)\r
+Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34])\r
+ by olra.theworths.org (Postfix) with ESMTP id 94394431FC1\r
+ for <notmuch@notmuchmail.org>; Wed, 21 Apr 2010 22:04:40 -0700 (PDT)\r
+Received: from localhost ([::1] helo=x200.gr8dns.org)\r
+ by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux))\r
+ id 1O4oae-0001Wr-4D\r
+ for notmuch@notmuchmail.org; Thu, 22 Apr 2010 05:04:40 +0000\r
+Received: by x200.gr8dns.org (Postfix, from userid 500)\r
+ id 7B4A9C0214; Wed, 21 Apr 2010 22:04:39 -0700 (PDT)\r
+From: Dirk Hohndel <hohndel@infradead.org>\r
+To: notmuch <notmuch@notmuchmail.org>\r
+Subject: [PATCH] Clean up author display for some "Last, First" cases\r
+Date: Wed, 21 Apr 2010 22:04:39 -0700\r
+Message-ID: <m3633kyt5k.fsf@x200.gr8dns.org>\r
+User-Agent: notmuch 0.2-52-ga28d2fe (Emacs 23.1.1/i386-redhat-linux-gnu)\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-SRS-Rewrite: SMTP reverse-path rewritten from <hohndel@infradead.org> by\r
+ bombadil.infradead.org See http://www.infradead.org/rpr.html\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 22 Apr 2010 05:04:41 -0000\r
+\r
+\r
+We specifically check if this is one of these two patterns:\r
+ "Last, First" <first.last@company.com>\r
+ "Last, First MI" <first.mi.last@company.com>\r
+If this is the case, we rewrite the author name in a more\r
+reader friendly manner\r
+\r
+Signed-off-by: Dirk Hohndel <hohndel@infradead.org>\r
+---\r
+ lib/thread.cc | 51 +++++++++++++++++++++++++++++++++++++++++++++++++--\r
+ 1 files changed, 49 insertions(+), 2 deletions(-)\r
+\r
+diff --git a/lib/thread.cc b/lib/thread.cc\r
+index baa0d7f..7e72114 100644\r
+--- a/lib/thread.cc\r
++++ b/lib/thread.cc\r
+@@ -144,6 +144,51 @@ _thread_move_matched_author (notmuch_thread_t *thread,\r
+ return;\r
+ }\r
+ \r
++/* clean up the uggly "Lastname, Firstname" format that some mail systems\r
++ * (most notably, Exchange) are creating to be "Firstname Lastname" \r
++ * To make sure that we don't change other potential situations where a \r
++ * comma is in the name, we check that we match one of these patterns\r
++ * "Last, First" <first.last@company.com>\r
++ * "Last, First MI" <first.mi.last@company.com>\r
++ */\r
++char *\r
++_thread_cleanup_author (notmuch_thread_t *thread,\r
++ const char *author, const char *from)\r
++{\r
++ char *cleanauthor,*testauthor;\r
++ const char *comma;\r
++ char *blank;\r
++ int fname,lname;\r
++\r
++ cleanauthor = talloc_strdup(thread, author);\r
++ if (cleanauthor == NULL)\r
++ return NULL;\r
++ comma = strchr(author,',');\r
++ if (comma) {\r
++ /* let's assemble what we think is the correct name */\r
++ lname = comma - author;\r
++ fname = strlen(author) - lname - 2;\r
++ strncpy(cleanauthor, comma + 2, fname);\r
++ *(cleanauthor+fname) = ' ';\r
++ strncpy(cleanauthor + fname + 1, author, lname);\r
++ *(cleanauthor+fname+1+lname) = '\0';\r
++ /* make a temporary copy and see if it matches the email */\r
++ testauthor = xstrdup(cleanauthor);\r
++ \r
++ blank=strchr(testauthor,' ');\r
++ while (blank != NULL) {\r
++ *blank = '.';\r
++ blank=strchr(testauthor,' ');\r
++ }\r
++ if (strcasestr(from, testauthor) == NULL)\r
++ /* we didn't identify this as part of the email address \r
++ * so let's punt and return the original author */\r
++ strcpy (cleanauthor, author);\r
++ \r
++ }\r
++ return cleanauthor;\r
++}\r
++\r
+ /* Add 'message' as a message that belongs to 'thread'.\r
+ *\r
+ * The 'thread' will talloc_steal the 'message' and hold onto a\r
+@@ -158,6 +203,7 @@ _thread_add_message (notmuch_thread_t *thread,\r
+ InternetAddressList *list;\r
+ InternetAddress *address;\r
+ const char *from, *author;\r
++ char *cleanauthor;\r
+ \r
+ _notmuch_message_list_add_message (thread->message_list,\r
+ talloc_steal (thread, message));\r
+@@ -178,8 +224,9 @@ _thread_add_message (notmuch_thread_t *thread,\r
+ mailbox = INTERNET_ADDRESS_MAILBOX (address);\r
+ author = internet_address_mailbox_get_addr (mailbox);\r
+ }\r
+- _thread_add_author (thread, author);\r
+- notmuch_message_set_author (message, author);\r
++ cleanauthor = _thread_cleanup_author (thread, author, from);\r
++ _thread_add_author (thread, cleanauthor);\r
++ notmuch_message_set_author (message, cleanauthor);\r
+ }\r
+ g_object_unref (G_OBJECT (list));\r
+ }\r
+-- \r
+1.6.6.1\r
+\r
+\r
+-- \r
+Dirk Hohndel\r
+Intel Open Source Technology Center\r