Re: [PATCH 0/4] Allow specifying alternate names for addresses in other_email
[notmuch-archives.git] / ae / 20c38db3742acbb8cd20a841008380def598d9
1 Return-Path: <amdragon@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 7C67D414796\r
6         for <notmuch@notmuchmail.org>; Fri, 24 Feb 2012 15:39:48 -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 P+ty2JFQ1it4 for <notmuch@notmuchmail.org>;\r
16         Fri, 24 Feb 2012 15:39:47 -0800 (PST)\r
17 Received: from dmz-mailsec-scanner-3.mit.edu (DMZ-MAILSEC-SCANNER-3.MIT.EDU\r
18         [18.9.25.14])\r
19         by olra.theworths.org (Postfix) with ESMTP id 9798541638B\r
20         for <notmuch@notmuchmail.org>; Fri, 24 Feb 2012 15:39:47 -0800 (PST)\r
21 X-AuditID: 1209190e-b7f7c6d0000008c3-59-4f481fc2576d\r
22 Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
23         by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 54.FF.02243.2CF184F4; Fri, 24 Feb 2012 18:39:46 -0500 (EST)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id q1ONdjZG001590; \r
27         Fri, 24 Feb 2012 18:39:46 -0500\r
28 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\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 q1ONdik0025799\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Fri, 24 Feb 2012 18:39:45 -0500 (EST)\r
34 Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)\r
35         (envelope-from <amdragon@mit.edu>)\r
36         id 1S14jo-0000hh-4O; Fri, 24 Feb 2012 18:39:44 -0500\r
37 Date: Fri, 24 Feb 2012 18:39:44 -0500\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: Mark Walters <markwalters1009@gmail.com>\r
40 Subject: Re: [RFC PATCH v5 05/11] lib: Make notmuch_query_search_messages set\r
41         the exclude flag\r
42 Message-ID: <20120224233944.GG30513@mit.edu>\r
43 References: <1329296619-7463-1-git-send-email-markwalters1009@gmail.com>\r
44         <1329296619-7463-6-git-send-email-markwalters1009@gmail.com>\r
45 MIME-Version: 1.0\r
46 Content-Type: text/plain; charset=us-ascii\r
47 Content-Disposition: inline\r
48 In-Reply-To: <1329296619-7463-6-git-send-email-markwalters1009@gmail.com>\r
49 User-Agent: Mutt/1.5.21 (2010-09-15)\r
50 X-Brightmail-Tracker:\r
51  H4sIAAAAAAAAA+NgFupjleLIzCtJLcpLzFFi42IRYrdT0T0k7+FvcGe3lMXquTwW12/OZHZg\r
52         8tg56y67x7NVt5gDmKK4bFJSczLLUov07RK4MqYce8hUsFavYtK2FrYGxibVLkZODgkBE4nf\r
53         q1uZIWwxiQv31rOB2EIC+xglNm5S7GLkArI3MErM7D/EDuGcZJLoXn0MylnCKHHw+RewFhYB\r
54         VYkLXctYQGw2AQ2JbfuXM4LYIgI6ErcPLWAHsZkFpCW+/W5mArGFBRIkzpyZCWbzAtUsmPyf\r
55         FWJoO6NE46mzbBAJQYmTM5+wQDRrSdz49xKogQNs0PJ/HCAmp4CnRP/0EJAKUQEViSknt7FN\r
56         YBSahaR5FpLmWQjNCxiZVzHKpuRW6eYmZuYUpybrFicn5uWlFuka6+VmluilppRuYgQFNack\r
57         3w7GrweVDjEKcDAq8fAyb3H3F2JNLCuuzD3EKMnBpCTKay7r4S/El5SfUpmRWJwRX1Sak1p8\r
58         iFGCg1lJhNeODSjHm5JYWZValA+TkuZgURLnVdN65yckkJ5YkpqdmlqQWgSTleHgUJLgfSkH\r
59         1ChYlJqeWpGWmVOCkGbi4AQZzgM0/D9IDW9xQWJucWY6RP4Uoy7H2sWbLzIKseTl56VKifP+\r
60         BSkSACnKKM2DmwNLRq8YxYHeEua9AFLFA0xkcJNeAS1hAlpi/9cVZElJIkJKqoFxzZVvUlvm\r
61         Szs7+s+vPWdy5/b5lscuScHJ/8q3pcrPkX/damg9341nUupti1v6k7z+zDu/tz48mfnZ4UXW\r
62         Px6Yr/uqe/HinOPTjXiu8gbbHhM4ee6o+S5VlolceRXF7/+fr+o+s+bDiWXx93/PFzirxad4\r
63         KHr2dvnbriszuFOF/fhfrJiyREpuqxJLcUaioRZzUXEiAAqBQeohAwAA\r
64 Cc: notmuch@notmuchmail.org\r
65 X-BeenThere: notmuch@notmuchmail.org\r
66 X-Mailman-Version: 2.1.13\r
67 Precedence: list\r
68 List-Id: "Use and development of the notmuch mail system."\r
69         <notmuch.notmuchmail.org>\r
70 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
71         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
72 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
73 List-Post: <mailto:notmuch@notmuchmail.org>\r
74 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
75 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
76         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
77 X-List-Received-Date: Fri, 24 Feb 2012 23:39:48 -0000\r
78 \r
79 Quoth Mark Walters on Feb 15 at  9:03 am:\r
80 > Add a flag NOTMUCH_MESSAGE_FLAG_EXCLUDED which is set by\r
81 > notmuch_query_search_messages for excluded messages. Also add an\r
82 > option omit_excluded_messages to the search that we do not want the\r
83 > excludes at all.\r
84\r
85 > This exclude flag will be added to notmuch_query_search threads in the\r
86 > next patch.\r
87 > ---\r
88 >  lib/notmuch-private.h |    1 +\r
89 >  lib/notmuch.h         |   10 ++++++++-\r
90 >  lib/query.cc          |   52 +++++++++++++++++++++++++++++++++++++++++++++---\r
91 >  3 files changed, 58 insertions(+), 5 deletions(-)\r
92\r
93 > diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
94 > index 7bf153e..e791bb0 100644\r
95 > --- a/lib/notmuch-private.h\r
96 > +++ b/lib/notmuch-private.h\r
97 > @@ -401,6 +401,7 @@ typedef struct _notmuch_message_list {\r
98 >   */\r
99 >  struct visible _notmuch_messages {\r
100 >      notmuch_bool_t is_of_list_type;\r
101 > +    notmuch_doc_id_set_t *excluded_doc_ids;\r
102 >      notmuch_message_node_t *iterator;\r
103 >  };\r
104 >  \r
105 > diff --git a/lib/notmuch.h b/lib/notmuch.h\r
106 > index 7929fe7..f75afae 100644\r
107 > --- a/lib/notmuch.h\r
108 > +++ b/lib/notmuch.h\r
109 > @@ -449,6 +449,13 @@ typedef enum {\r
110 >  const char *\r
111 >  notmuch_query_get_query_string (notmuch_query_t *query);\r
112 >  \r
113 > +/* Specify whether to results should omit the excluded results rather\r
114 > + * than just marking them excluded. This is useful for passing a\r
115 > + * notmuch_messages_t not containing the excluded messages to other\r
116 > + * functions. */\r
117 > +void\r
118 > +notmuch_query_set_omit_excluded_messages (notmuch_query_t *query, notmuch_bool_t omit);\r
119 > +\r
120 >  /* Specify the sorting desired for this query. */\r
121 >  void\r
122 >  notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort);\r
123 > @@ -895,7 +902,8 @@ notmuch_message_get_filenames (notmuch_message_t *message);\r
124 >  \r
125 >  /* Message flags */\r
126 >  typedef enum _notmuch_message_flag {\r
127 > -    NOTMUCH_MESSAGE_FLAG_MATCH\r
128 > +    NOTMUCH_MESSAGE_FLAG_MATCH,\r
129 > +    NOTMUCH_MESSAGE_FLAG_EXCLUDED\r
130 >  } notmuch_message_flag_t;\r
131 >  \r
132 >  /* Get a value of a flag for the email corresponding to 'message'. */\r
133 > diff --git a/lib/query.cc b/lib/query.cc\r
134 > index c25b301..90a71a1 100644\r
135 > --- a/lib/query.cc\r
136 > +++ b/lib/query.cc\r
137 > @@ -28,6 +28,7 @@ struct _notmuch_query {\r
138 >      const char *query_string;\r
139 >      notmuch_sort_t sort;\r
140 >      notmuch_string_list_t *exclude_terms;\r
141 > +    notmuch_bool_t omit_excluded_messages;\r
142 >  };\r
143 >  \r
144 >  typedef struct _notmuch_mset_messages {\r
145 > @@ -57,6 +58,12 @@ struct visible _notmuch_threads {\r
146 >      notmuch_doc_id_set_t match_set;\r
147 >  };\r
148 >  \r
149 > +/* We need this in the message functions so forward declare. */\r
150 > +static notmuch_bool_t\r
151 > +_notmuch_doc_id_set_init (void *ctx,\r
152 > +                       notmuch_doc_id_set_t *doc_ids,\r
153 > +                       GArray *arr);\r
154 > +\r
155 >  notmuch_query_t *\r
156 >  notmuch_query_create (notmuch_database_t *notmuch,\r
157 >                     const char *query_string)\r
158 > @@ -79,6 +86,8 @@ notmuch_query_create (notmuch_database_t *notmuch,\r
159 >  \r
160 >      query->exclude_terms = _notmuch_string_list_create (query);\r
161 >  \r
162 > +    query->omit_excluded_messages = FALSE;\r
163 > +\r
164 >      return query;\r
165 >  }\r
166 >  \r
167 > @@ -89,6 +98,12 @@ notmuch_query_get_query_string (notmuch_query_t *query)\r
168 >  }\r
169 >  \r
170 >  void\r
171 > +notmuch_query_set_omit_excluded_messages (notmuch_query_t *query, notmuch_bool_t omit)\r
172 > +{\r
173 > +    query->omit_excluded_messages = omit;\r
174 > +}\r
175 > +\r
176 > +void\r
177 >  notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort)\r
178 >  {\r
179 >      query->sort = sort;\r
180 > @@ -173,6 +188,7 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
181 >                                                  "mail"));\r
182 >       Xapian::Query string_query, final_query, exclude_query;\r
183 >       Xapian::MSet mset;\r
184 > +     Xapian::MSetIterator iterator;\r
185 >       unsigned int flags = (Xapian::QueryParser::FLAG_BOOLEAN |\r
186 >                             Xapian::QueryParser::FLAG_PHRASE |\r
187 >                             Xapian::QueryParser::FLAG_LOVEHATE |\r
188 > @@ -190,11 +206,35 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
189 >           final_query = Xapian::Query (Xapian::Query::OP_AND,\r
190 >                                        mail_query, string_query);\r
191 >       }\r
192 > +     messages->base.excluded_doc_ids = NULL;\r
193 > +\r
194 > +     if (query->exclude_terms) {\r
195 > +         exclude_query = _notmuch_exclude_tags (query, final_query);\r
196 > +         exclude_query = Xapian::Query (Xapian::Query::OP_AND,\r
197 > +                                        exclude_query, final_query);\r
198 > +\r
199 > +         if (query->omit_excluded_messages)\r
200 > +             final_query = Xapian::Query (Xapian::Query::OP_AND_NOT,\r
201 > +                                          final_query, exclude_query);\r
202 > +         else {\r
203 > +             enquire.set_weighting_scheme (Xapian::BoolWeight());\r
204 > +             enquire.set_query (exclude_query);\r
205 > +\r
206 > +             mset = enquire.get_mset (0, notmuch->xapian_db->get_doccount ());\r
207 > +\r
208 > +             GArray *excluded_doc_ids = g_array_new (FALSE, FALSE, sizeof (unsigned int));\r
209 > +\r
210 > +             for (iterator = mset.begin (); iterator != mset.end (); iterator++) {\r
211 > +                 unsigned int doc_id = *iterator;\r
212 > +                 g_array_append_val (excluded_doc_ids, doc_id);\r
213 > +             }\r
214 > +             messages->base.excluded_doc_ids = talloc (query, _notmuch_doc_id_set);\r
215 \r
216 Should this have 'messages' as its talloc context?\r
217 \r
218 > +             _notmuch_doc_id_set_init (query, messages->base.excluded_doc_ids,\r
219 > +                                       excluded_doc_ids);\r
220 > +             g_array_unref (excluded_doc_ids);\r
221 > +         }\r
222 > +     }\r
223 >  \r
224 > -     exclude_query = _notmuch_exclude_tags (query, final_query);\r
225 > -\r
226 > -     final_query = Xapian::Query (Xapian::Query::OP_AND_NOT,\r
227 > -                                      final_query, exclude_query);\r
228 >  \r
229 >       enquire.set_weighting_scheme (Xapian::BoolWeight());\r
230 >  \r
231 > @@ -283,6 +323,10 @@ _notmuch_mset_messages_get (notmuch_messages_t *messages)\r
232 >       INTERNAL_ERROR ("a messages iterator contains a non-existent document ID.\n");\r
233 >      }\r
234 >  \r
235 > +    if (messages->excluded_doc_ids &&\r
236 > +     _notmuch_doc_id_set_contains (messages->excluded_doc_ids, doc_id))\r
237 > +     notmuch_message_set_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED, TRUE);\r
238 > +\r
239 \r
240 This, at least, is pleasingly simple!\r
241 \r
242 >      return message;\r
243 >  }\r
244 >  \r