1 Return-Path: <amthrax@drake.mit.edu>
\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 C53D1429E25
\r
6 for <notmuch@notmuchmail.org>; Fri, 13 Jan 2012 15:07:12 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id Mydmqg6Okl-D for <notmuch@notmuchmail.org>;
\r
16 Fri, 13 Jan 2012 15:07:11 -0800 (PST)
\r
17 Received: from dmz-mailsec-scanner-5.mit.edu (DMZ-MAILSEC-SCANNER-5.MIT.EDU
\r
19 by olra.theworths.org (Postfix) with ESMTP id A1677429E3C
\r
20 for <notmuch@notmuchmail.org>; Fri, 13 Jan 2012 15:07:11 -0800 (PST)
\r
21 X-AuditID: 12074422-b7fd66d0000008f9-b8-4f10b91f58a5
\r
22 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])
\r
23 by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP
\r
24 id 12.66.02297.F19B01F4; Fri, 13 Jan 2012 18:07:11 -0500 (EST)
\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])
\r
26 by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id q0DN7AJ5023160;
\r
27 Fri, 13 Jan 2012 18:07:10 -0500
\r
28 Received: from drake.mit.edu (26-4-166.dynamic.csail.mit.edu [18.26.4.166])
\r
29 (authenticated bits=0)
\r
30 (User authenticated as amdragon@ATHENA.MIT.EDU)
\r
31 by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q0DN79GN028778
\r
32 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);
\r
33 Fri, 13 Jan 2012 18:07:10 -0500 (EST)
\r
34 Received: from amthrax by drake.mit.edu with local (Exim 4.77)
\r
35 (envelope-from <amthrax@drake.mit.edu>)
\r
36 id 1RlqDF-0003lw-Od; Fri, 13 Jan 2012 18:07:09 -0500
\r
37 From: Austin Clements <amdragon@MIT.EDU>
\r
38 To: notmuch@notmuchmail.org
\r
39 Subject: [PATCH v2 2/3] lib: Add support for automatically excluding tags from
\r
41 Date: Fri, 13 Jan 2012 18:07:03 -0500
\r
42 Message-Id: <1326496024-14403-3-git-send-email-amdragon@mit.edu>
\r
43 X-Mailer: git-send-email 1.7.7.3
\r
44 In-Reply-To: <1326496024-14403-1-git-send-email-amdragon@mit.edu>
\r
45 References: <1326258173-21163-1-git-send-email-amdragon@mit.edu>
\r
46 <1326496024-14403-1-git-send-email-amdragon@mit.edu>
\r
47 X-Brightmail-Tracker:
\r
48 H4sIAAAAAAAAA+NgFjrKIsWRmVeSWpSXmKPExsUixCmqrCu/U8Df4O0KDoum6c4We/Z5WVy/
\r
49 OZPZgdnj7mkuj1v3X7N7PFt1izmAOYrLJiU1J7MstUjfLoErY9O9FraCPzIV17uXsTYw7hfv
\r
50 YuTkkBAwkei/1cgEYYtJXLi3nq2LkYtDSGAfo0TjwWVQzgZGiderNkA5x5kklq/8wArhzGeU
\r
51 +LwHpIeTg01AQ2Lb/uWMILaIgLTEzruzWUFsZgFHiZ/3HoLZwgJhEv2/N7CD2CwCqhJN77rB
\r
52 4rwCDhJLl12EukNB4tzqc2A1nEC9f191gs0UEiiXWHxkDeMERv4FjAyrGGVTcqt0cxMzc4pT
\r
53 k3WLkxPz8lKLdE31cjNL9FJTSjcxgkKL3UVpB+PPg0qHGAU4GJV4eAtzBPyFWBPLiitzDzFK
\r
54 cjApifI+2AYU4kvKT6nMSCzOiC8qzUktPsQowcGsJMIrZQqU401JrKxKLcqHSUlzsCiJ86pr
\r
55 vfMTEkhPLEnNTk0tSC2CycpwcChJ8O7aAdQoWJSanlqRlplTgpBm4uAEGc4DNHwRSA1vcUFi
\r
56 bnFmOkT+FKOilDhvCkhCACSRUZoH1wuL/VeM4kCvCPMeAKniAaYNuO5XQIOZgAaXpfCBDC5J
\r
57 REhJNTCyRsibJLxpTZH02nN0S9MptqD8Sx0y+v8tbj7vND12JqGB0Wjz1ajd13bfnrL9vLd5
\r
58 D0PVs7upvTN32bz8s/1tS4lWQmiT04zJH0U2GTOdmNgtdGv/rzezfKKfvl5TXryXRcno193U
\r
59 RZqh6c+SL03f9Vf5V83n8vyTFdPtNymbJ+3NVJpr3CamxFKckWioxVxUnAgARPgbqdgCAAA=
\r
60 X-BeenThere: notmuch@notmuchmail.org
\r
61 X-Mailman-Version: 2.1.13
\r
63 List-Id: "Use and development of the notmuch mail system."
\r
64 <notmuch.notmuchmail.org>
\r
65 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
66 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
67 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
68 List-Post: <mailto:notmuch@notmuchmail.org>
\r
69 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
70 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
71 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
72 X-List-Received-Date: Fri, 13 Jan 2012 23:07:13 -0000
\r
74 This is useful for tags like "deleted" and "spam" that people
\r
75 generally want to exclude from query results. These exclusions will
\r
76 be overridden if a tag is explicitly mentioned in a query.
\r
78 lib/notmuch.h | 6 ++++++
\r
79 lib/query.cc | 35 +++++++++++++++++++++++++++++++++++
\r
80 2 files changed, 41 insertions(+), 0 deletions(-)
\r
82 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
83 index 9f23a10..7929fe7 100644
\r
86 @@ -457,6 +457,12 @@ notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort);
\r
88 notmuch_query_get_sort (notmuch_query_t *query);
\r
90 +/* Add a tag that will be excluded from the query results by default.
\r
91 + * This exclusion will be overridden if this tag appears explicitly in
\r
94 +notmuch_query_add_tag_exclude (notmuch_query_t *query, const char *tag);
\r
96 /* Execute a query for threads, returning a notmuch_threads_t object
\r
97 * which can be used to iterate over the results. The returned threads
\r
98 * object is owned by the query and as such, will only be valid until
\r
99 diff --git a/lib/query.cc b/lib/query.cc
\r
100 index b6c0f12..0b36602 100644
\r
103 @@ -27,6 +27,7 @@ struct _notmuch_query {
\r
104 notmuch_database_t *notmuch;
\r
105 const char *query_string;
\r
106 notmuch_sort_t sort;
\r
107 + notmuch_string_list_t *exclude_terms;
\r
110 typedef struct _notmuch_mset_messages {
\r
111 @@ -76,6 +77,8 @@ notmuch_query_create (notmuch_database_t *notmuch,
\r
113 query->sort = NOTMUCH_SORT_NEWEST_FIRST;
\r
115 + query->exclude_terms = _notmuch_string_list_create (query);
\r
120 @@ -97,6 +100,13 @@ notmuch_query_get_sort (notmuch_query_t *query)
\r
121 return query->sort;
\r
125 +notmuch_query_add_tag_exclude (notmuch_query_t *query, const char *tag)
\r
127 + char *term = talloc_asprintf (query, "%s%s", _find_prefix ("tag"), tag);
\r
128 + _notmuch_string_list_append (query->exclude_terms, term);
\r
131 /* We end up having to call the destructors explicitly because we had
\r
132 * to use "placement new" in order to initialize C++ objects within a
\r
133 * block that we allocated with talloc. So C++ is making talloc
\r
134 @@ -112,6 +122,27 @@ _notmuch_messages_destructor (notmuch_mset_messages_t *messages)
\r
138 +/* Return a query that does not match messages with the excluded tags
\r
139 + * registered with the query. Any tags that explicitly appear in
\r
140 + * xquery will not be excluded. */
\r
141 +static Xapian::Query
\r
142 +_notmuch_exclude_tags (notmuch_query_t *query, Xapian::Query xquery)
\r
144 + for (notmuch_string_node_t *term = query->exclude_terms->head; term;
\r
145 + term = term->next) {
\r
146 + Xapian::TermIterator it = xquery.get_terms_begin ();
\r
147 + Xapian::TermIterator end = xquery.get_terms_end ();
\r
148 + for (; it != end; it++) {
\r
149 + if ((*it).compare (term->string) == 0)
\r
153 + xquery = Xapian::Query (Xapian::Query::OP_AND_NOT,
\r
154 + xquery, Xapian::Query (term->string));
\r
159 notmuch_messages_t *
\r
160 notmuch_query_search_messages (notmuch_query_t *query)
\r
162 @@ -157,6 +188,8 @@ notmuch_query_search_messages (notmuch_query_t *query)
\r
163 mail_query, string_query);
\r
166 + final_query = _notmuch_exclude_tags (query, final_query);
\r
168 enquire.set_weighting_scheme (Xapian::BoolWeight());
\r
170 switch (query->sort) {
\r
171 @@ -436,6 +469,8 @@ notmuch_query_count_messages (notmuch_query_t *query)
\r
172 mail_query, string_query);
\r
175 + final_query = _notmuch_exclude_tags (query, final_query);
\r
177 enquire.set_weighting_scheme(Xapian::BoolWeight());
\r
178 enquire.set_docid_order(Xapian::Enquire::ASCENDING);
\r