[PATCH 4/4] Update NEWS for user.other_name
[notmuch-archives.git] / 8a / 9ccb0bb6f0ad80bc0f320af15dd6fd8067ab71
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 9BB8B431FDE\r
6         for <notmuch@notmuchmail.org>; Mon,  7 Oct 2013 15:33:47 -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.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 58lZ3rNuRgbQ for <notmuch@notmuchmail.org>;\r
16         Mon,  7 Oct 2013 15:33:42 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-5.mit.edu (dmz-mailsec-scanner-5.mit.edu\r
18         [18.7.68.34])\r
19         by olra.theworths.org (Postfix) with ESMTP id DB51B431FC0\r
20         for <notmuch@notmuchmail.org>; Mon,  7 Oct 2013 15:33:30 -0700 (PDT)\r
21 X-AuditID: 12074422-b7f5a8e000000a34-86-525336badede\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
23         by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 4C.F6.02612.AB633525; Mon,  7 Oct 2013 18:33:30 -0400 (EDT)\r
25 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
26         by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id r97MXTQg024746; \r
27         Mon, 7 Oct 2013 18:33:30 -0400\r
28 Received: from drake.dyndns.org (26-4-172.dynamic.csail.mit.edu [18.26.4.172])\r
29         (authenticated bits=0)\r
30         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
31         by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id r97MXSjP028592\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Mon, 7 Oct 2013 18:33:29 -0400\r
34 Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
35         (envelope-from <amdragon@mit.edu>)\r
36         id 1VTJMh-0006c2-NK; Mon, 07 Oct 2013 18:33:23 -0400\r
37 From: Austin Clements <amdragon@MIT.EDU>\r
38 To: notmuch@notmuchmail.org\r
39 Subject: [PATCH 08/11] search: Add stable queries to thread search results\r
40 Date: Mon,  7 Oct 2013 18:33:18 -0400\r
41 Message-Id: <1381185201-25197-9-git-send-email-amdragon@mit.edu>\r
42 X-Mailer: git-send-email 1.8.4.rc3\r
43 In-Reply-To: <1381185201-25197-1-git-send-email-amdragon@mit.edu>\r
44 References: <1381185201-25197-1-git-send-email-amdragon@mit.edu>\r
45 MIME-Version: 1.0\r
46 Content-Type: text/plain; charset=UTF-8\r
47 Content-Transfer-Encoding: 8bit\r
48 X-Brightmail-Tracker:\r
49  H4sIAAAAAAAAA+NgFvrOIsWRmVeSWpSXmKPExsUixG6nrrvLLDjI4Nh6TYvrN2cyOzB6PFt1\r
50         izmAMYrLJiU1J7MstUjfLoEr4/9+rYKLbhUTp29ga2A8aNHFyMkhIWAicfdzJwuELSZx4d56\r
51         ti5GLg4hgX2MEvfutrFDOBsYJT41z2aEcA4zSRzYehisRUhgLqPEjUteIDabgIbEtv3LGUFs\r
52         EQFpiZ13Z7N2MXJwMAuoSfzpUgEJCwt4Sax5uRmslUVAVeLPwr2sIDavgIPEiu/vGSGuUJJY\r
53         eGobWJxTwFFiycaLbBCrHCTm7l8EVS8ocXLmExaI8eoS6+cJgYSZBeQlmrfOZp7AKDQLSdUs\r
54         hKpZSKoWMDKvYpRNya3SzU3MzClOTdYtTk7My0st0jXVy80s0UtNKd3ECA5fF6UdjD8PKh1i\r
55         FOBgVOLhzTgaFCTEmlhWXJl7iFGSg0lJlPeMaXCQEF9SfkplRmJxRnxRaU5q8SFGCQ5mJRFe\r
56         ASOgHG9KYmVValE+TEqag0VJnPcWh32QkEB6YklqdmpqQWoRTFaGg0NJgjcMZKhgUWp6akVa\r
57         Zk4JQpqJgxNkOA/Q8FsgNbzFBYm5xZnpEPlTjIpS4rx3QBICIImM0jy4Xlh6ecUoDvSKMO9n\r
58         kCoeYGqC634FNJgJaLAueyDI4JJEhJRUA2OD7olNky5dLfG6OuetLLNotm3+pCeT5FwYk71l\r
59         GxPz3BQsneOivpjk3xWzsYuutfSaX7Pmn6l9m8eHtPBU+3oGi9xFZV48lu7Cu+bJl309fpz9\r
60         9tVfE6+fTH0m8PDv1Oie+Bn/HwWF7LsUJh9266Pc4sCErBk7Z32/reg3x2X1Gj4Ns4jiQ0os\r
61         xRmJhlrMRcWJAAaIyOwKAwAA\r
62 X-BeenThere: notmuch@notmuchmail.org\r
63 X-Mailman-Version: 2.1.13\r
64 Precedence: list\r
65 List-Id: "Use and development of the notmuch mail system."\r
66         <notmuch.notmuchmail.org>\r
67 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
68         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
69 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
70 List-Post: <mailto:notmuch@notmuchmail.org>\r
71 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
72 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
73         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
74 X-List-Received-Date: Mon, 07 Oct 2013 22:33:48 -0000\r
75 \r
76 These queries will match exactly the set of messages currently in the\r
77 thread, even if more messages later arrive.  Two queries are provided:\r
78 one for matched messages and one for unmatched messages.\r
79 \r
80 This can be used to fix race conditions with tagging threads from\r
81 search results.  While tagging based on a thread: query can affect\r
82 messages that arrived after the search, tagging based on stable\r
83 queries affects only the messages the user was shown in the search UI.\r
84 \r
85 Since we want clients to be able to depend on the presence of these\r
86 queries, this ushers in schema version 2.\r
87 ---\r
88  devel/schemata       | 22 +++++++++++++++++--\r
89  notmuch-client.h     |  2 +-\r
90  notmuch-search.c     | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++\r
91  test/json            |  2 ++\r
92  test/missing-headers |  6 ++++--\r
93  test/sexp            |  4 ++--\r
94  6 files changed, 89 insertions(+), 7 deletions(-)\r
95 \r
96 diff --git a/devel/schemata b/devel/schemata\r
97 index cdd0e43..41dc4a6 100644\r
98 --- a/devel/schemata\r
99 +++ b/devel/schemata\r
100 @@ -14,7 +14,17 @@ are interleaved. Keys are printed as keywords (symbols preceded by a\r
101  colon), e.g. (:id "123" :time 54321 :from "foobar"). Null is printed as\r
102  nil, true as t and false as nil.\r
103  \r
104 -This is version 1 of the structured output format.\r
105 +This is version 2 of the structured output format.\r
106 +\r
107 +Version history\r
108 +---------------\r
109 +\r
110 +v1\r
111 +- First versioned schema release.\r
112 +- Added part.content-length and part.content-transfer-encoding fields.\r
113 +\r
114 +v2\r
115 +- Added the thread_summary.query field.\r
116  \r
117  Common non-terminals\r
118  --------------------\r
119 @@ -145,7 +155,15 @@ thread_summary = {\r
120      authors:        string,   # comma-separated names with | between\r
121                                # matched and unmatched\r
122      subject:        string,\r
123 -    tags:           [string*]\r
124 +    tags:           [string*],\r
125 +\r
126 +    # Two stable query strings identifying exactly the matched and\r
127 +    # unmatched messages currently in this thread.  The messages\r
128 +    # matched by these queries will not change even if more messages\r
129 +    # arrive in the thread.  If there are no matched or unmatched\r
130 +    # messages, the corresponding query will be null (there is no\r
131 +    # query that matches nothing).  (Added in schema version 2.)\r
132 +    query:          [string|null, string|null],\r
133  }\r
134  \r
135  notmuch reply schema\r
136 diff --git a/notmuch-client.h b/notmuch-client.h\r
137 index 8d986f4..1b14910 100644\r
138 --- a/notmuch-client.h\r
139 +++ b/notmuch-client.h\r
140 @@ -138,7 +138,7 @@ chomp_newline (char *str)\r
141   * this.  New (required) map fields can be added without increasing\r
142   * this.\r
143   */\r
144 -#define NOTMUCH_FORMAT_CUR 1\r
145 +#define NOTMUCH_FORMAT_CUR 2\r
146  /* The minimum supported structured output format version.  Requests\r
147   * for format versions below this will return an error. */\r
148  #define NOTMUCH_FORMAT_MIN 1\r
149 diff --git a/notmuch-search.c b/notmuch-search.c\r
150 index d9d39ec..1d14651 100644\r
151 --- a/notmuch-search.c\r
152 +++ b/notmuch-search.c\r
153 @@ -20,6 +20,7 @@\r
154  \r
155  #include "notmuch-client.h"\r
156  #include "sprinter.h"\r
157 +#include "string-util.h"\r
158  \r
159  typedef enum {\r
160      OUTPUT_SUMMARY,\r
161 @@ -46,6 +47,46 @@ sanitize_string (const void *ctx, const char *str)\r
162      return out;\r
163  }\r
164  \r
165 +/* Return two stable query strings that identify exactly the matched\r
166 + * and unmatched messages currently in thread.  If there are no\r
167 + * matched or unmatched messages, the returned buffers will be\r
168 + * NULL. */\r
169 +static int\r
170 +get_thread_query (notmuch_thread_t *thread,\r
171 +                 char **matched_out, char **unmached_out)\r
172 +{\r
173 +    notmuch_messages_t *messages;\r
174 +    char *escaped = NULL;\r
175 +    size_t escaped_len = 0;\r
176 +\r
177 +    *matched_out = *unmached_out = NULL;\r
178 +\r
179 +    for (messages = notmuch_thread_get_messages (thread);\r
180 +        notmuch_messages_valid (messages);\r
181 +        notmuch_messages_move_to_next (messages))\r
182 +    {\r
183 +       notmuch_message_t *message = notmuch_messages_get (messages);\r
184 +       const char *mid = notmuch_message_get_message_id (message);\r
185 +       /* Determine which query buffer to extend */\r
186 +       char **buf = notmuch_message_get_flag (\r
187 +           message, NOTMUCH_MESSAGE_FLAG_MATCH) ? matched_out : unmached_out;\r
188 +       /* Allocate the query buffer is this is the first message */\r
189 +       if (!*buf && (*buf = talloc_strdup (thread, "")) == NULL)\r
190 +           return -1;\r
191 +       /* Add this message's id: query.  Since "id" is an exclusive\r
192 +        * prefix, it is implicitly 'or'd together, so we only need to\r
193 +        * join queries with a space. */\r
194 +       if (make_boolean_term (thread, "id", mid, &escaped, &escaped_len) < 0)\r
195 +           return -1;\r
196 +       *buf = talloc_asprintf_append_buffer (\r
197 +           *buf, "%s%s", **buf ? " " : "", escaped);\r
198 +       if (!*buf)\r
199 +           return -1;\r
200 +    }\r
201 +    talloc_free (escaped);\r
202 +    return 0;\r
203 +}\r
204 +\r
205  static int\r
206  do_search_threads (sprinter_t *format,\r
207                    notmuch_query_t *query,\r
208 @@ -131,6 +172,25 @@ do_search_threads (sprinter_t *format,\r
209                 format->string (format, authors);\r
210                 format->map_key (format, "subject");\r
211                 format->string (format, subject);\r
212 +               if (notmuch_format_version >= 2) {\r
213 +                   char *matched_query, *unmatched_query;\r
214 +                   if (get_thread_query (thread, &matched_query,\r
215 +                                         &unmatched_query) < 0) {\r
216 +                       fprintf (stderr, "Out of memory\n");\r
217 +                       return 1;\r
218 +                   }\r
219 +                   format->map_key (format, "query");\r
220 +                   format->begin_list (format);\r
221 +                   if (matched_query)\r
222 +                       format->string (format, matched_query);\r
223 +                   else\r
224 +                       format->null (format);\r
225 +                   if (unmatched_query)\r
226 +                       format->string (format, unmatched_query);\r
227 +                   else\r
228 +                       format->null (format);\r
229 +                   format->end (format);\r
230 +               }\r
231             }\r
232  \r
233             talloc_free (ctx_quote);\r
234 diff --git a/test/json b/test/json\r
235 index b87b7f6..e07a290 100755\r
236 --- a/test/json\r
237 +++ b/test/json\r
238 @@ -26,6 +26,7 @@ test_expect_equal_json "$output" "[{\"thread\": \"XXX\",\r
239   \"total\": 1,\r
240   \"authors\": \"Notmuch Test Suite\",\r
241   \"subject\": \"json-search-subject\",\r
242 + \"query\": [\"id:$gen_msg_id\", null],\r
243   \"tags\": [\"inbox\",\r
244   \"unread\"]}]"\r
245  \r
246 @@ -59,6 +60,7 @@ test_expect_equal_json "$output" "[{\"thread\": \"XXX\",\r
247   \"total\": 1,\r
248   \"authors\": \"Notmuch Test Suite\",\r
249   \"subject\": \"json-search-utf8-body-sübjéct\",\r
250 + \"query\": [\"id:$gen_msg_id\", null],\r
251   \"tags\": [\"inbox\",\r
252   \"unread\"]}]"\r
253  \r
254 diff --git a/test/missing-headers b/test/missing-headers\r
255 index f14b878..43e861b 100755\r
256 --- a/test/missing-headers\r
257 +++ b/test/missing-headers\r
258 @@ -43,7 +43,8 @@ test_expect_equal_json "$output" '\r
259          ],\r
260          "thread": "XXX",\r
261          "timestamp": 978709437,\r
262 -        "total": 1\r
263 +        "total": 1,\r
264 +        "query": ["id:notmuch-sha1-7a6e4eac383ef958fcd3ebf2143db71b8ff01161", null]\r
265      },\r
266      {\r
267          "authors": "Notmuch Test Suite",\r
268 @@ -56,7 +57,8 @@ test_expect_equal_json "$output" '\r
269          ],\r
270          "thread": "XXX",\r
271          "timestamp": 0,\r
272 -        "total": 1\r
273 +        "total": 1,\r
274 +        "query": ["id:notmuch-sha1-ca55943aff7a72baf2ab21fa74fab3d632401334", null]\r
275      }\r
276  ]'\r
277  \r
278 diff --git a/test/sexp b/test/sexp\r
279 index 492a82f..be815e1 100755\r
280 --- a/test/sexp\r
281 +++ b/test/sexp\r
282 @@ -19,7 +19,7 @@ test_expect_equal "$output" "((((:id \"${gen_msg_id}\" :match t :excluded nil :f\r
283  test_begin_subtest "Search message: sexp"\r
284  add_message "[subject]=\"sexp-search-subject\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"sexp-search-message\""\r
285  output=$(notmuch search --format=sexp "sexp-search-message" | notmuch_search_sanitize)\r
286 -test_expect_equal "$output" "((:thread \"0000000000000002\" :timestamp 946728000 :date_relative \"2000-01-01\" :matched 1 :total 1 :authors \"Notmuch Test Suite\" :subject \"sexp-search-subject\" :tags (\"inbox\" \"unread\")))"\r
287 +test_expect_equal "$output" "((:thread \"0000000000000002\" :timestamp 946728000 :date_relative \"2000-01-01\" :matched 1 :total 1 :authors \"Notmuch Test Suite\" :subject \"sexp-search-subject\" :query (\"id:$gen_msg_id\" nil) :tags (\"inbox\" \"unread\")))"\r
288  \r
289  test_begin_subtest "Show message: sexp, utf-8"\r
290  add_message "[subject]=\"sexp-show-utf8-body-sübjéct\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"jsön-show-méssage\""\r
291 @@ -44,7 +44,7 @@ test_expect_equal "$output" "((((:id \"$id\" :match t :excluded nil :filename \"\r
292  test_begin_subtest "Search message: sexp, utf-8"\r
293  add_message "[subject]=\"sexp-search-utf8-body-sübjéct\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"jsön-search-méssage\""\r
294  output=$(notmuch search --format=sexp "jsön-search-méssage" | notmuch_search_sanitize)\r
295 -test_expect_equal "$output" "((:thread \"0000000000000005\" :timestamp 946728000 :date_relative \"2000-01-01\" :matched 1 :total 1 :authors \"Notmuch Test Suite\" :subject \"sexp-search-utf8-body-sübjéct\" :tags (\"inbox\" \"unread\")))"\r
296 +test_expect_equal "$output" "((:thread \"0000000000000005\" :timestamp 946728000 :date_relative \"2000-01-01\" :matched 1 :total 1 :authors \"Notmuch Test Suite\" :subject \"sexp-search-utf8-body-sübjéct\" :query (\"id:$gen_msg_id\" nil) :tags (\"inbox\" \"unread\")))"\r
297  \r
298  \r
299  test_done\r
300 -- \r
301 1.8.4.rc3\r
302 \r