]> git.notmuchmail.org Git - notmuch/blobdiff - lib/thread.cc
lib: break reference loop by choosing arbitrary top level msg
[notmuch] / lib / thread.cc
index 3561b27f743976d2c2d1918d33fc2a8d33469c74..dbac002fd7130c4c7559dcf96fbb9b90bdab2487 100644 (file)
@@ -397,7 +397,13 @@ _resolve_thread_relationships (notmuch_thread_t *thread)
     for (node = thread->message_list->head; node; node = node->next) {
        message = node->message;
        in_reply_to = _notmuch_message_get_in_reply_to (message);
-       if (in_reply_to && strlen (in_reply_to) &&
+       /*
+        * 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) &&
            g_hash_table_lookup_extended (thread->message_hash,
                                          in_reply_to, NULL,
                                          (void **) &parent))