1 Return-Path: <tomi.ollila@iki.fi>
\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 E15FA431FAF
\r
6 for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 14:30:56 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\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 FiEkWJl2nTP2 for <notmuch@notmuchmail.org>;
\r
16 Sat, 24 Nov 2012 14:30:47 -0800 (PST)
\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])
\r
18 by olra.theworths.org (Postfix) with ESMTP id 0980C431FAE
\r
19 for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 14:30:47 -0800 (PST)
\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])
\r
21 by guru.guru-group.fi (Postfix) with ESMTP id D3BF610010B;
\r
22 Sun, 25 Nov 2012 00:30:43 +0200 (EET)
\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>
\r
24 To: markwalters1009 <markwalters1009@gmail.com>, notmuch@notmuchmail.org
\r
25 Subject: Re: [PATCH v2 6/7] cli: allow search mode to include msg-ids with
\r
27 In-Reply-To: <1353763256-32336-7-git-send-email-markwalters1009@gmail.com>
\r
28 References: <1353763256-32336-1-git-send-email-markwalters1009@gmail.com>
\r
29 <1353763256-32336-7-git-send-email-markwalters1009@gmail.com>
\r
30 User-Agent: Notmuch/0.14+84~g8a199bf (http://notmuchmail.org) Emacs/24.2.1
\r
31 (x86_64-unknown-linux-gnu)
\r
32 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL
\r
33 $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F
\r
34 !)g;OY^,BjTbr)Np:%c_o'jj,Z
\r
35 Date: Sun, 25 Nov 2012 00:30:43 +0200
\r
36 Message-ID: <m2624uk50s.fsf@guru.guru-group.fi>
\r
38 Content-Type: text/plain
\r
39 X-BeenThere: notmuch@notmuchmail.org
\r
40 X-Mailman-Version: 2.1.13
\r
42 List-Id: "Use and development of the notmuch mail system."
\r
43 <notmuch.notmuchmail.org>
\r
44 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
45 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
46 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
47 List-Post: <mailto:notmuch@notmuchmail.org>
\r
48 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
49 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
50 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
51 X-List-Received-Date: Sat, 24 Nov 2012 22:30:57 -0000
\r
53 On Sat, Nov 24 2012, markwalters1009 wrote:
\r
55 > From: Mark Walters <markwalters1009@gmail.com>
\r
57 > This adds a --queries=true option which modifies the summary output of
\r
58 > notmuch search by including two extra query strings with each result:
\r
59 > one query string specifies all matching messages and one query string
\r
60 > all non-matching messages. Currently these are just lists of message
\r
61 > ids joined with " or " but that could change in future.
\r
64 Please see (mostly formatting) comments inline below.
\r
67 > Currently this is not implemented for text format.
\r
69 > notmuch-search.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++---
\r
70 > 1 files changed, 89 insertions(+), 6 deletions(-)
\r
72 > diff --git a/notmuch-search.c b/notmuch-search.c
\r
73 > index 830c4e4..c8fc9a6 100644
\r
74 > --- a/notmuch-search.c
\r
75 > +++ b/notmuch-search.c
\r
76 > @@ -26,7 +26,8 @@ typedef enum {
\r
82 > + OUTPUT_SUMMARY_WITH_QUERIES
\r
86 > @@ -46,6 +47,57 @@ sanitize_string (const void *ctx, const char *str)
\r
90 > +/* This function takes a message id and returns an escaped string
\r
91 > + * which can be used as a Xapian query. This involves prefixing with
\r
92 > + * `id:', putting the id inside double quotes, and doubling any
\r
93 > + * occurence of a double quote in the message id itself.*/
\r
95 > +xapian_escape_id (const void *ctx,
\r
96 > + const char *msg_id)
\r
98 second line indentation, not at '(' level as elsewhere
\r
102 > + char *escaped_msg_id;
\r
103 > + escaped_msg_id = talloc_strdup (ctx, "id:\"");
\r
104 > + for (c=msg_id; *c; c++)
\r
109 > + escaped_msg_id = talloc_asprintf_append (escaped_msg_id, "\"\"");
\r
111 > + escaped_msg_id = talloc_asprintf_append (escaped_msg_id, "%c", *c);
\r
112 > + escaped_msg_id = talloc_asprintf_append (escaped_msg_id, "\"");
\r
113 > + return escaped_msg_id;
\r
116 If Austin sees fit he can comment the O(...) of the addition of msgids
\r
117 to query strings -- it would take quite an overhaul to the functionality
\r
118 if the escaped msgid's were directly written to query string...
\r
122 > +output_msg_query (const void *ctx,
\r
123 > + sprinter_t *format,
\r
124 > + notmuch_bool_t matching,
\r
125 > + notmuch_bool_t first,
\r
126 > + notmuch_messages_t *messages)
\r
128 indentation level above
\r
131 > + notmuch_message_t *message;
\r
132 > + char *query, *escaped_msg_id;
\r
133 > + query = talloc_strdup (ctx, "");
\r
135 > + notmuch_messages_valid (messages);
\r
136 > + notmuch_messages_move_to_next (messages))
\r
138 > + message = notmuch_messages_get (messages);
\r
139 > + if (notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH) == matching) {
\r
140 > + escaped_msg_id = xapian_escape_id (ctx, notmuch_message_get_message_id (message));
\r
142 > + query = talloc_asprintf_append (query, "%s", escaped_msg_id);
\r
146 > + query = talloc_asprintf_append (query, " or %s", escaped_msg_id);
\r
147 > + talloc_free (escaped_msg_id);
\r
149 > + /* output_msg_query already starts with an ` or' */
\r
150 > + query = talloc_asprintf_append (query, "%s", output_msg_query (ctx, format, matching, first, notmuch_message_get_replies (message)));
\r
156 > do_search_threads (sprinter_t *format,
\r
157 > notmuch_query_t *query,
\r
158 > @@ -88,7 +140,7 @@ do_search_threads (sprinter_t *format,
\r
159 > format->string (format,
\r
160 > notmuch_thread_get_thread_id (thread));
\r
161 > format->separator (format);
\r
162 > - } else { /* output == OUTPUT_SUMMARY */
\r
163 > + } else { /* output == OUTPUT_SUMMARY or OUTPUT_SUMMARY_WITH_QUERIES */
\r
164 > void *ctx_quote = talloc_new (thread);
\r
165 > const char *authors = notmuch_thread_get_authors (thread);
\r
166 > const char *subject = notmuch_thread_get_subject (thread);
\r
167 > @@ -108,7 +160,7 @@ do_search_threads (sprinter_t *format,
\r
168 > relative_date = notmuch_time_relative_date (ctx_quote, date);
\r
170 > if (format->is_text_printer) {
\r
171 > - /* Special case for the text formatter */
\r
172 > + /* Special case for the text formatter */
\r
174 irrelevant spacing change
\r
176 > printf ("thread:%s %12s [%d/%d] %s; %s (",
\r
179 > @@ -133,8 +185,6 @@ do_search_threads (sprinter_t *format,
\r
180 > format->string (format, subject);
\r
183 > - talloc_free (ctx_quote);
\r
185 > format->map_key (format, "tags");
\r
186 > format->begin_list (format);
\r
188 > @@ -145,7 +195,7 @@ do_search_threads (sprinter_t *format,
\r
189 > const char *tag = notmuch_tags_get (tags);
\r
191 > if (format->is_text_printer) {
\r
192 > - /* Special case for the text formatter */
\r
193 > + /* Special case for the text formatter */
\r
195 irrelevant spacing change
\r
198 > first_tag = FALSE;
\r
200 > @@ -160,8 +210,25 @@ do_search_threads (sprinter_t *format,
\r
203 > format->end (format);
\r
205 > + if (output == OUTPUT_SUMMARY_WITH_QUERIES) {
\r
207 > + query = output_msg_query (ctx_quote, format, TRUE, TRUE, notmuch_thread_get_toplevel_messages (thread));
\r
208 > + if (strlen (query)) {
\r
209 > + format->map_key (format, "matching_msg_query");
\r
210 > + format->string (format, query);
\r
212 > + query = output_msg_query (ctx_quote, format, FALSE, TRUE, notmuch_thread_get_toplevel_messages (thread));
\r
213 > + if (strlen (query)) {
\r
214 > + format->map_key (format, "nonmatching_msg_query");
\r
215 > + format->string (format, query);
\r
219 > format->end (format);
\r
220 > format->separator (format);
\r
222 > + talloc_free (ctx_quote);
\r
225 > notmuch_thread_destroy (thread);
\r
226 > @@ -303,6 +370,7 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
\r
228 > int limit = -1; /* unlimited */
\r
229 > int exclude = EXCLUDE_TRUE;
\r
230 > + notmuch_bool_t with_queries = FALSE;
\r
233 > enum { NOTMUCH_FORMAT_JSON, NOTMUCH_FORMAT_TEXT }
\r
234 > @@ -323,12 +391,14 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
\r
235 > { "messages", OUTPUT_MESSAGES },
\r
236 > { "files", OUTPUT_FILES },
\r
237 > { "tags", OUTPUT_TAGS },
\r
238 > + { "with-queries", OUTPUT_SUMMARY_WITH_QUERIES },
\r
240 this "with-queries" confuses me -- old version or undocumented feature ?
\r
243 > { NOTMUCH_OPT_KEYWORD, &exclude, "exclude", 'x',
\r
244 > (notmuch_keyword_t []){ { "true", EXCLUDE_TRUE },
\r
245 > { "false", EXCLUDE_FALSE },
\r
246 > { "flag", EXCLUDE_FLAG },
\r
248 > + { NOTMUCH_OPT_BOOLEAN, &with_queries, "queries", 'b', 0 },
\r
249 > { NOTMUCH_OPT_INT, &offset, "offset", 'O', 0 },
\r
250 > { NOTMUCH_OPT_INT, &limit, "limit", 'L', 0 },
\r
251 > { 0, 0, 0, 0, 0 }
\r
252 > @@ -398,6 +468,19 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
\r
253 > notmuch_query_set_omit_excluded (query, FALSE);
\r
256 > + if (with_queries) {
\r
257 > + if (format_sel == NOTMUCH_FORMAT_TEXT) {
\r
258 > + fprintf (stderr, "Warning: --queries=true not implemented for text format.\n");
\r
259 > + with_queries = FALSE;
\r
261 > + if (output != OUTPUT_SUMMARY) {
\r
262 > + fprintf (stderr, "Warning: --queries=true only implemented for --output=summary.\n");
\r
263 > + with_queries = FALSE;
\r
267 > + if (with_queries) output = OUTPUT_SUMMARY_WITH_QUERIES;
\r
269 newline before output = ...
\r
272 > switch (output) {
\r
274 > case OUTPUT_SUMMARY:
\r
278 > _______________________________________________
\r
279 > notmuch mailing list
\r
280 > notmuch@notmuchmail.org
\r
281 > http://notmuchmail.org/mailman/listinfo/notmuch
\r