[PATCH 1/2] notmuch-show: Add content-description output pair
[notmuch-archives.git] / 97 / 634ef7a4b02d89d761a183bc157ef3bc22fc88
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 BA3E1431E64\r
6         for <notmuch@notmuchmail.org>; Mon, 30 Jan 2012 20:44: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 Mru7AIKc-mMB for <notmuch@notmuchmail.org>;\r
16         Mon, 30 Jan 2012 20:44:46 -0800 (PST)\r
17 Received: from dmz-mailsec-scanner-8.mit.edu (DMZ-MAILSEC-SCANNER-8.MIT.EDU\r
18         [18.7.68.37])\r
19         by olra.theworths.org (Postfix) with ESMTP id 1EA8C431FBC\r
20         for <notmuch@notmuchmail.org>; Mon, 30 Jan 2012 20:44:46 -0800 (PST)\r
21 X-AuditID: 12074425-b7f4a6d0000008e0-97-4f2771bd419f\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
23         by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 08.F4.02272.DB1772F4; Mon, 30 Jan 2012 23:44:45 -0500 (EST)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q0V4ij1l032194; \r
27         Mon, 30 Jan 2012 23:44:45 -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 q0V4ii2W029861\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Mon, 30 Jan 2012 23:44: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 1Rs5ZQ-0002m6-TW; Mon, 30 Jan 2012 23:43:52 -0500\r
37 Date: Mon, 30 Jan 2012 23:43:52 -0500\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: Mark Walters <markwalters1009@gmail.com>\r
40 Subject: Re: [PATCH 3/7] lib: Make notmuch_query_search_messages set the\r
41         exclude flag\r
42 Message-ID: <20120131044352.GZ17991@mit.edu>\r
43 References: <8762fu4aqt.fsf@qmul.ac.uk>\r
44         <1327862394-14334-3-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: <1327862394-14334-3-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+NgFuplleLIzCtJLcpLzFFi42IRYrdT191bqO5vsOiNpsXquTwW12/OZHZg\r
52         8tg56y67x7NVt5gDmKK4bFJSczLLUov07RK4MhbdXsZacMO4Yue3HywNjDM1uxg5OCQETCQ+\r
53         tct3MXICmWISF+6tZwOxhQT2MUq8bIvoYuQCsjcwSny5+pUdwjnJJHFlwycWCGcJo8TxxnOs\r
54         IC0sAqoS+/6/YASx2QQ0JLbtXw5miwjoSNw+tIAdxGYWkJb49ruZCcQWFgiXWPTnOwuIzQtU\r
55         c+rSS2aI1ekS3dcOsUHEBSVOznzCAtGrJXHj30smkKtB5iz/xwES5hTwkpi/7S/YKlEBFYkp\r
56         J7exTWAUmoWkexaS7lkI3QsYmVcxyqbkVunmJmbmFKcm6xYnJ+blpRbpWujlZpbopaaUbmIE\r
57         h7SL6g7GCYeUDjEKcDAq8fAKfFLzF2JNLCuuzD3EKMnBpCTKO6dA3V+ILyk/pTIjsTgjvqg0\r
58         J7X4EKMEB7OSCO+b1UDlvCmJlVWpRfkwKWkOFiVxXk2td35A/yaWpGanphakFsFkZTg4lCR4\r
59         w4CxKyRYlJqeWpGWmVOCkGbi4AQZzgM0XBSkhre4IDG3ODMdIn+KUZej/e3u84xCLHn5ealS\r
60         4ryMIEUCIEUZpXlwc2Cp6BWjONBbwrz6IFU8wDQGN+kV0BImoCXPGVRBlpQkIqSkGhiFq/Yf\r
61         aLrDeb2hdkv9KX3pz7EWF5I3eyhonfb1PPT3dCLLkekuruZ9R1VLpn7vt4wKFVw/V1TvhW/9\r
62         4bOO5j+Td0hcu+iTdDXtHM8BM9M7S1qz5vw65b3CPKD7ikxfmJTM46abh2Ujfke98jMuEl9T\r
63         fIJ1epP5ec9IzQO6NznDdQK/HVQTPKrEUpyRaKjFXFScCABshsHfIAMAAA==\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: Tue, 31 Jan 2012 04:44:48 -0000\r
78 \r
79 Quoth Mark Walters on Jan 29 at  6:39 pm:\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         |    8 ++++++-\r
90 >  lib/query.cc          |   52 +++++++++++++++++++++++++++++++++++++++++++++---\r
91 >  3 files changed, 56 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 \r
103 I might be following the diff wrong, but shouldn't this be a field of\r
104 notmuch_mset_messages_t?  (Then it also doesn't have to be a pointer,\r
105 which is really how notmuch_doc_id_set_t was designed to be used.)\r
106 \r
107 >      notmuch_message_node_t *iterator;\r
108 >  };\r
109 >  \r
110 > diff --git a/lib/notmuch.h b/lib/notmuch.h\r
111 > index 7929fe7..740d005 100644\r
112 > --- a/lib/notmuch.h\r
113 > +++ b/lib/notmuch.h\r
114 > @@ -449,6 +449,11 @@ typedef enum {\r
115 >  const char *\r
116 >  notmuch_query_get_query_string (notmuch_query_t *query);\r
117 >  \r
118 > +/* specify whether to results should omit the excluded results rather\r
119 > + * than just marking them excluded */\r
120 > +void\r
121 > +notmuch_query_set_omit_excluded_messages (notmuch_query_t *query, notmuch_bool_t omit);\r
122 > +\r
123 \r
124 I don't think we should add this API.  The library behavior will not\r
125 change for library users that don't use excludes and library users\r
126 that do use excludes should by aware of the excluded flag and do the\r
127 appropriate thing.\r
128 \r
129 I can see why this is handy in some cases, but I don't think it\r
130 provides enough utility to warrant becoming part of the permanent and\r
131 minimal library interface.\r
132 \r
133 >  /* Specify the sorting desired for this query. */\r
134 >  void\r
135 >  notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort);\r
136 > @@ -895,7 +900,8 @@ notmuch_message_get_filenames (notmuch_message_t *message);\r
137 >  \r
138 >  /* Message flags */\r
139 >  typedef enum _notmuch_message_flag {\r
140 > -    NOTMUCH_MESSAGE_FLAG_MATCH\r
141 > +    NOTMUCH_MESSAGE_FLAG_MATCH,\r
142 > +    NOTMUCH_MESSAGE_FLAG_EXCLUDED\r
143 >  } notmuch_message_flag_t;\r
144 >  \r
145 >  /* Get a value of a flag for the email corresponding to 'message'. */\r
146 > diff --git a/lib/query.cc b/lib/query.cc\r
147 > index c25b301..7d165d2 100644\r
148 > --- a/lib/query.cc\r
149 > +++ b/lib/query.cc\r
150 > @@ -28,6 +28,7 @@ struct _notmuch_query {\r
151 >      const char *query_string;\r
152 >      notmuch_sort_t sort;\r
153 >      notmuch_string_list_t *exclude_terms;\r
154 > +    notmuch_bool_t omit_excluded_messages;\r
155 >  };\r
156 >  \r
157 >  typedef struct _notmuch_mset_messages {\r
158 > @@ -57,6 +58,12 @@ struct visible _notmuch_threads {\r
159 >      notmuch_doc_id_set_t match_set;\r
160 >  };\r
161 >  \r
162 > +/* we need this in the message functions so forward declare */\r
163 \r
164 Comments should start with a capital letter and end with a period.\r
165 (The code isn't completely consistent about this, but it is something\r
166 we're codifying in the upcoming style guide.)\r
167 \r
168 > +static notmuch_bool_t\r
169 > +_notmuch_doc_id_set_init (void *ctx,\r
170 > +                       notmuch_doc_id_set_t *doc_ids,\r
171 > +                       GArray *arr);\r
172 > +\r
173 >  notmuch_query_t *\r
174 >  notmuch_query_create (notmuch_database_t *notmuch,\r
175 >                     const char *query_string)\r
176 > @@ -79,6 +86,8 @@ notmuch_query_create (notmuch_database_t *notmuch,\r
177 >  \r
178 >      query->exclude_terms = _notmuch_string_list_create (query);\r
179 >  \r
180 > +    query->omit_excluded_messages = FALSE;\r
181 > +\r
182 >      return query;\r
183 >  }\r
184 >  \r
185 > @@ -89,6 +98,12 @@ notmuch_query_get_query_string (notmuch_query_t *query)\r
186 >  }\r
187 >  \r
188 >  void\r
189 > +notmuch_query_set_omit_excluded_messages (notmuch_query_t *query, notmuch_bool_t omit)\r
190 > +{\r
191 > +    query->omit_excluded_messages = omit;\r
192 > +}\r
193 > +\r
194 > +void\r
195 >  notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort)\r
196 >  {\r
197 >      query->sort = sort;\r
198 > @@ -173,6 +188,7 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
199 >                                                  "mail"));\r
200 >       Xapian::Query string_query, final_query, exclude_query;\r
201 >       Xapian::MSet mset;\r
202 > +     Xapian::MSetIterator iterator;\r
203 >       unsigned int flags = (Xapian::QueryParser::FLAG_BOOLEAN |\r
204 >                             Xapian::QueryParser::FLAG_PHRASE |\r
205 >                             Xapian::QueryParser::FLAG_LOVEHATE |\r
206 > @@ -190,11 +206,35 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
207 >           final_query = Xapian::Query (Xapian::Query::OP_AND,\r
208 >                                        mail_query, string_query);\r
209 >       }\r
210 > +     messages->base.excluded_doc_ids = NULL;\r
211 > +\r
212 > +     if (query->exclude_terms) {\r
213 > +         exclude_query = _notmuch_exclude_tags (query, final_query);\r
214 > +         exclude_query = Xapian::Query (Xapian::Query::OP_AND,\r
215 > +                                        exclude_query, final_query);\r
216 > +\r
217 > +         if (query->omit_excluded_messages)\r
218 > +             final_query = Xapian::Query (Xapian::Query::OP_AND_NOT,\r
219 > +                                          final_query, exclude_query);\r
220 > +         else {\r
221 > +             enquire.set_weighting_scheme (Xapian::BoolWeight());\r
222 > +             enquire.set_query (exclude_query);\r
223 > +\r
224 > +             mset = enquire.get_mset (0, notmuch->xapian_db->get_doccount ());\r
225 > +\r
226 > +             GArray *excluded_doc_ids = g_array_new (FALSE, FALSE, sizeof (unsigned int));\r
227 > +\r
228 > +             for (iterator = mset.begin (); iterator != mset.end (); iterator++)\r
229 > +             {\r
230 \r
231 No newline before the brace.\r
232 \r
233 > +                 unsigned int doc_id = *iterator;\r
234 > +                 g_array_append_val (excluded_doc_ids, doc_id);\r
235 > +             }\r
236 > +             messages->base.excluded_doc_ids = talloc (query, _notmuch_doc_id_set);\r
237 > +             _notmuch_doc_id_set_init (query, messages->base.excluded_doc_ids,\r
238 > +                                       excluded_doc_ids);\r
239 \r
240 Don't forget to g_array_unref excluded_doc_ids.\r
241 \r
242 > +         }\r
243 > +     }\r
244 >  \r
245 > -     exclude_query = _notmuch_exclude_tags (query, final_query);\r
246 > -\r
247 > -     final_query = Xapian::Query (Xapian::Query::OP_AND_NOT,\r
248 > -                                      final_query, exclude_query);\r
249 >  \r
250 >       enquire.set_weighting_scheme (Xapian::BoolWeight());\r
251 >  \r
252 > @@ -283,6 +323,10 @@ _notmuch_mset_messages_get (notmuch_messages_t *messages)\r
253 >       INTERNAL_ERROR ("a messages iterator contains a non-existent document ID.\n");\r
254 >      }\r
255 >  \r
256 > +    if ((messages->excluded_doc_ids) &&\r
257 > +     (_notmuch_doc_id_set_contains (messages->excluded_doc_ids, doc_id)))\r
258 \r
259 No need for so many parens (just a nit).\r
260 \r
261 > +     notmuch_message_set_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED, TRUE);\r
262 > +\r
263 >      return message;\r
264 >  }\r
265 >  \r