[PATCH v2 11/14] cli/reply: return internet address list from get header funcs
[notmuch-archives.git] / fa / 57e4ffa14ea05b9dcacd1422276abd3558236b
1 Return-Path: <jani@nikula.org>\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 543C6431FD0\r
6         for <notmuch@notmuchmail.org>; Wed, 11 Jan 2012 02:11:39 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.7\r
10 X-Spam-Level: \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 2zU91f54rsOG for <notmuch@notmuchmail.org>;\r
16         Wed, 11 Jan 2012 02:11:38 -0800 (PST)\r
17 Received: from mail-qw0-f46.google.com (mail-qw0-f46.google.com\r
18         [209.85.216.46]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 7B37D431FB6\r
21         for <notmuch@notmuchmail.org>; Wed, 11 Jan 2012 02:11:38 -0800 (PST)\r
22 Received: by qats34 with SMTP id s34so2624519qat.5\r
23         for <notmuch@notmuchmail.org>; Wed, 11 Jan 2012 02:11:36 -0800 (PST)\r
24 Received: by 10.224.33.65 with SMTP id g1mr28778316qad.98.1326276696669;\r
25         Wed, 11 Jan 2012 02:11:36 -0800 (PST)\r
26 Received: from localhost (nikula.org. [92.243.24.172])\r
27         by mx.google.com with ESMTPS id j18sm2688288qag.17.2012.01.11.02.11.34\r
28         (version=SSLv3 cipher=OTHER); Wed, 11 Jan 2012 02:11:35 -0800 (PST)\r
29 From: Jani Nikula <jani@nikula.org>\r
30 To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org\r
31 Subject: Re: [PATCH 2/3] lib: Add support for automatically excluding tags\r
32         from queries\r
33 In-Reply-To: <1326258173-21163-3-git-send-email-amdragon@mit.edu>\r
34 References: <20120109043101.GH20796@mit.edu>\r
35         <1326258173-21163-1-git-send-email-amdragon@mit.edu>\r
36         <1326258173-21163-3-git-send-email-amdragon@mit.edu>\r
37 User-Agent: Notmuch/0.10.2+187~g43d4f26 (http://notmuchmail.org) Emacs/23.1.1\r
38         (i686-pc-linux-gnu)\r
39 Date: Wed, 11 Jan 2012 10:11:33 +0000\r
40 Message-ID: <87ty42v99m.fsf@nikula.org>\r
41 MIME-Version: 1.0\r
42 Content-Type: text/plain; charset=us-ascii\r
43 X-BeenThere: notmuch@notmuchmail.org\r
44 X-Mailman-Version: 2.1.13\r
45 Precedence: list\r
46 List-Id: "Use and development of the notmuch mail system."\r
47         <notmuch.notmuchmail.org>\r
48 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
50 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
51 List-Post: <mailto:notmuch@notmuchmail.org>\r
52 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
53 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
54         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
55 X-List-Received-Date: Wed, 11 Jan 2012 10:11:39 -0000\r
56 \r
57 On Wed, 11 Jan 2012 00:02:52 -0500, Austin Clements <amdragon@MIT.EDU> wrote:\r
58 > This is useful for tags like "deleted" and "spam" that people\r
59 > generally want to exclude from query results.  These exclusions will\r
60 > be overridden if a tag is explicitly mentioned in a query.\r
61 > ---\r
62 >  lib/notmuch.h |    6 ++++++\r
63 >  lib/query.cc  |   33 +++++++++++++++++++++++++++++++++\r
64 >  2 files changed, 39 insertions(+), 0 deletions(-)\r
65\r
66 > diff --git a/lib/notmuch.h b/lib/notmuch.h\r
67 > index 9f23a10..0a3ae2b 100644\r
68 > --- a/lib/notmuch.h\r
69 > +++ b/lib/notmuch.h\r
70 > @@ -457,6 +457,12 @@ notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort);\r
71 >  notmuch_sort_t\r
72 >  notmuch_query_get_sort (notmuch_query_t *query);\r
73 >  \r
74 > +/* Add a tag that will be excluded by default from the query results.\r
75 > + * This exclusion will be overridden if this tag appears explicitly in\r
76 > + * the query. */\r
77 > +void\r
78 > +notmuch_query_add_tag_exclude (notmuch_query_t *query, const char *tag);\r
79 > +\r
80 >  /* Execute a query for threads, returning a notmuch_threads_t object\r
81 >   * which can be used to iterate over the results. The returned threads\r
82 >   * object is owned by the query and as such, will only be valid until\r
83 > diff --git a/lib/query.cc b/lib/query.cc\r
84 > index b6c0f12..716db1c 100644\r
85 > --- a/lib/query.cc\r
86 > +++ b/lib/query.cc\r
87 > @@ -27,6 +27,7 @@ struct _notmuch_query {\r
88 >      notmuch_database_t *notmuch;\r
89 >      const char *query_string;\r
90 >      notmuch_sort_t sort;\r
91 > +    notmuch_string_list_t *exclude_terms;\r
92 >  };\r
93 >  \r
94 >  typedef struct _notmuch_mset_messages {\r
95 > @@ -76,6 +77,8 @@ notmuch_query_create (notmuch_database_t *notmuch,\r
96 >  \r
97 >      query->sort = NOTMUCH_SORT_NEWEST_FIRST;\r
98 >  \r
99 > +    query->exclude_terms = _notmuch_string_list_create (query);\r
100 > +\r
101 >      return query;\r
102 >  }\r
103 >  \r
104 > @@ -97,6 +100,13 @@ notmuch_query_get_sort (notmuch_query_t *query)\r
105 >      return query->sort;\r
106 >  }\r
107 >  \r
108 > +void\r
109 > +notmuch_query_add_tag_exclude (notmuch_query_t *query, const char *tag)\r
110 > +{\r
111 > +    char *term = talloc_asprintf (query, "%s%s", _find_prefix ("tag"), tag);\r
112 > +    _notmuch_string_list_append (query->exclude_terms, term);\r
113 > +}\r
114 > +\r
115 >  /* We end up having to call the destructors explicitly because we had\r
116 >   * to use "placement new" in order to initialize C++ objects within a\r
117 >   * block that we allocated with talloc. So C++ is making talloc\r
118 > @@ -112,6 +122,25 @@ _notmuch_messages_destructor (notmuch_mset_messages_t *messages)\r
119 >      return 0;\r
120 >  }\r
121 >  \r
122 \r
123 I'd like to have a comment here, or inline in the code, explaining the\r
124 following function a little bit.\r
125 \r
126 > +static Xapian::Query\r
127 > +_notmuch_exclude_tags (notmuch_query_t *query, Xapian::Query xquery)\r
128 > +{\r
129 > +    Xapian::TermIterator end = xquery.get_terms_end ();\r
130 > +\r
131 > +    for (notmuch_string_node_t *term = query->exclude_terms->head; term;\r
132 > +      term = term->next) {\r
133 > +     Xapian::TermIterator it = xquery.get_terms_begin ();\r
134 > +     for (; it != end; it++) {\r
135 > +         if (*it == term->string)\r
136 \r
137 [This is a double reminder to me why I'm not that enthusiastic about\r
138 operator overloading in C++.]\r
139 \r
140 > +             break;\r
141 > +     }\r
142 > +     if (it == end)\r
143 > +         xquery = Xapian::Query (Xapian::Query::OP_AND_NOT,\r
144 > +                                 xquery, Xapian::Query (term->string));\r
145 \r
146 I briefly dug into Xapian documentation and source code, and became none\r
147 the wiser whether this copies the queries passed to it or not, i.e. does\r
148 this leak memory or not. I just presume you know what you're doing. ;)\r
149 \r
150 I think the function fails if someone is stupid enough to exclude the\r
151 same tag twice. I'm not sure if you should care. If you think so, you\r
152 could just check double add in notmuch_query_add_tag_exclude().\r
153 \r
154 Otherwise, looks good.\r
155 \r
156 > +    }\r
157 > +    return xquery;\r
158 > +}\r
159 > +\r
160 >  notmuch_messages_t *\r
161 >  notmuch_query_search_messages (notmuch_query_t *query)\r
162 >  {\r
163 > @@ -157,6 +186,8 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
164 >                                        mail_query, string_query);\r
165 >       }\r
166 >  \r
167 > +     final_query = _notmuch_exclude_tags (query, final_query);\r
168 > +\r
169 >       enquire.set_weighting_scheme (Xapian::BoolWeight());\r
170 >  \r
171 >       switch (query->sort) {\r
172 > @@ -436,6 +467,8 @@ notmuch_query_count_messages (notmuch_query_t *query)\r
173 >                                        mail_query, string_query);\r
174 >       }\r
175 >  \r
176 > +     final_query = _notmuch_exclude_tags (query, final_query);\r
177 > +\r
178 >       enquire.set_weighting_scheme(Xapian::BoolWeight());\r
179 >       enquire.set_docid_order(Xapian::Enquire::ASCENDING);\r
180 >  \r
181 > -- \r
182 > 1.7.7.3\r
183\r
184 > _______________________________________________\r
185 > notmuch mailing list\r
186 > notmuch@notmuchmail.org\r
187 > http://notmuchmail.org/mailman/listinfo/notmuch\r