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 84A35429E39 for ; Thu, 2 Feb 2012 09:43:25 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0.201 X-Spam-Level: X-Spam-Status: No, score=0.201 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] 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 cXguDjoPkW+K for ; Thu, 2 Feb 2012 09:43:22 -0800 (PST) Received: from mail-ww0-f45.google.com (mail-ww0-f45.google.com [74.125.82.45]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 2BA11429E3E for ; Thu, 2 Feb 2012 09:43:10 -0800 (PST) Received: by mail-ww0-f45.google.com with SMTP id dt12so2522817wgb.2 for ; Thu, 02 Feb 2012 09:43:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=ft1IahEMhtmHYG7nZwKDqN9UBhvMMgnXonDQYddK1RU=; b=imcmImRnnqaDP+RPiLQzNC7tt0t/L7bl2N+CLnyzWG59w4qaa1/dvcyO6L7/snIKtr i3Qa40lJtFqAsgeQ98+LTahMr9CM971o+Fy94bIPsRTwoBuNCRCl7ntmwIFli8BmjNYZ Ugll8FS+a1+GtA5CzzffbUbt8Ut5hYnwEMd3I= Received: by 10.180.106.33 with SMTP id gr1mr6195411wib.6.1328204589854; Thu, 02 Feb 2012 09:43:09 -0800 (PST) Received: from localhost (94-192-233-223.zone6.bethere.co.uk. [94.192.233.223]) by mx.google.com with ESMTPS id y1sm9134771wiw.6.2012.02.02.09.43.08 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 02 Feb 2012 09:43:09 -0800 (PST) From: Mark Walters To: notmuch@notmuchmail.org, amdragon@MIT.EDU Subject: [PATCH v4 07/11] lib: added interface notmuch_thread_get_flag_messages Date: Thu, 2 Feb 2012 17:43:35 +0000 Message-Id: <1328204619-25046-7-git-send-email-markwalters1009@gmail.com> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <874nv9rv79.fsf@qmul.ac.uk> References: <874nv9rv79.fsf@qmul.ac.uk> 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: Thu, 02 Feb 2012 17:43:26 -0000 The function is notmuch_thread_get_flag_messages (notmuch_thread_t *thread, unsigned int flag_mask, unsigned int flags) and returns the number of messages with the specified flags on flag_mask. This generalises the existing function notmuch_thread_get_total_messages and notmuch_thread_get_matched_messages which are retained to maintain compatibility. --- lib/message.cc | 6 +++--- lib/notmuch.h | 15 +++++++++++++-- lib/thread.cc | 39 ++++++++++++++++++++++++++------------- 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/lib/message.cc b/lib/message.cc index 0075425..d60da83 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -746,7 +746,7 @@ notmuch_bool_t notmuch_message_get_flag (notmuch_message_t *message, notmuch_message_flag_t flag) { - return message->flags & (1 << flag); + return message->flags & flag; } void @@ -754,9 +754,9 @@ notmuch_message_set_flag (notmuch_message_t *message, notmuch_message_flag_t flag, notmuch_bool_t enable) { if (enable) - message->flags |= (1 << flag); + message->flags |= flag; else - message->flags &= ~(1 << flag); + message->flags &= ~flag; } time_t diff --git a/lib/notmuch.h b/lib/notmuch.h index f75afae..c02e7f4 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -654,6 +654,16 @@ notmuch_thread_get_thread_id (notmuch_thread_t *thread); int notmuch_thread_get_total_messages (notmuch_thread_t *thread); +/* Get the number of messages in 'thread' which have the specified + * flags on flag_mask. + * + * This is a more general interface than + * notmuch_thread_get_total_messages or + * notmuch_thread_get_matched_messages + */ +int +notmuch_thread_get_flag_messages (notmuch_thread_t *thread, unsigned int flag_mask, unsigned int flags); + /* Get a notmuch_messages_t iterator for the top-level messages in * 'thread'. * @@ -902,8 +912,9 @@ notmuch_message_get_filenames (notmuch_message_t *message); /* Message flags */ typedef enum _notmuch_message_flag { - NOTMUCH_MESSAGE_FLAG_MATCH, - NOTMUCH_MESSAGE_FLAG_EXCLUDED + NOTMUCH_MESSAGE_FLAG_MATCH = (1<<0), + NOTMUCH_MESSAGE_FLAG_EXCLUDED = (1<<1), + NOTMUCH_MESSAGE_FLAG_MAX = (1<<2) } notmuch_message_flag_t; /* Get a value of a flag for the email corresponding to 'message'. */ diff --git a/lib/thread.cc b/lib/thread.cc index e976d64..542f7f4 100644 --- a/lib/thread.cc +++ b/lib/thread.cc @@ -37,8 +37,7 @@ struct visible _notmuch_thread { notmuch_message_list_t *message_list; GHashTable *message_hash; - int total_messages; - int matched_messages; + int flag_count_messages[NOTMUCH_MESSAGE_FLAG_MAX]; time_t oldest; time_t newest; }; @@ -226,7 +225,6 @@ _thread_add_message (notmuch_thread_t *thread, _notmuch_message_list_add_message (thread->message_list, talloc_steal (thread, message)); - thread->total_messages++; g_hash_table_insert (thread->message_hash, xstrdup (notmuch_message_get_message_id (message)), @@ -319,21 +317,18 @@ _thread_add_matched_message (notmuch_thread_t *thread, date = notmuch_message_get_date (message); - if (date < thread->oldest || ! thread->matched_messages) { + if (date < thread->oldest || ! notmuch_thread_get_matched_messages (thread)) { thread->oldest = date; if (sort == NOTMUCH_SORT_OLDEST_FIRST) _thread_set_subject_from_message (thread, message); } - if (date > thread->newest || ! thread->matched_messages) { + if (date > thread->newest || ! notmuch_thread_get_matched_messages (thread)) { thread->newest = date; if (sort != NOTMUCH_SORT_OLDEST_FIRST) _thread_set_subject_from_message (thread, message); } - if (!notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED)) - thread->matched_messages++; - if (g_hash_table_lookup_extended (thread->message_hash, notmuch_message_get_message_id (message), NULL, (void **) &hashed_message)) { @@ -411,7 +406,7 @@ _notmuch_thread_create (void *ctx, const char *thread_id; char *thread_id_query_string; notmuch_query_t *thread_id_query; - + int i; notmuch_messages_t *messages; notmuch_message_t *message; @@ -457,8 +452,8 @@ _notmuch_thread_create (void *ctx, thread->message_hash = g_hash_table_new_full (g_str_hash, g_str_equal, free, NULL); - thread->total_messages = 0; - thread->matched_messages = 0; + for (i = 0; i < NOTMUCH_MESSAGE_FLAG_MAX; i++) + thread->flag_count_messages[i] = 0; thread->oldest = 0; thread->newest = 0; @@ -473,6 +468,7 @@ _notmuch_thread_create (void *ctx, notmuch_messages_move_to_next (messages)) { unsigned int doc_id; + unsigned int message_flags; message = notmuch_messages_get (messages); doc_id = _notmuch_message_get_doc_id (message); @@ -485,6 +481,10 @@ _notmuch_thread_create (void *ctx, _notmuch_doc_id_set_remove (match_set, doc_id); _thread_add_matched_message (thread, message, sort); } + message_flags = + notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH) | + notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED); + thread->flag_count_messages[message_flags]++; _notmuch_message_close (message); } @@ -511,15 +511,28 @@ notmuch_thread_get_thread_id (notmuch_thread_t *thread) } int +notmuch_thread_get_flag_messages (notmuch_thread_t *thread, unsigned int flag_mask, unsigned int flags) +{ + unsigned int i; + int count = 0; + for (i = 0; i < NOTMUCH_MESSAGE_FLAG_MAX; i++) + if ((i & flag_mask) == (flags & flag_mask)) + count += thread->flag_count_messages[i]; + return count; +} + +int notmuch_thread_get_total_messages (notmuch_thread_t *thread) { - return thread->total_messages; + return notmuch_thread_get_flag_messages (thread, 0, 0); } int notmuch_thread_get_matched_messages (notmuch_thread_t *thread) { - return thread->matched_messages; + return notmuch_thread_get_flag_messages (thread, + NOTMUCH_MESSAGE_FLAG_MATCH | NOTMUCH_MESSAGE_FLAG_EXCLUDED, + NOTMUCH_MESSAGE_FLAG_MATCH); } const char * -- 1.7.2.3