From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id C9F146DE0A7F for ; Fri, 20 Apr 2018 11:32:01 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[AWL=0.011, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id m9wpgdtseRZn for ; Fri, 20 Apr 2018 11:32:01 -0700 (PDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id B1DC66DE0A9A for ; Fri, 20 Apr 2018 11:31:52 -0700 (PDT) Received: from remotemail by fethera.tethera.net with local (Exim 4.89) (envelope-from ) id 1f9ap5-00072B-SC; Fri, 20 Apr 2018 14:31:51 -0400 Received: (nullmailer pid 14519 invoked by uid 1000); Fri, 20 Apr 2018 18:31:45 -0000 From: David Bremner To: notmuch@notmuchmail.org, David Bremner Subject: [PATCH 6/6] lib: choose oldest message when breaking reference loops Date: Fri, 20 Apr 2018 15:31:35 -0300 Message-Id: <20180420183135.14331-7-david@tethera.net> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180420183135.14331-1-david@tethera.net> References: <20180414014610.15438-6-david@tethera.net> <20180420183135.14331-1-david@tethera.net> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.26 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: Fri, 20 Apr 2018 18:32:02 -0000 This preserves a sensible thread order --- lib/thread.cc | 33 ++++++++++++++++++++++++--------- test/T050-new.sh | 1 - 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/lib/thread.cc b/lib/thread.cc index dbac002f..a6dc4e5a 100644 --- a/lib/thread.cc +++ b/lib/thread.cc @@ -390,20 +390,18 @@ _thread_add_matched_message (notmuch_thread_t *thread, static void _resolve_thread_relationships (notmuch_thread_t *thread) { - notmuch_message_node_t *node; + notmuch_message_node_t *node, *first_node; notmuch_message_t *message, *parent; const char *in_reply_to; - for (node = thread->message_list->head; node; node = node->next) { + first_node = thread->message_list->head; + if (!first_node) + return; + + for (node = first_node->next; node; node = node->next) { message = node->message; in_reply_to = _notmuch_message_get_in_reply_to (message); - /* - * if we reach the end of the list without finding a top-level - * message, that means the thread is a cycle (or set of - * cycles) and any message can be considered top-level - */ - if ((thread->toplevel_list->head || node->next) && - in_reply_to && strlen (in_reply_to) && + if (in_reply_to && strlen (in_reply_to) && g_hash_table_lookup_extended (thread->message_hash, in_reply_to, NULL, (void **) &parent)) @@ -412,6 +410,23 @@ _resolve_thread_relationships (notmuch_thread_t *thread) _notmuch_message_list_add_message (thread->toplevel_list, message); } + /* + * if we reach the end of the list without finding a top-level + * message, that means the thread is a cycle (or set of cycles) + * and any message can be considered top-level. Choose the oldest + * message, which happens to be first in our list. + */ + message=first_node->message; + in_reply_to = _notmuch_message_get_in_reply_to (message); + if (thread->toplevel_list->head && + in_reply_to && strlen (in_reply_to) && + g_hash_table_lookup_extended (thread->message_hash, + in_reply_to, NULL, + (void **) &parent)) + _notmuch_message_add_reply (parent, message); + else + _notmuch_message_list_add_message (thread->toplevel_list, message); + /* XXX: After scanning through the entire list looking for parents * via "In-Reply-To", we should do a second pass that looks at the * list of messages IDs in the "References" header instead. (And diff --git a/test/T050-new.sh b/test/T050-new.sh index 320a7646..9025fa7a 100755 --- a/test/T050-new.sh +++ b/test/T050-new.sh @@ -359,7 +359,6 @@ test_begin_subtest "reference loop does not crash" test_expect_code 0 "notmuch show --format=json id:mid-loop-12@example.org id:mid-loop-21@example.org > OUTPUT" test_begin_subtest "reference loop ordered by date" -test_subtest_known_broken threadid=$(notmuch search --output=threads id:mid-loop-12@example.org) notmuch show --format=mbox $threadid | grep '^Date' > OUTPUT cat < EXPECTED -- 2.17.0