1 Return-Path: <markwalters1009@gmail.com>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 84A35429E39
\r
6 for <notmuch@notmuchmail.org>; Thu, 2 Feb 2012 09:43:25 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0.201 tagged_above=-999 required=5
\r
12 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
\r
13 FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,
\r
14 RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
15 Received: from olra.theworths.org ([127.0.0.1])
\r
16 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
17 with ESMTP id cXguDjoPkW+K for <notmuch@notmuchmail.org>;
\r
18 Thu, 2 Feb 2012 09:43:22 -0800 (PST)
\r
19 Received: from mail-ww0-f45.google.com (mail-ww0-f45.google.com
\r
20 [74.125.82.45]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client
\r
21 certificate requested) by olra.theworths.org (Postfix) with ESMTPS id
\r
22 2BA11429E3E for <notmuch@notmuchmail.org>; Thu, 2 Feb 2012 09:43:10 -0800
\r
24 Received: by mail-ww0-f45.google.com with SMTP id dt12so2522817wgb.2
\r
25 for <notmuch@notmuchmail.org>; Thu, 02 Feb 2012 09:43:09 -0800 (PST)
\r
26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;
\r
27 h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;
\r
28 bh=ft1IahEMhtmHYG7nZwKDqN9UBhvMMgnXonDQYddK1RU=;
\r
29 b=imcmImRnnqaDP+RPiLQzNC7tt0t/L7bl2N+CLnyzWG59w4qaa1/dvcyO6L7/snIKtr
\r
30 i3Qa40lJtFqAsgeQ98+LTahMr9CM971o+Fy94bIPsRTwoBuNCRCl7ntmwIFli8BmjNYZ
\r
31 Ugll8FS+a1+GtA5CzzffbUbt8Ut5hYnwEMd3I=
\r
32 Received: by 10.180.106.33 with SMTP id gr1mr6195411wib.6.1328204589854;
\r
33 Thu, 02 Feb 2012 09:43:09 -0800 (PST)
\r
34 Received: from localhost (94-192-233-223.zone6.bethere.co.uk.
\r
35 [94.192.233.223]) by mx.google.com with ESMTPS id
\r
36 y1sm9134771wiw.6.2012.02.02.09.43.08 (version=TLSv1/SSLv3 cipher=OTHER); Thu,
\r
37 02 Feb 2012 09:43:09 -0800 (PST)
\r
38 From: Mark Walters <markwalters1009@gmail.com>
\r
39 To: notmuch@notmuchmail.org,
\r
41 Subject: [PATCH v4 07/11] lib: added interface
\r
42 notmuch_thread_get_flag_messages
\r
43 Date: Thu, 2 Feb 2012 17:43:35 +0000
\r
44 Message-Id: <1328204619-25046-7-git-send-email-markwalters1009@gmail.com>
\r
45 X-Mailer: git-send-email 1.7.2.3
\r
46 In-Reply-To: <874nv9rv79.fsf@qmul.ac.uk>
\r
47 References: <874nv9rv79.fsf@qmul.ac.uk>
\r
48 X-BeenThere: notmuch@notmuchmail.org
\r
49 X-Mailman-Version: 2.1.13
\r
51 List-Id: "Use and development of the notmuch mail system."
\r
52 <notmuch.notmuchmail.org>
\r
53 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
54 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
55 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
56 List-Post: <mailto:notmuch@notmuchmail.org>
\r
57 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
58 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
59 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
60 X-List-Received-Date: Thu, 02 Feb 2012 17:43:26 -0000
\r
63 notmuch_thread_get_flag_messages
\r
64 (notmuch_thread_t *thread, unsigned int flag_mask, unsigned int flags)
\r
66 and returns the number of messages with the specified flags on flag_mask.
\r
68 This generalises the existing function
\r
69 notmuch_thread_get_total_messages and
\r
70 notmuch_thread_get_matched_messages which are retained to maintain
\r
73 lib/message.cc | 6 +++---
\r
74 lib/notmuch.h | 15 +++++++++++++--
\r
75 lib/thread.cc | 39 ++++++++++++++++++++++++++-------------
\r
76 3 files changed, 42 insertions(+), 18 deletions(-)
\r
78 diff --git a/lib/message.cc b/lib/message.cc
\r
79 index 0075425..d60da83 100644
\r
80 --- a/lib/message.cc
\r
81 +++ b/lib/message.cc
\r
82 @@ -746,7 +746,7 @@ notmuch_bool_t
\r
83 notmuch_message_get_flag (notmuch_message_t *message,
\r
84 notmuch_message_flag_t flag)
\r
86 - return message->flags & (1 << flag);
\r
87 + return message->flags & flag;
\r
91 @@ -754,9 +754,9 @@ notmuch_message_set_flag (notmuch_message_t *message,
\r
92 notmuch_message_flag_t flag, notmuch_bool_t enable)
\r
95 - message->flags |= (1 << flag);
\r
96 + message->flags |= flag;
\r
98 - message->flags &= ~(1 << flag);
\r
99 + message->flags &= ~flag;
\r
103 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
104 index f75afae..c02e7f4 100644
\r
105 --- a/lib/notmuch.h
\r
106 +++ b/lib/notmuch.h
\r
107 @@ -654,6 +654,16 @@ notmuch_thread_get_thread_id (notmuch_thread_t *thread);
\r
109 notmuch_thread_get_total_messages (notmuch_thread_t *thread);
\r
111 +/* Get the number of messages in 'thread' which have the specified
\r
112 + * flags on flag_mask.
\r
114 + * This is a more general interface than
\r
115 + * notmuch_thread_get_total_messages or
\r
116 + * notmuch_thread_get_matched_messages
\r
119 +notmuch_thread_get_flag_messages (notmuch_thread_t *thread, unsigned int flag_mask, unsigned int flags);
\r
121 /* Get a notmuch_messages_t iterator for the top-level messages in
\r
124 @@ -902,8 +912,9 @@ notmuch_message_get_filenames (notmuch_message_t *message);
\r
126 /* Message flags */
\r
127 typedef enum _notmuch_message_flag {
\r
128 - NOTMUCH_MESSAGE_FLAG_MATCH,
\r
129 - NOTMUCH_MESSAGE_FLAG_EXCLUDED
\r
130 + NOTMUCH_MESSAGE_FLAG_MATCH = (1<<0),
\r
131 + NOTMUCH_MESSAGE_FLAG_EXCLUDED = (1<<1),
\r
132 + NOTMUCH_MESSAGE_FLAG_MAX = (1<<2)
\r
133 } notmuch_message_flag_t;
\r
135 /* Get a value of a flag for the email corresponding to 'message'. */
\r
136 diff --git a/lib/thread.cc b/lib/thread.cc
\r
137 index e976d64..542f7f4 100644
\r
138 --- a/lib/thread.cc
\r
139 +++ b/lib/thread.cc
\r
140 @@ -37,8 +37,7 @@ struct visible _notmuch_thread {
\r
142 notmuch_message_list_t *message_list;
\r
143 GHashTable *message_hash;
\r
144 - int total_messages;
\r
145 - int matched_messages;
\r
146 + int flag_count_messages[NOTMUCH_MESSAGE_FLAG_MAX];
\r
150 @@ -226,7 +225,6 @@ _thread_add_message (notmuch_thread_t *thread,
\r
152 _notmuch_message_list_add_message (thread->message_list,
\r
153 talloc_steal (thread, message));
\r
154 - thread->total_messages++;
\r
156 g_hash_table_insert (thread->message_hash,
\r
157 xstrdup (notmuch_message_get_message_id (message)),
\r
158 @@ -319,21 +317,18 @@ _thread_add_matched_message (notmuch_thread_t *thread,
\r
160 date = notmuch_message_get_date (message);
\r
162 - if (date < thread->oldest || ! thread->matched_messages) {
\r
163 + if (date < thread->oldest || ! notmuch_thread_get_matched_messages (thread)) {
\r
164 thread->oldest = date;
\r
165 if (sort == NOTMUCH_SORT_OLDEST_FIRST)
\r
166 _thread_set_subject_from_message (thread, message);
\r
169 - if (date > thread->newest || ! thread->matched_messages) {
\r
170 + if (date > thread->newest || ! notmuch_thread_get_matched_messages (thread)) {
\r
171 thread->newest = date;
\r
172 if (sort != NOTMUCH_SORT_OLDEST_FIRST)
\r
173 _thread_set_subject_from_message (thread, message);
\r
176 - if (!notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED))
\r
177 - thread->matched_messages++;
\r
179 if (g_hash_table_lookup_extended (thread->message_hash,
\r
180 notmuch_message_get_message_id (message), NULL,
\r
181 (void **) &hashed_message)) {
\r
182 @@ -411,7 +406,7 @@ _notmuch_thread_create (void *ctx,
\r
183 const char *thread_id;
\r
184 char *thread_id_query_string;
\r
185 notmuch_query_t *thread_id_query;
\r
188 notmuch_messages_t *messages;
\r
189 notmuch_message_t *message;
\r
191 @@ -457,8 +452,8 @@ _notmuch_thread_create (void *ctx,
\r
192 thread->message_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
\r
195 - thread->total_messages = 0;
\r
196 - thread->matched_messages = 0;
\r
197 + for (i = 0; i < NOTMUCH_MESSAGE_FLAG_MAX; i++)
\r
198 + thread->flag_count_messages[i] = 0;
\r
199 thread->oldest = 0;
\r
200 thread->newest = 0;
\r
202 @@ -473,6 +468,7 @@ _notmuch_thread_create (void *ctx,
\r
203 notmuch_messages_move_to_next (messages))
\r
205 unsigned int doc_id;
\r
206 + unsigned int message_flags;
\r
208 message = notmuch_messages_get (messages);
\r
209 doc_id = _notmuch_message_get_doc_id (message);
\r
210 @@ -485,6 +481,10 @@ _notmuch_thread_create (void *ctx,
\r
211 _notmuch_doc_id_set_remove (match_set, doc_id);
\r
212 _thread_add_matched_message (thread, message, sort);
\r
215 + notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH) |
\r
216 + notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED);
\r
217 + thread->flag_count_messages[message_flags]++;
\r
219 _notmuch_message_close (message);
\r
221 @@ -511,15 +511,28 @@ notmuch_thread_get_thread_id (notmuch_thread_t *thread)
\r
225 +notmuch_thread_get_flag_messages (notmuch_thread_t *thread, unsigned int flag_mask, unsigned int flags)
\r
229 + for (i = 0; i < NOTMUCH_MESSAGE_FLAG_MAX; i++)
\r
230 + if ((i & flag_mask) == (flags & flag_mask))
\r
231 + count += thread->flag_count_messages[i];
\r
236 notmuch_thread_get_total_messages (notmuch_thread_t *thread)
\r
238 - return thread->total_messages;
\r
239 + return notmuch_thread_get_flag_messages (thread, 0, 0);
\r
243 notmuch_thread_get_matched_messages (notmuch_thread_t *thread)
\r
245 - return thread->matched_messages;
\r
246 + return notmuch_thread_get_flag_messages (thread,
\r
247 + NOTMUCH_MESSAGE_FLAG_MATCH | NOTMUCH_MESSAGE_FLAG_EXCLUDED,
\r
248 + NOTMUCH_MESSAGE_FLAG_MATCH);
\r