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 C13F66DE0240 for ; Fri, 20 Jul 2018 16:38:56 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.001 X-Spam-Level: X-Spam-Status: No, score=-0.001 tagged_above=-999 required=5 tests=[AWL=0.010, 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 0pddRh0SzsJ3 for ; Fri, 20 Jul 2018 16:38:55 -0700 (PDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id 2874B6DE026B for ; Fri, 20 Jul 2018 16:38:51 -0700 (PDT) Received: from remotemail by fethera.tethera.net with local (Exim 4.89) (envelope-from ) id 1fgez4-00026d-9J; Fri, 20 Jul 2018 19:38:50 -0400 Received: (nullmailer pid 2982 invoked by uid 1000); Fri, 20 Jul 2018 23:37:52 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 7/9] lib: calculate message depth in thread Date: Sat, 21 Jul 2018 08:37:44 +0900 Message-Id: <20180720233746.2844-8-david@tethera.net> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180720233746.2844-1-david@tethera.net> References: <20180720233746.2844-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 Jul 2018 23:38:56 -0000 This will be used in reparenting messages without useful in-reply-to, but with useful references --- lib/message.cc | 23 +++++++++++++++++++++++ lib/notmuch-private.h | 5 +++++ 2 files changed, 28 insertions(+) diff --git a/lib/message.cc b/lib/message.cc index 790d26f5..1567f14b 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -32,6 +32,7 @@ struct _notmuch_message { int frozen; char *message_id; char *thread_id; + size_t thread_depth; char *in_reply_to; notmuch_string_list_t *tag_list; notmuch_string_list_t *filename_term_list; @@ -118,6 +119,9 @@ _notmuch_message_create_for_document (const void *talloc_owner, /* the message is initially not synchronized with Xapian */ message->last_view = 0; + /* Calculated after the thread structure is computed */ + message->thread_depth = 0; + /* Each of these will be lazily created as needed. */ message->message_id = NULL; message->thread_id = NULL; @@ -599,6 +603,25 @@ _notmuch_message_add_reply (notmuch_message_t *message, _notmuch_message_list_add_message (message->replies, reply); } +size_t +_notmuch_message_get_thread_depth (notmuch_message_t *message) { + return message->thread_depth; +} + +void +_notmuch_message_label_depths (notmuch_message_t *message, + size_t depth) +{ + message->thread_depth = depth; + + for (notmuch_messages_t *messages = _notmuch_messages_create (message->replies); + notmuch_messages_valid (messages); + notmuch_messages_move_to_next (messages)) { + notmuch_message_t *child = notmuch_messages_get (messages); + _notmuch_message_label_depths (child, depth+1); + } +} + const notmuch_string_list_t * _notmuch_message_get_references (notmuch_message_t *message) { diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h index e7bbc156..385cf7a5 100644 --- a/lib/notmuch-private.h +++ b/lib/notmuch-private.h @@ -539,6 +539,11 @@ _notmuch_message_remove_unprefixed_terms (notmuch_message_t *message); const char * _notmuch_message_get_thread_id_only(notmuch_message_t *message); +size_t _notmuch_message_get_thread_depth (notmuch_message_t *message); + +void +_notmuch_message_label_depths (notmuch_message_t *message, + size_t depth); /* sha1.c */ char * -- 2.18.0