Re: [PATCH] TODO: date range queries - check
[notmuch-archives.git] / ec / 3ee210de2d3ac901b16f98088f95533f6ee81b
1 Return-Path: <novalazy@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 CF655431FD0\r
6         for <notmuch@notmuchmail.org>; Wed, 20 Jun 2012 06:29:32 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.799\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13         FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id dX8TI7kwreSU for <notmuch@notmuchmail.org>;\r
17         Wed, 20 Jun 2012 06:29:31 -0700 (PDT)\r
18 Received: from mail-pz0-f53.google.com (mail-pz0-f53.google.com\r
19         [209.85.210.53]) (using TLSv1 with cipher RC4-MD5 (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id CB180431FCB\r
22         for <notmuch@notmuchmail.org>; Wed, 20 Jun 2012 06:29:30 -0700 (PDT)\r
23 Received: by dadg9 with SMTP id g9so12291942dad.26\r
24         for <notmuch@notmuchmail.org>; Wed, 20 Jun 2012 06:29:30 -0700 (PDT)\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
26         h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
27         bh=wbM92hLqFqJT+Doctyy/ZeCmh2XnikQt41iBi9d6lBg=;\r
28         b=kpN3/LeSxXUJrqPe5AXb1SjDtTOrDxnyrOl5K/seSysIfHTgUANmeSlAF61BaoET99\r
29         4mJilMuWbTu3r0/tFoZDoDoKcXKAkdGPSObr+97AuAnGpXnIRJAPTXr2QYoyp7IVWgRa\r
30         3c7Eh5X/jZICgjzPdBBfDspHlOZw4bEIxfBKwcSLskXAx5kJ2Un7bnIDdzbZJnIAurOD\r
31         s0PL2PvLQyzKRtUtek+HPpCdnrLB+aHe9ba07ltRIoagUNULvIyygBWSv15x7bV/RTsK\r
32         /6v7NWr0UwmoNt2AT7dU/VTW4yE8O5y5mZOY/yIy/llDduj+cvgC4eCElSneafghGXFg\r
33         ndHg==\r
34 Received: by 10.68.197.70 with SMTP id is6mr57963960pbc.64.1340198970092;\r
35         Wed, 20 Jun 2012 06:29:30 -0700 (PDT)\r
36 Received: from localhost (215.42.233.220.static.exetel.com.au.\r
37         [220.233.42.215])\r
38         by mx.google.com with ESMTPS id ok6sm31955999pbb.29.2012.06.20.06.29.26\r
39         (version=TLSv1/SSLv3 cipher=OTHER);\r
40         Wed, 20 Jun 2012 06:29:29 -0700 (PDT)\r
41 From: Peter Wang <novalazy@gmail.com>\r
42 To: notmuch@notmuchmail.org\r
43 Subject: [PATCH 1/8] lib: add --exclude=all option\r
44 Date: Wed, 20 Jun 2012 23:29:00 +1000\r
45 Message-Id: <1340198947-29370-2-git-send-email-novalazy@gmail.com>\r
46 X-Mailer: git-send-email 1.7.4.4\r
47 In-Reply-To: <1340198947-29370-1-git-send-email-novalazy@gmail.com>\r
48 References: <1340198947-29370-1-git-send-email-novalazy@gmail.com>\r
49 X-BeenThere: notmuch@notmuchmail.org\r
50 X-Mailman-Version: 2.1.13\r
51 Precedence: list\r
52 List-Id: "Use and development of the notmuch mail system."\r
53         <notmuch.notmuchmail.org>\r
54 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
55         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
56 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
57 List-Post: <mailto:notmuch@notmuchmail.org>\r
58 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
59 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
60         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
61 X-List-Received-Date: Wed, 20 Jun 2012 13:29:33 -0000\r
62 \r
63 From: Mark Walters <markwalters1009@gmail.com>\r
64 \r
65 Adds a exclude all option to the lib which means that excluded\r
66 messages are completely ignored (as if they had actually been\r
67 deleted).\r
68 ---\r
69  lib/notmuch-private.h |    1 +\r
70  lib/notmuch.h         |   22 +++++++++++++++-------\r
71  lib/query.cc          |   10 ++++++----\r
72  lib/thread.cc         |   41 ++++++++++++++++++++++++++++++-----------\r
73  4 files changed, 52 insertions(+), 22 deletions(-)\r
74 \r
75 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
76 index bfb4111..aa799b4 100644\r
77 --- a/lib/notmuch-private.h\r
78 +++ b/lib/notmuch-private.h\r
79 @@ -232,6 +232,7 @@ _notmuch_thread_create (void *ctx,\r
80                         unsigned int seed_doc_id,\r
81                         notmuch_doc_id_set_t *match_set,\r
82                         notmuch_string_list_t *excluded_terms,\r
83 +                       notmuch_exclude_t omit_exclude,\r
84                         notmuch_sort_t sort);\r
85  \r
86  /* message.cc */\r
87 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
88 index 3633bed..1280afd 100644\r
89 --- a/lib/notmuch.h\r
90 +++ b/lib/notmuch.h\r
91 @@ -500,14 +500,22 @@ typedef enum {\r
92  const char *\r
93  notmuch_query_get_query_string (notmuch_query_t *query);\r
94  \r
95 +/* Exclude values for notmuch_query_set_omit_excluded */\r
96 +typedef enum {\r
97 +    NOTMUCH_EXCLUDE_FALSE,\r
98 +    NOTMUCH_EXCLUDE_TRUE,\r
99 +    NOTMUCH_EXCLUDE_ALL\r
100 +} notmuch_exclude_t;\r
101 +\r
102  /* Specify whether to omit excluded results or simply flag them.  By\r
103   * default, this is set to TRUE.\r
104   *\r
105 - * If this is TRUE, notmuch_query_search_messages will omit excluded\r
106 - * messages from the results.  notmuch_query_search_threads will omit\r
107 - * threads that match only in excluded messages, but will include all\r
108 - * messages in threads that match in at least one non-excluded\r
109 - * message.\r
110 + * If set to TRUE or ALL, notmuch_query_search_messages will omit excluded\r
111 + * messages from the results, and notmuch_query_search_threads will omit\r
112 + * threads that match only in excluded messages.  If set to TRUE,\r
113 + * notmuch_query_search_threads will include all messages in threads that\r
114 + * match in at least one non-excluded message.  Otherwise, if set to ALL,\r
115 + * notmuch_query_search_threads will omit excluded messages from all threads.\r
116   *\r
117   * The performance difference when calling\r
118   * notmuch_query_search_messages should be relatively small (and both\r
119 @@ -516,9 +524,9 @@ notmuch_query_get_query_string (notmuch_query_t *query);\r
120   * excluded messages as it does not need to construct the threads that\r
121   * only match in excluded messages.\r
122   */\r
123 -\r
124  void\r
125 -notmuch_query_set_omit_excluded (notmuch_query_t *query, notmuch_bool_t omit_excluded);\r
126 +notmuch_query_set_omit_excluded (notmuch_query_t *query,\r
127 +                                notmuch_exclude_t omit_excluded);\r
128  \r
129  /* Specify the sorting desired for this query. */\r
130  void\r
131 diff --git a/lib/query.cc b/lib/query.cc\r
132 index e9c1a2d..f752452 100644\r
133 --- a/lib/query.cc\r
134 +++ b/lib/query.cc\r
135 @@ -28,7 +28,7 @@ struct _notmuch_query {\r
136      const char *query_string;\r
137      notmuch_sort_t sort;\r
138      notmuch_string_list_t *exclude_terms;\r
139 -    notmuch_bool_t omit_excluded;\r
140 +    notmuch_exclude_t omit_excluded;\r
141  };\r
142  \r
143  typedef struct _notmuch_mset_messages {\r
144 @@ -92,7 +92,7 @@ notmuch_query_create (notmuch_database_t *notmuch,\r
145  \r
146      query->exclude_terms = _notmuch_string_list_create (query);\r
147  \r
148 -    query->omit_excluded = TRUE;\r
149 +    query->omit_excluded = NOTMUCH_EXCLUDE_TRUE;\r
150  \r
151      return query;\r
152  }\r
153 @@ -104,7 +104,8 @@ notmuch_query_get_query_string (notmuch_query_t *query)\r
154  }\r
155  \r
156  void\r
157 -notmuch_query_set_omit_excluded (notmuch_query_t *query, notmuch_bool_t omit_excluded)\r
158 +notmuch_query_set_omit_excluded (notmuch_query_t *query,\r
159 +                                notmuch_exclude_t omit_excluded)\r
160  {\r
161      query->omit_excluded = omit_excluded;\r
162  }\r
163 @@ -220,7 +221,7 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
164         if (query->exclude_terms) {\r
165             exclude_query = _notmuch_exclude_tags (query, final_query);\r
166  \r
167 -           if (query->omit_excluded)\r
168 +           if (query->omit_excluded != NOTMUCH_EXCLUDE_FALSE)\r
169                 final_query = Xapian::Query (Xapian::Query::OP_AND_NOT,\r
170                                              final_query, exclude_query);\r
171             else {\r
172 @@ -486,6 +487,7 @@ notmuch_threads_get (notmuch_threads_t *threads)\r
173                                    doc_id,\r
174                                    &threads->match_set,\r
175                                    threads->query->exclude_terms,\r
176 +                                  threads->query->omit_excluded,\r
177                                    threads->query->sort);\r
178  }\r
179  \r
180 diff --git a/lib/thread.cc b/lib/thread.cc\r
181 index e976d64..4cb0896 100644\r
182 --- a/lib/thread.cc\r
183 +++ b/lib/thread.cc\r
184 @@ -215,7 +215,8 @@ _thread_cleanup_author (notmuch_thread_t *thread,\r
185  static void\r
186  _thread_add_message (notmuch_thread_t *thread,\r
187                      notmuch_message_t *message,\r
188 -                    notmuch_string_list_t *exclude_terms)\r
189 +                    notmuch_string_list_t *exclude_terms,\r
190 +                    notmuch_exclude_t omit_exclude)\r
191  {\r
192      notmuch_tags_t *tags;\r
193      const char *tag;\r
194 @@ -223,6 +224,28 @@ _thread_add_message (notmuch_thread_t *thread,\r
195      InternetAddress *address;\r
196      const char *from, *author;\r
197      char *clean_author;\r
198 +    notmuch_bool_t message_excluded = FALSE;\r
199 +\r
200 +    for (tags = notmuch_message_get_tags (message);\r
201 +        notmuch_tags_valid (tags);\r
202 +        notmuch_tags_move_to_next (tags))\r
203 +    {\r
204 +       tag = notmuch_tags_get (tags);\r
205 +       /* Is message excluded? */\r
206 +       for (notmuch_string_node_t *term = exclude_terms->head;\r
207 +            term != NULL;\r
208 +            term = term->next)\r
209 +       {\r
210 +           /* We ignore initial 'K'. */\r
211 +           if (strcmp(tag, (term->string + 1)) == 0) {\r
212 +               message_excluded = TRUE;\r
213 +               break;\r
214 +           }\r
215 +       }\r
216 +    }\r
217 +\r
218 +    if (message_excluded && omit_exclude == NOTMUCH_EXCLUDE_ALL)\r
219 +       return;\r
220  \r
221      _notmuch_message_list_add_message (thread->message_list,\r
222                                        talloc_steal (thread, message));\r
223 @@ -263,17 +286,12 @@ _thread_add_message (notmuch_thread_t *thread,\r
224          notmuch_tags_move_to_next (tags))\r
225      {\r
226         tag = notmuch_tags_get (tags);\r
227 -       /* Mark excluded messages. */\r
228 -       for (notmuch_string_node_t *term = exclude_terms->head; term;\r
229 -            term = term->next) {\r
230 -           /* We ignore initial 'K'. */\r
231 -           if (strcmp(tag, (term->string + 1)) == 0) {\r
232 -               notmuch_message_set_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED, TRUE);\r
233 -               break;\r
234 -           }\r
235 -       }\r
236         g_hash_table_insert (thread->tags, xstrdup (tag), NULL);\r
237      }\r
238 +\r
239 +    /* Mark excluded messages. */\r
240 +    if (message_excluded)\r
241 +       notmuch_message_set_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED, TRUE);\r
242  }\r
243  \r
244  static void\r
245 @@ -404,6 +422,7 @@ _notmuch_thread_create (void *ctx,\r
246                         unsigned int seed_doc_id,\r
247                         notmuch_doc_id_set_t *match_set,\r
248                         notmuch_string_list_t *exclude_terms,\r
249 +                       notmuch_exclude_t omit_excluded,\r
250                         notmuch_sort_t sort)\r
251  {\r
252      notmuch_thread_t *thread;\r
253 @@ -479,7 +498,7 @@ _notmuch_thread_create (void *ctx,\r
254         if (doc_id == seed_doc_id)\r
255             message = seed_message;\r
256  \r
257 -       _thread_add_message (thread, message, exclude_terms);\r
258 +       _thread_add_message (thread, message, exclude_terms, omit_excluded);\r
259  \r
260         if ( _notmuch_doc_id_set_contains (match_set, doc_id)) {\r
261             _notmuch_doc_id_set_remove (match_set, doc_id);\r
262 -- \r
263 1.7.4.4\r
264 \r