Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / f1 / 54f62b43f5cfa6ae556ba222fea4eb28e48f03
1 Return-Path: <markwalters1009@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 B5038431FDE\r
6         for <notmuch@notmuchmail.org>; Thu,  1 Mar 2012 14:29:45 -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.201\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13         FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
14         RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
15 Received: from olra.theworths.org ([127.0.0.1])\r
16         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
17         with ESMTP id YXxIMO5o8-0m for <notmuch@notmuchmail.org>;\r
18         Thu,  1 Mar 2012 14:29:43 -0800 (PST)\r
19 Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com\r
20         [209.85.212.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
21         (No client certificate requested)\r
22         by olra.theworths.org (Postfix) with ESMTPS id 05E52429E3D\r
23         for <notmuch@notmuchmail.org>; Thu,  1 Mar 2012 14:29:25 -0800 (PST)\r
24 Received: by mail-wi0-f181.google.com with SMTP id o1so305757wic.26\r
25         for <notmuch@notmuchmail.org>; Thu, 01 Mar 2012 14:29:25 -0800 (PST)\r
26 Received-SPF: pass (google.com: domain of markwalters1009@gmail.com designates\r
27         10.180.84.170 as permitted sender) client-ip=10.180.84.170; \r
28 Authentication-Results: mr.google.com; spf=pass (google.com: domain of\r
29         markwalters1009@gmail.com designates 10.180.84.170 as permitted\r
30         sender) smtp.mail=markwalters1009@gmail.com;\r
31         dkim=pass header.i=markwalters1009@gmail.com\r
32 Received: from mr.google.com ([10.180.84.170])\r
33         by 10.180.84.170 with SMTP id a10mr6523375wiz.9.1330640965867 (num_hops\r
34         = 1); Thu, 01 Mar 2012 14:29:25 -0800 (PST)\r
35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
36         h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
37         bh=SoROdO1KnSo5ZQOPHxwkh6inm1EtWKujflP7hNz3yVM=;\r
38         b=gNvReNVnUuJQb2NsEblMA4/wRFDzEtZ5DZaNpTmiF4zScm67RHChTEu1/t9qkczSET\r
39         sr1QAZKXhN9U/W3HVdeXlqQo+B5FtJ7A61maDF8zyigT1Yc03DkWwbuHBvwJUE/+6wHV\r
40         9GEm1Atsw24evh8Z5Mf+nJz4zf2dux5o/kocoy/3hNeNvdeLNFwhAjdhaujjZKRA14zR\r
41         XoZin4RERWzmnYPXsxR/X4tTy1yYNvtej7YU8QjJcvYtJp8uszM23dAZJakcTrI6NBb4\r
42         M3oKp6uXFY0IOyzWUZLRJWpu2WWQ66QXilW6xYz8P+dvIGH+ueiALfVi3N3Ynz81yaDg\r
43         GWNg==\r
44 Received: by 10.180.84.170 with SMTP id a10mr5262781wiz.9.1330640965803;\r
45         Thu, 01 Mar 2012 14:29:25 -0800 (PST)\r
46 Received: from localhost (94-192-233-223.zone6.bethere.co.uk.\r
47  [94.192.233.223])      by mx.google.com with ESMTPS id\r
48  9sm16612907wid.2.2012.03.01.14.29.16   (version=TLSv1/SSLv3 cipher=OTHER);     Thu,\r
49  01 Mar 2012 14:29:17 -0800 (PST)\r
50 From: Mark Walters <markwalters1009@gmail.com>\r
51 To: notmuch@notmuchmail.org\r
52 Subject: [Patch v7 05/13] lib: Make notmuch_query_search_messages set the\r
53         exclude flag\r
54 Date: Thu,  1 Mar 2012 22:30:37 +0000\r
55 Message-Id: <1330641045-27416-6-git-send-email-markwalters1009@gmail.com>\r
56 X-Mailer: git-send-email 1.7.2.3\r
57 In-Reply-To: <1330641045-27416-1-git-send-email-markwalters1009@gmail.com>\r
58 References: <1330641045-27416-1-git-send-email-markwalters1009@gmail.com>\r
59 X-BeenThere: notmuch@notmuchmail.org\r
60 X-Mailman-Version: 2.1.13\r
61 Precedence: list\r
62 List-Id: "Use and development of the notmuch mail system."\r
63         <notmuch.notmuchmail.org>\r
64 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
65         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
66 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
67 List-Post: <mailto:notmuch@notmuchmail.org>\r
68 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
69 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
70         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
71 X-List-Received-Date: Thu, 01 Mar 2012 22:29:46 -0000\r
72 \r
73 Add a flag NOTMUCH_MESSAGE_FLAG_EXCLUDED which is set by\r
74 notmuch_query_search_messages for excluded messages. Also add an\r
75 option omit_excluded_messages to the search that we do not want the\r
76 excludes at all.\r
77 \r
78 This exclude flag will be added to notmuch_query_search threads in the\r
79 next patch.\r
80 ---\r
81  lib/notmuch-private.h |    1 +\r
82  lib/notmuch.h         |   10 +++++++-\r
83  lib/query.cc          |   59 ++++++++++++++++++++++++++++++++++++++++++++-----\r
84  3 files changed, 63 insertions(+), 7 deletions(-)\r
85 \r
86 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
87 index 7bf153e..e791bb0 100644\r
88 --- a/lib/notmuch-private.h\r
89 +++ b/lib/notmuch-private.h\r
90 @@ -401,6 +401,7 @@ typedef struct _notmuch_message_list {\r
91   */\r
92  struct visible _notmuch_messages {\r
93      notmuch_bool_t is_of_list_type;\r
94 +    notmuch_doc_id_set_t *excluded_doc_ids;\r
95      notmuch_message_node_t *iterator;\r
96  };\r
97  \r
98 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
99 index 7929fe7..f75afae 100644\r
100 --- a/lib/notmuch.h\r
101 +++ b/lib/notmuch.h\r
102 @@ -449,6 +449,13 @@ typedef enum {\r
103  const char *\r
104  notmuch_query_get_query_string (notmuch_query_t *query);\r
105  \r
106 +/* Specify whether to results should omit the excluded results rather\r
107 + * than just marking them excluded. This is useful for passing a\r
108 + * notmuch_messages_t not containing the excluded messages to other\r
109 + * functions. */\r
110 +void\r
111 +notmuch_query_set_omit_excluded_messages (notmuch_query_t *query, notmuch_bool_t omit);\r
112 +\r
113  /* Specify the sorting desired for this query. */\r
114  void\r
115  notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort);\r
116 @@ -895,7 +902,8 @@ notmuch_message_get_filenames (notmuch_message_t *message);\r
117  \r
118  /* Message flags */\r
119  typedef enum _notmuch_message_flag {\r
120 -    NOTMUCH_MESSAGE_FLAG_MATCH\r
121 +    NOTMUCH_MESSAGE_FLAG_MATCH,\r
122 +    NOTMUCH_MESSAGE_FLAG_EXCLUDED\r
123  } notmuch_message_flag_t;\r
124  \r
125  /* Get a value of a flag for the email corresponding to 'message'. */\r
126 diff --git a/lib/query.cc b/lib/query.cc\r
127 index c25b301..ef2a11f 100644\r
128 --- a/lib/query.cc\r
129 +++ b/lib/query.cc\r
130 @@ -28,6 +28,7 @@ struct _notmuch_query {\r
131      const char *query_string;\r
132      notmuch_sort_t sort;\r
133      notmuch_string_list_t *exclude_terms;\r
134 +    notmuch_bool_t omit_excluded_messages;\r
135  };\r
136  \r
137  typedef struct _notmuch_mset_messages {\r
138 @@ -57,6 +58,12 @@ struct visible _notmuch_threads {\r
139      notmuch_doc_id_set_t match_set;\r
140  };\r
141  \r
142 +/* We need this in the message functions so forward declare. */\r
143 +static notmuch_bool_t\r
144 +_notmuch_doc_id_set_init (void *ctx,\r
145 +                         notmuch_doc_id_set_t *doc_ids,\r
146 +                         GArray *arr);\r
147 +\r
148  notmuch_query_t *\r
149  notmuch_query_create (notmuch_database_t *notmuch,\r
150                       const char *query_string)\r
151 @@ -79,6 +86,8 @@ notmuch_query_create (notmuch_database_t *notmuch,\r
152  \r
153      query->exclude_terms = _notmuch_string_list_create (query);\r
154  \r
155 +    query->omit_excluded_messages = FALSE;\r
156 +\r
157      return query;\r
158  }\r
159  \r
160 @@ -89,6 +98,12 @@ notmuch_query_get_query_string (notmuch_query_t *query)\r
161  }\r
162  \r
163  void\r
164 +notmuch_query_set_omit_excluded_messages (notmuch_query_t *query, notmuch_bool_t omit)\r
165 +{\r
166 +    query->omit_excluded_messages = omit;\r
167 +}\r
168 +\r
169 +void\r
170  notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort)\r
171  {\r
172      query->sort = sort;\r
173 @@ -124,8 +139,9 @@ _notmuch_messages_destructor (notmuch_mset_messages_t *messages)\r
174  \r
175  /* Return a query that matches messages with the excluded tags\r
176   * registered with query.  Any tags that explicitly appear in xquery\r
177 - * will not be excluded. The caller of this function has to combine\r
178 - * the returned query appropriately.*/\r
179 + * will not be excluded, and will be removed from the list of exclude\r
180 + * tags.  The caller of this function has to combine the returned\r
181 + * query appropriately.*/\r
182  static Xapian::Query\r
183  _notmuch_exclude_tags (notmuch_query_t *query, Xapian::Query xquery)\r
184  {\r
185 @@ -142,6 +158,8 @@ _notmuch_exclude_tags (notmuch_query_t *query, Xapian::Query xquery)\r
186         if (it == end)\r
187             exclude_query = Xapian::Query (Xapian::Query::OP_OR,\r
188                                     exclude_query, Xapian::Query (term->string));\r
189 +       else\r
190 +           term->string = talloc_strdup (query, "");\r
191      }\r
192      return exclude_query;\r
193  }\r
194 @@ -173,6 +191,7 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
195                                                    "mail"));\r
196         Xapian::Query string_query, final_query, exclude_query;\r
197         Xapian::MSet mset;\r
198 +       Xapian::MSetIterator iterator;\r
199         unsigned int flags = (Xapian::QueryParser::FLAG_BOOLEAN |\r
200                               Xapian::QueryParser::FLAG_PHRASE |\r
201                               Xapian::QueryParser::FLAG_LOVEHATE |\r
202 @@ -190,11 +209,35 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
203             final_query = Xapian::Query (Xapian::Query::OP_AND,\r
204                                          mail_query, string_query);\r
205         }\r
206 +       messages->base.excluded_doc_ids = NULL;\r
207 +\r
208 +       if (query->exclude_terms) {\r
209 +           exclude_query = _notmuch_exclude_tags (query, final_query);\r
210 +           exclude_query = Xapian::Query (Xapian::Query::OP_AND,\r
211 +                                          exclude_query, final_query);\r
212 +\r
213 +           if (query->omit_excluded_messages)\r
214 +               final_query = Xapian::Query (Xapian::Query::OP_AND_NOT,\r
215 +                                            final_query, exclude_query);\r
216 +           else {\r
217 +               enquire.set_weighting_scheme (Xapian::BoolWeight());\r
218 +               enquire.set_query (exclude_query);\r
219 +\r
220 +               mset = enquire.get_mset (0, notmuch->xapian_db->get_doccount ());\r
221 +\r
222 +               GArray *excluded_doc_ids = g_array_new (FALSE, FALSE, sizeof (unsigned int));\r
223 +\r
224 +               for (iterator = mset.begin (); iterator != mset.end (); iterator++) {\r
225 +                   unsigned int doc_id = *iterator;\r
226 +                   g_array_append_val (excluded_doc_ids, doc_id);\r
227 +               }\r
228 +               messages->base.excluded_doc_ids = talloc (messages, _notmuch_doc_id_set);\r
229 +               _notmuch_doc_id_set_init (query, messages->base.excluded_doc_ids,\r
230 +                                         excluded_doc_ids);\r
231 +               g_array_unref (excluded_doc_ids);\r
232 +           }\r
233 +       }\r
234  \r
235 -       exclude_query = _notmuch_exclude_tags (query, final_query);\r
236 -\r
237 -       final_query = Xapian::Query (Xapian::Query::OP_AND_NOT,\r
238 -                                        final_query, exclude_query);\r
239  \r
240         enquire.set_weighting_scheme (Xapian::BoolWeight());\r
241  \r
242 @@ -283,6 +326,10 @@ _notmuch_mset_messages_get (notmuch_messages_t *messages)\r
243         INTERNAL_ERROR ("a messages iterator contains a non-existent document ID.\n");\r
244      }\r
245  \r
246 +    if (messages->excluded_doc_ids &&\r
247 +       _notmuch_doc_id_set_contains (messages->excluded_doc_ids, doc_id))\r
248 +       notmuch_message_set_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED, TRUE);\r
249 +\r
250      return message;\r
251  }\r
252  \r
253 -- \r
254 1.7.2.3\r
255 \r