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 273886DE0361 for ; Fri, 21 Jul 2017 03:59:03 -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 AY82jJJ-0hmx for ; Fri, 21 Jul 2017 03:59:02 -0700 (PDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id 40B1D6DE00DB for ; Fri, 21 Jul 2017 03:58:55 -0700 (PDT) Received: from remotemail by fethera.tethera.net with local (Exim 4.84_2) (envelope-from ) id 1dYVan-0002yk-Pr; Fri, 21 Jul 2017 06:55:33 -0400 Received: (nullmailer pid 4910 invoked by uid 1000); Fri, 21 Jul 2017 10:58:47 -0000 From: David Bremner To: notmuch@notmuchmail.org, notmuch@freelists.org Subject: [Patch v4 07/12] lib: add notmuch_message_count_files Date: Fri, 21 Jul 2017 07:58:35 -0300 Message-Id: <20170721105840.4737-8-david@tethera.net> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170721105840.4737-1-david@tethera.net> References: <20170721105840.4737-1-david@tethera.net> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.23 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, 21 Jul 2017 10:59:03 -0000 This operation is relatively inexpensive, as the needed metadata is already computed by our lazy metadata fetching. The goal is to support better UI for messages with multipile files. --- lib/message.cc | 8 ++++++++ lib/notmuch-private.h | 6 ++++++ lib/notmuch.h | 8 ++++++++ lib/string-list.c | 6 ++++++ 4 files changed, 28 insertions(+) diff --git a/lib/message.cc b/lib/message.cc index f78e5a9d..68c02001 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -946,6 +946,14 @@ notmuch_message_get_filenames (notmuch_message_t *message) return _notmuch_filenames_create (message, message->filename_list); } +int +notmuch_message_count_files (notmuch_message_t *message) +{ + _notmuch_message_ensure_filename_list (message); + + return _notmuch_string_list_length (message->filename_list); +} + notmuch_bool_t notmuch_message_get_flag (notmuch_message_t *message, notmuch_message_flag_t flag) diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h index 57c61639..544788bc 100644 --- a/lib/notmuch-private.h +++ b/lib/notmuch-private.h @@ -550,6 +550,12 @@ typedef struct _notmuch_string_list { notmuch_string_list_t * _notmuch_string_list_create (const void *ctx); +/* + * return the number of strings in 'list' + */ +int +_notmuch_string_list_length (notmuch_string_list_t *list); + /* Add 'string' to 'list'. * * The list will create its own talloced copy of 'string'. diff --git a/lib/notmuch.h b/lib/notmuch.h index 17f0872e..f5018497 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -1342,6 +1342,14 @@ notmuch_messages_t * notmuch_message_get_replies (notmuch_message_t *message); /** + * Get the total number of files associated with a message. + * @returns Non-negative integer + * @since libnotmuch 5.0 (notmuch 0.25) + */ +int +notmuch_message_count_files (notmuch_message_t *message); + +/** * Get a filename for the email corresponding to 'message'. * * The returned filename is an absolute filename, (the initial diff --git a/lib/string-list.c b/lib/string-list.c index 43ebe499..9c3ae7ef 100644 --- a/lib/string-list.c +++ b/lib/string-list.c @@ -42,6 +42,12 @@ _notmuch_string_list_create (const void *ctx) return list; } +int +_notmuch_string_list_length (notmuch_string_list_t *list) +{ + return list->length; +} + void _notmuch_string_list_append (notmuch_string_list_t *list, const char *string) -- 2.13.2