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 15F0D431FBD
\r
6 for <notmuch@notmuchmail.org>; Sat, 25 Feb 2012 21:35:35 -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 jpQRTAtTaBzQ for <notmuch@notmuchmail.org>;
\r
18 Sat, 25 Feb 2012 21:35:34 -0800 (PST)
\r
19 Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com
\r
20 [209.85.212.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
21 (No client certificate requested)
\r
22 by olra.theworths.org (Postfix) with ESMTPS id E2CD4431FAE
\r
23 for <notmuch@notmuchmail.org>; Sat, 25 Feb 2012 21:35:33 -0800 (PST)
\r
24 Received: by wibhi8 with SMTP id hi8so2569385wib.26
\r
25 for <notmuch@notmuchmail.org>; Sat, 25 Feb 2012 21:35:32 -0800 (PST)
\r
26 Received-SPF: pass (google.com: domain of markwalters1009@gmail.com designates
\r
27 10.180.107.68 as permitted sender) client-ip=10.180.107.68;
\r
28 Authentication-Results: mr.google.com; spf=pass (google.com: domain of
\r
29 markwalters1009@gmail.com designates 10.180.107.68 as permitted
\r
30 sender) smtp.mail=markwalters1009@gmail.com;
\r
31 dkim=pass header.i=markwalters1009@gmail.com
\r
32 Received: from mr.google.com ([10.180.107.68])
\r
33 by 10.180.107.68 with SMTP id ha4mr17652112wib.9.1330234532646
\r
34 (num_hops = 1); Sat, 25 Feb 2012 21:35:32 -0800 (PST)
\r
35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;
\r
36 h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;
\r
37 bh=SoROdO1KnSo5ZQOPHxwkh6inm1EtWKujflP7hNz3yVM=;
\r
38 b=OjlWnvYbcdQHPbfAt8wW0WvMbs0+vTH9TpqDkyrdo5UHSUx1wRgetA/7DY8l8ew27D
\r
39 3KPWSu2NZ1gNxsPLEiF7puQSL4LFZ+5NzwV5Q5FTxf95iMEtYyJG30BhjnztvFTTEjud
\r
40 /pjR+WXLDoHFHtrkvzXxpaDe9kOteBHWDLRnM=
\r
41 Received: by 10.180.107.68 with SMTP id ha4mr9286184wib.9.1330157136949;
\r
42 Sat, 25 Feb 2012 00:05:36 -0800 (PST)
\r
43 Received: from localhost (94-192-233-223.zone6.bethere.co.uk.
\r
44 [94.192.233.223]) by mx.google.com with ESMTPS id
\r
45 df3sm8234904wib.1.2012.02.25.00.05.35 (version=TLSv1/SSLv3 cipher=OTHER);
\r
46 Sat, 25 Feb 2012 00:05:36 -0800 (PST)
\r
47 From: Mark Walters <markwalters1009@gmail.com>
\r
48 To: notmuch@notmuchmail.org,
\r
49 Austin Clements <amdragon@MIT.EDU>
\r
50 Subject: [Patch v6 05/13] lib: Make notmuch_query_search_messages set the
\r
52 Date: Sat, 25 Feb 2012 08:06:36 +0000
\r
53 Message-Id: <1330157204-26094-6-git-send-email-markwalters1009@gmail.com>
\r
54 X-Mailer: git-send-email 1.7.2.3
\r
55 In-Reply-To: <1330157204-26094-1-git-send-email-markwalters1009@gmail.com>
\r
56 References: <1330157204-26094-1-git-send-email-markwalters1009@gmail.com>
\r
57 X-BeenThere: notmuch@notmuchmail.org
\r
58 X-Mailman-Version: 2.1.13
\r
60 List-Id: "Use and development of the notmuch mail system."
\r
61 <notmuch.notmuchmail.org>
\r
62 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
63 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
64 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
65 List-Post: <mailto:notmuch@notmuchmail.org>
\r
66 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
67 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
68 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
69 X-List-Received-Date: Sun, 26 Feb 2012 05:35:35 -0000
\r
71 Add a flag NOTMUCH_MESSAGE_FLAG_EXCLUDED which is set by
\r
72 notmuch_query_search_messages for excluded messages. Also add an
\r
73 option omit_excluded_messages to the search that we do not want the
\r
76 This exclude flag will be added to notmuch_query_search threads in the
\r
79 lib/notmuch-private.h | 1 +
\r
80 lib/notmuch.h | 10 +++++++-
\r
81 lib/query.cc | 59 ++++++++++++++++++++++++++++++++++++++++++++-----
\r
82 3 files changed, 63 insertions(+), 7 deletions(-)
\r
84 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
\r
85 index 7bf153e..e791bb0 100644
\r
86 --- a/lib/notmuch-private.h
\r
87 +++ b/lib/notmuch-private.h
\r
88 @@ -401,6 +401,7 @@ typedef struct _notmuch_message_list {
\r
90 struct visible _notmuch_messages {
\r
91 notmuch_bool_t is_of_list_type;
\r
92 + notmuch_doc_id_set_t *excluded_doc_ids;
\r
93 notmuch_message_node_t *iterator;
\r
96 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
97 index 7929fe7..f75afae 100644
\r
100 @@ -449,6 +449,13 @@ typedef enum {
\r
102 notmuch_query_get_query_string (notmuch_query_t *query);
\r
104 +/* Specify whether to results should omit the excluded results rather
\r
105 + * than just marking them excluded. This is useful for passing a
\r
106 + * notmuch_messages_t not containing the excluded messages to other
\r
109 +notmuch_query_set_omit_excluded_messages (notmuch_query_t *query, notmuch_bool_t omit);
\r
111 /* Specify the sorting desired for this query. */
\r
113 notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort);
\r
114 @@ -895,7 +902,8 @@ notmuch_message_get_filenames (notmuch_message_t *message);
\r
116 /* Message flags */
\r
117 typedef enum _notmuch_message_flag {
\r
118 - NOTMUCH_MESSAGE_FLAG_MATCH
\r
119 + NOTMUCH_MESSAGE_FLAG_MATCH,
\r
120 + NOTMUCH_MESSAGE_FLAG_EXCLUDED
\r
121 } notmuch_message_flag_t;
\r
123 /* Get a value of a flag for the email corresponding to 'message'. */
\r
124 diff --git a/lib/query.cc b/lib/query.cc
\r
125 index c25b301..ef2a11f 100644
\r
128 @@ -28,6 +28,7 @@ struct _notmuch_query {
\r
129 const char *query_string;
\r
130 notmuch_sort_t sort;
\r
131 notmuch_string_list_t *exclude_terms;
\r
132 + notmuch_bool_t omit_excluded_messages;
\r
135 typedef struct _notmuch_mset_messages {
\r
136 @@ -57,6 +58,12 @@ struct visible _notmuch_threads {
\r
137 notmuch_doc_id_set_t match_set;
\r
140 +/* We need this in the message functions so forward declare. */
\r
141 +static notmuch_bool_t
\r
142 +_notmuch_doc_id_set_init (void *ctx,
\r
143 + notmuch_doc_id_set_t *doc_ids,
\r
147 notmuch_query_create (notmuch_database_t *notmuch,
\r
148 const char *query_string)
\r
149 @@ -79,6 +86,8 @@ notmuch_query_create (notmuch_database_t *notmuch,
\r
151 query->exclude_terms = _notmuch_string_list_create (query);
\r
153 + query->omit_excluded_messages = FALSE;
\r
158 @@ -89,6 +98,12 @@ notmuch_query_get_query_string (notmuch_query_t *query)
\r
162 +notmuch_query_set_omit_excluded_messages (notmuch_query_t *query, notmuch_bool_t omit)
\r
164 + query->omit_excluded_messages = omit;
\r
168 notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort)
\r
170 query->sort = sort;
\r
171 @@ -124,8 +139,9 @@ _notmuch_messages_destructor (notmuch_mset_messages_t *messages)
\r
173 /* Return a query that matches messages with the excluded tags
\r
174 * registered with query. Any tags that explicitly appear in xquery
\r
175 - * will not be excluded. The caller of this function has to combine
\r
176 - * the returned query appropriately.*/
\r
177 + * will not be excluded, and will be removed from the list of exclude
\r
178 + * tags. The caller of this function has to combine the returned
\r
179 + * query appropriately.*/
\r
180 static Xapian::Query
\r
181 _notmuch_exclude_tags (notmuch_query_t *query, Xapian::Query xquery)
\r
183 @@ -142,6 +158,8 @@ _notmuch_exclude_tags (notmuch_query_t *query, Xapian::Query xquery)
\r
185 exclude_query = Xapian::Query (Xapian::Query::OP_OR,
\r
186 exclude_query, Xapian::Query (term->string));
\r
188 + term->string = talloc_strdup (query, "");
\r
190 return exclude_query;
\r
192 @@ -173,6 +191,7 @@ notmuch_query_search_messages (notmuch_query_t *query)
\r
194 Xapian::Query string_query, final_query, exclude_query;
\r
196 + Xapian::MSetIterator iterator;
\r
197 unsigned int flags = (Xapian::QueryParser::FLAG_BOOLEAN |
\r
198 Xapian::QueryParser::FLAG_PHRASE |
\r
199 Xapian::QueryParser::FLAG_LOVEHATE |
\r
200 @@ -190,11 +209,35 @@ notmuch_query_search_messages (notmuch_query_t *query)
\r
201 final_query = Xapian::Query (Xapian::Query::OP_AND,
\r
202 mail_query, string_query);
\r
204 + messages->base.excluded_doc_ids = NULL;
\r
206 + if (query->exclude_terms) {
\r
207 + exclude_query = _notmuch_exclude_tags (query, final_query);
\r
208 + exclude_query = Xapian::Query (Xapian::Query::OP_AND,
\r
209 + exclude_query, final_query);
\r
211 + if (query->omit_excluded_messages)
\r
212 + final_query = Xapian::Query (Xapian::Query::OP_AND_NOT,
\r
213 + final_query, exclude_query);
\r
215 + enquire.set_weighting_scheme (Xapian::BoolWeight());
\r
216 + enquire.set_query (exclude_query);
\r
218 + mset = enquire.get_mset (0, notmuch->xapian_db->get_doccount ());
\r
220 + GArray *excluded_doc_ids = g_array_new (FALSE, FALSE, sizeof (unsigned int));
\r
222 + for (iterator = mset.begin (); iterator != mset.end (); iterator++) {
\r
223 + unsigned int doc_id = *iterator;
\r
224 + g_array_append_val (excluded_doc_ids, doc_id);
\r
226 + messages->base.excluded_doc_ids = talloc (messages, _notmuch_doc_id_set);
\r
227 + _notmuch_doc_id_set_init (query, messages->base.excluded_doc_ids,
\r
228 + excluded_doc_ids);
\r
229 + g_array_unref (excluded_doc_ids);
\r
233 - exclude_query = _notmuch_exclude_tags (query, final_query);
\r
235 - final_query = Xapian::Query (Xapian::Query::OP_AND_NOT,
\r
236 - final_query, exclude_query);
\r
238 enquire.set_weighting_scheme (Xapian::BoolWeight());
\r
240 @@ -283,6 +326,10 @@ _notmuch_mset_messages_get (notmuch_messages_t *messages)
\r
241 INTERNAL_ERROR ("a messages iterator contains a non-existent document ID.\n");
\r
244 + if (messages->excluded_doc_ids &&
\r
245 + _notmuch_doc_id_set_contains (messages->excluded_doc_ids, doc_id))
\r
246 + notmuch_message_set_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED, TRUE);
\r