From 646274b2d455dde7d336c5aab3c2db7fee773e70 Mon Sep 17 00:00:00 2001 From: Jesse Rosenthal Date: Thu, 30 Oct 2014 16:51:43 +2000 Subject: [PATCH] [v2 1/3] thread.cc: Avoid empty thread names if possible. --- a6/d8113c89ffe795dcb8987e34fdecac41822c19 | 118 ++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 a6/d8113c89ffe795dcb8987e34fdecac41822c19 diff --git a/a6/d8113c89ffe795dcb8987e34fdecac41822c19 b/a6/d8113c89ffe795dcb8987e34fdecac41822c19 new file mode 100644 index 000000000..14d1774f3 --- /dev/null +++ b/a6/d8113c89ffe795dcb8987e34fdecac41822c19 @@ -0,0 +1,118 @@ +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 1A9DA431FC2 + for ; Wed, 29 Oct 2014 13:52:20 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -2.3 +X-Spam-Level: +X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled +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 oO6o5cdHs9XU for ; + Wed, 29 Oct 2014 13:52:12 -0700 (PDT) +Received: from smtpauth.johnshopkins.edu (smtpauth.johnshopkins.edu + [162.129.8.200]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 5242D431FB6 + for ; Wed, 29 Oct 2014 13:52:12 -0700 (PDT) +X-IronPort-AV: E=Sophos;i="5.07,279,1413259200"; d="scan'208";a="437698602" +Received: from guppy.hwcampus.jhu.edu (HELO localhost) ([10.161.32.234]) + by ipex1.johnshopkins.edu with ESMTP/TLS/AES128-SHA; + 29 Oct 2014 16:52:10 -0400 +From: Jesse Rosenthal +To: notmuch@notmuchmail.org +Subject: [v2 1/3] thread.cc: Avoid empty thread names if possible. +Date: Wed, 29 Oct 2014 16:51:43 -0400 +Message-Id: <1414615905-22554-2-git-send-email-jrosenthal@jhu.edu> +X-Mailer: git-send-email 2.1.2 +In-Reply-To: <1414615905-22554-1-git-send-email-jrosenthal@jhu.edu> +References: <1414615905-22554-1-git-send-email-jrosenthal@jhu.edu> +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: Wed, 29 Oct 2014 20:52:20 -0000 + +Currently the thread is named based on either the oldest or newest +matching message (depending on the search order). If this message has +an empty subject, though, the thread will show up with an empty +subject in the search results. (See the thread starting with +`id:1412371140-21051-1-git-send-email-david@tethera.net` for an +example.) + +This changes the behavior so it will use a non-empty name for the +thread if possible. We name threads based on (a) non-empty matches for +the query, and (b) the search order. If the search order is +oldest-first (as in the default inbox) it chooses the oldest matching +non-empty message as the subject. If the search order is newest-first +it chooses the newest one. +--- + lib/thread.cc | 16 +++++++++++----- + 1 file changed, 11 insertions(+), 5 deletions(-) + +diff --git a/lib/thread.cc b/lib/thread.cc +index 8922403..267f351 100644 +--- a/lib/thread.cc ++++ b/lib/thread.cc +@@ -24,6 +24,8 @@ + #include + #include /* GHashTable */ + ++#define EMPTY_STRING(s) ((s)[0] == '\0') ++ + struct visible _notmuch_thread { + notmuch_database_t *notmuch; + char *thread_id; +@@ -330,11 +332,13 @@ _thread_set_subject_from_message (notmuch_thread_t *thread, + } else { + cleaned_subject = talloc_strdup (thread, subject); + } ++ ++ if (! EMPTY_STRING(cleaned_subject)) { ++ if (thread->subject) ++ talloc_free (thread->subject); + +- if (thread->subject) +- talloc_free (thread->subject); +- +- thread->subject = talloc_strdup (thread, cleaned_subject); ++ thread->subject = talloc_strdup (thread, cleaned_subject); ++ } + } + + /* Add a message to this thread which is known to match the original +@@ -348,8 +352,10 @@ _thread_add_matched_message (notmuch_thread_t *thread, + { + time_t date; + notmuch_message_t *hashed_message; ++ const char *cur_subject; + + date = notmuch_message_get_date (message); ++ cur_subject = notmuch_thread_get_subject(thread); + + if (date < thread->oldest || ! thread->matched_messages) { + thread->oldest = date; +@@ -359,7 +365,7 @@ _thread_add_matched_message (notmuch_thread_t *thread, + + if (date > thread->newest || ! thread->matched_messages) { + thread->newest = date; +- if (sort != NOTMUCH_SORT_OLDEST_FIRST) ++ if (sort != NOTMUCH_SORT_OLDEST_FIRST || EMPTY_STRING(cur_subject)) + _thread_set_subject_from_message (thread, message); + } + +-- +2.1.2 + -- 2.26.2