[PATCH] Reordering of thread authors to list matching authors first
authorDirk Hohndel <hohndel@infradead.org>
Thu, 22 Apr 2010 03:58:27 +0000 (20:58 +1700)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:36:46 +0000 (09:36 -0800)
a5/927047658ff59ba92a76ec20946afcf3f7f668 [new file with mode: 0644]

diff --git a/a5/927047658ff59ba92a76ec20946afcf3f7f668 b/a5/927047658ff59ba92a76ec20946afcf3f7f668
new file mode 100644 (file)
index 0000000..2e8ebef
--- /dev/null
@@ -0,0 +1,259 @@
+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 294294196F2\r
+       for <notmuch@notmuchmail.org>; Wed, 21 Apr 2010 20:58:31 -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 LH20GX3chCfC for <notmuch@notmuchmail.org>;\r
+       Wed, 21 Apr 2010 20:58:29 -0700 (PDT)\r
+Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34])\r
+       by olra.theworths.org (Postfix) with ESMTP id 70A3A431FC1\r
+       for <notmuch@notmuchmail.org>; Wed, 21 Apr 2010 20:58:29 -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 1O4nYa-00036z-EV\r
+       for notmuch@notmuchmail.org; Thu, 22 Apr 2010 03:58:28 +0000\r
+Received: by x200.gr8dns.org (Postfix, from userid 500)\r
+       id EF0B0C0212; Wed, 21 Apr 2010 20:58:27 -0700 (PDT)\r
+From: Dirk Hohndel <hohndel@infradead.org>\r
+To: notmuch <notmuch@notmuchmail.org>\r
+Subject: [PATCH] Reordering of thread authors to list matching authors first\r
+In-Reply-To: <m3aaswyw9t.fsf@x200.gr8dns.org>\r
+References: <m31veru7vn.fsf@x200.gr8dns.org> <87zl1d5fc0.fsf@steelpick.2x.cz>\r
+       <m3zl1cfsb4.fsf@x200.gr8dns.org>\r
+       <87aatcysw8.fsf@wsheee.localdomain>\r
+       <m3wrwg6n9y.fsf@x200.gr8dns.org> <m3aaswyw9t.fsf@x200.gr8dns.org>\r
+Date: Wed, 21 Apr 2010 20:58:27 -0700\r
+Message-ID: <m38w8gyw7w.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 03:58:31 -0000\r
+\r
+\r
+When displaying threads as result of a search it makes sense to list those\r
+authors first who match the search. The matching authors are separated from the\r
+non-matching ones with a '|' instead of a ','\r
+\r
+Imagine the default "+inbox" query. Those mails in the thread that\r
+match the query are actually "new" (whatever that means). And some\r
+people seem to think that it would be much better to see those author\r
+names first. For example, imagine a long and drawn out thread that once\r
+was started by me; you have long read the older part of the thread and\r
+removed the inbox tag. Whenever a new email comes in on this thread,\r
+prior to this patch the author column in the search display will first show\r
+"Dirk Hohndel" - I think it should first show the actual author(s) of the new\r
+mail(s).\r
+\r
+Signed-off-by: Dirk Hohndel <hohndel@infradead.org>\r
+---\r
+ lib/message.cc |   16 ++++++++++++\r
+ lib/notmuch.h  |   11 ++++++++\r
+ lib/thread.cc  |   74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ 3 files changed, 101 insertions(+), 0 deletions(-)\r
+\r
+diff --git a/lib/message.cc b/lib/message.cc\r
+index 721c9a6..ac0afd9 100644\r
+--- a/lib/message.cc\r
++++ b/lib/message.cc\r
+@@ -35,6 +35,7 @@ struct _notmuch_message {\r
+     char *thread_id;\r
+     char *in_reply_to;\r
+     char *filename;\r
++    char *author;\r
+     notmuch_message_file_t *message_file;\r
+     notmuch_message_list_t *replies;\r
+     unsigned long flags;\r
+@@ -110,6 +111,7 @@ _notmuch_message_create (const void *talloc_owner,\r
+     message->in_reply_to = NULL;\r
+     message->filename = NULL;\r
+     message->message_file = NULL;\r
++    message->author = NULL;\r
\r
+     message->replies = _notmuch_message_list_create (message);\r
+     if (unlikely (message->replies == NULL)) {\r
+@@ -533,6 +535,20 @@ notmuch_message_get_tags (notmuch_message_t *message)\r
+     return _notmuch_convert_tags(message, i, end);\r
+ }\r
\r
++const char *\r
++notmuch_message_get_author (notmuch_message_t *message)\r
++{\r
++    return message->author;\r
++}\r
++\r
++void\r
++notmuch_message_set_author (notmuch_message_t *message,\r
++                          const char *author)\r
++{\r
++    message->author = talloc_strdup(message, author);\r
++    return;\r
++}\r
++\r
+ void\r
+ _notmuch_message_set_date (notmuch_message_t *message,\r
+                          const char *date)\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index bae48a6..769f747 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -773,6 +773,17 @@ notmuch_message_set_flag (notmuch_message_t *message,\r
+ time_t\r
+ notmuch_message_get_date  (notmuch_message_t *message);\r
\r
++/* Set the author member of 'message' - this is the representation used\r
++ * when displaying the message\r
++ */\r
++void\r
++notmuch_message_set_author (notmuch_message_t *message, const char *author);\r
++\r
++/* Get the author member of 'message'\r
++ */\r
++const char *\r
++notmuch_message_get_author (notmuch_message_t *message);\r
++\r
+ /* Get the value of the specified header from 'message'.\r
+  *\r
+  * The value will be read from the actual message file, not from the\r
+diff --git a/lib/thread.cc b/lib/thread.cc\r
+index e514bf8..baa0d7f 100644\r
+--- a/lib/thread.cc\r
++++ b/lib/thread.cc\r
+@@ -32,6 +32,7 @@ struct _notmuch_thread {\r
+     char *subject;\r
+     GHashTable *authors_hash;\r
+     char *authors;\r
++    char *nonmatched_authors;\r
+     GHashTable *tags;\r
\r
+     notmuch_message_list_t *message_list;\r
+@@ -73,6 +74,76 @@ _thread_add_author (notmuch_thread_t *thread,\r
+       thread->authors = talloc_strdup (thread, author);\r
+ }\r
\r
++/*\r
++ * move authors of matched messages in the thread to \r
++ * the front of the authors list, but keep them in\r
++ * existing order within their group\r
++ */\r
++static void\r
++_thread_move_matched_author (notmuch_thread_t *thread,\r
++                           const char *author)\r
++{\r
++    char *authorscopy;\r
++    char *currentauthor;\r
++    char *lastpipe,*nextpipe;\r
++    int idx,nmstart,author_len,authors_len;\r
++\r
++    if (thread->authors == NULL || author == NULL)\r
++      return;\r
++    if (thread->nonmatched_authors == NULL)\r
++      thread->nonmatched_authors = thread->authors;\r
++    author_len = strlen(author);\r
++    authors_len = strlen(thread->authors);\r
++    if (author_len == authors_len) {\r
++      /* just one author */\r
++      thread->nonmatched_authors += author_len;\r
++      return;\r
++    }\r
++    currentauthor = strcasestr(thread->authors, author);\r
++    if (currentauthor == NULL)\r
++      return;\r
++    /* how far inside the nonmatched authors is our author? */\r
++    idx = currentauthor - thread->nonmatched_authors;\r
++    if (idx < 0) {\r
++      /* already among matched authors */\r
++      return;\r
++    }\r
++    /* are there any authors in the list after our author? */\r
++    if (thread->nonmatched_authors + author_len < thread->authors + authors_len) {\r
++      /* we have to make changes, so let's get a temp copy */\r
++      authorscopy = xstrdup(thread->authors);\r
++      /* nmstart is the offset into where the non-matched authors start */\r
++      nmstart = thread->nonmatched_authors - thread->authors;\r
++      /* copy this author and add the "| " - the if clause above tells us there's more */\r
++      strncpy(thread->nonmatched_authors,author,author_len);\r
++      strncpy(thread->nonmatched_authors+author_len,"| ",2);\r
++      thread->nonmatched_authors += author_len+2;     \r
++      if (idx > 0) {\r
++        /* we are actually moving authors around, not just changing the separator\r
++         * first copy the authors that came BEFORE our author */\r
++        strncpy(thread->nonmatched_authors, authorscopy+nmstart, idx-2);\r
++        /* finally, if there are authors AFTER our author, copy those */\r
++        if(author_len+nmstart+idx < authors_len) {\r
++          strncpy(thread->nonmatched_authors + idx - 2,", ",2);\r
++          strncpy(thread->nonmatched_authors + idx, authorscopy+nmstart + idx + author_len + 2, \r
++                  authors_len - (nmstart + idx + author_len + 2));\r
++        }\r
++      }\r
++      free(authorscopy);\r
++      /* finally let's make sure there's just one '|' in the authors string */\r
++      lastpipe = strchr(thread->authors,'|');\r
++      while (lastpipe) {\r
++          nextpipe = strchr(lastpipe+1,'|');\r
++          if (nextpipe)\r
++              *lastpipe = ',';\r
++          lastpipe = nextpipe;\r
++      }\r
++    } else {\r
++      thread->nonmatched_authors += author_len;\r
++    }\r
++    return;\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
+@@ -108,6 +179,7 @@ _thread_add_message (notmuch_thread_t *thread,\r
+               author = internet_address_mailbox_get_addr (mailbox);\r
+           }\r
+           _thread_add_author (thread, author);\r
++          notmuch_message_set_author (message, author);\r
+       }\r
+       g_object_unref (G_OBJECT (list));\r
+     }\r
+@@ -162,6 +234,7 @@ _thread_add_matched_message (notmuch_thread_t *thread,\r
+       notmuch_message_set_flag (hashed_message,\r
+                                 NOTMUCH_MESSAGE_FLAG_MATCH, 1);\r
+     }\r
++    _thread_move_matched_author (thread,notmuch_message_get_author(hashed_message));\r
+ }\r
\r
+ static void\r
+@@ -283,6 +356,7 @@ _notmuch_thread_create (void *ctx,\r
+     thread->authors_hash = g_hash_table_new_full (g_str_hash, g_str_equal,\r
+                                                 free, NULL);\r
+     thread->authors = NULL;\r
++    thread->nonmatched_authors = NULL;\r
+     thread->tags = g_hash_table_new_full (g_str_hash, g_str_equal,\r
+                                         free, NULL);\r
\r
+-- \r
+1.6.6.1\r
+\r
+\r
+-- \r
+Dirk Hohndel\r
+Intel Open Source Technology Center\r