[PATCH 5/5] Simple attempt to display author names in a friendlier way
authorDirk Hohndel <hohndel@infradead.org>
Sat, 24 Apr 2010 18:20:57 +0000 (11:20 +1700)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:36:52 +0000 (09:36 -0800)
a3/a5adf8748250167a84ef5428e1ff71caad14af [new file with mode: 0644]

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