]> rtime.felk.cvut.cz Git - notmuch.git/blob - notmuch-search.c
cli: search: Add --output=count
[notmuch.git] / notmuch-search.c
1 /* notmuch - Not much of an email program, (just index and search)
2  *
3  * Copyright © 2009 Carl Worth
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see http://www.gnu.org/licenses/ .
17  *
18  * Author: Carl Worth <cworth@cworth.org>
19  */
20
21 #include "notmuch-client.h"
22 #include "sprinter.h"
23 #include "string-util.h"
24
25 typedef enum {
26     OUTPUT_SUMMARY      = 1 << 0,
27     OUTPUT_THREADS      = 1 << 1,
28     OUTPUT_MESSAGES     = 1 << 2,
29     OUTPUT_FILES        = 1 << 3,
30     OUTPUT_TAGS         = 1 << 4,
31     OUTPUT_SENDER       = 1 << 5,
32     OUTPUT_RECIPIENTS   = 1 << 6,
33     OUTPUT_COUNT        = 1 << 7,
34 } output_t;
35
36 #define OUTPUT_ADDRESS_FLAGS (OUTPUT_SENDER | OUTPUT_RECIPIENTS | OUTPUT_COUNT)
37
38 typedef enum {
39     FILTER_BY_NAMEADDR = 0,
40     FILTER_BY_NAME,
41     FILTER_BY_ADDR,
42     FILTER_BY_ADDRFOLD,
43     FILTER_BY_NAMEADDRFOLD,
44 } filter_by_t;
45
46 typedef struct {
47     sprinter_t *format;
48     notmuch_query_t *query;
49     notmuch_sort_t sort;
50     output_t output;
51     int offset;
52     int limit;
53     int dupe;
54     filter_by_t filter_by;
55 } search_options_t;
56
57 typedef struct {
58     const char *name;
59     const char *addr;
60     int count;
61 } mailbox_t;
62
63 /* Return two stable query strings that identify exactly the matched
64  * and unmatched messages currently in thread.  If there are no
65  * matched or unmatched messages, the returned buffers will be
66  * NULL. */
67 static int
68 get_thread_query (notmuch_thread_t *thread,
69                   char **matched_out, char **unmatched_out)
70 {
71     notmuch_messages_t *messages;
72     char *escaped = NULL;
73     size_t escaped_len = 0;
74
75     *matched_out = *unmatched_out = NULL;
76
77     for (messages = notmuch_thread_get_messages (thread);
78          notmuch_messages_valid (messages);
79          notmuch_messages_move_to_next (messages))
80     {
81         notmuch_message_t *message = notmuch_messages_get (messages);
82         const char *mid = notmuch_message_get_message_id (message);
83         /* Determine which query buffer to extend */
84         char **buf = notmuch_message_get_flag (
85             message, NOTMUCH_MESSAGE_FLAG_MATCH) ? matched_out : unmatched_out;
86         /* Add this message's id: query.  Since "id" is an exclusive
87          * prefix, it is implicitly 'or'd together, so we only need to
88          * join queries with a space. */
89         if (make_boolean_term (thread, "id", mid, &escaped, &escaped_len) < 0)
90             return -1;
91         if (*buf)
92             *buf = talloc_asprintf_append_buffer (*buf, " %s", escaped);
93         else
94             *buf = talloc_strdup (thread, escaped);
95         if (!*buf)
96             return -1;
97     }
98     talloc_free (escaped);
99     return 0;
100 }
101
102 static int
103 do_search_threads (search_options_t *opt)
104 {
105     notmuch_thread_t *thread;
106     notmuch_threads_t *threads;
107     notmuch_tags_t *tags;
108     sprinter_t *format = opt->format;
109     time_t date;
110     int i;
111
112     if (opt->offset < 0) {
113         opt->offset += notmuch_query_count_threads (opt->query);
114         if (opt->offset < 0)
115             opt->offset = 0;
116     }
117
118     threads = notmuch_query_search_threads (opt->query);
119     if (threads == NULL)
120         return 1;
121
122     format->begin_list (format);
123
124     for (i = 0;
125          notmuch_threads_valid (threads) && (opt->limit < 0 || i < opt->offset + opt->limit);
126          notmuch_threads_move_to_next (threads), i++)
127     {
128         thread = notmuch_threads_get (threads);
129
130         if (i < opt->offset) {
131             notmuch_thread_destroy (thread);
132             continue;
133         }
134
135         if (opt->output == OUTPUT_THREADS) {
136             format->set_prefix (format, "thread");
137             format->string (format,
138                             notmuch_thread_get_thread_id (thread));
139             format->separator (format);
140         } else { /* output == OUTPUT_SUMMARY */
141             void *ctx_quote = talloc_new (thread);
142             const char *authors = notmuch_thread_get_authors (thread);
143             const char *subject = notmuch_thread_get_subject (thread);
144             const char *thread_id = notmuch_thread_get_thread_id (thread);
145             int matched = notmuch_thread_get_matched_messages (thread);
146             int total = notmuch_thread_get_total_messages (thread);
147             const char *relative_date = NULL;
148             notmuch_bool_t first_tag = TRUE;
149
150             format->begin_map (format);
151
152             if (opt->sort == NOTMUCH_SORT_OLDEST_FIRST)
153                 date = notmuch_thread_get_oldest_date (thread);
154             else
155                 date = notmuch_thread_get_newest_date (thread);
156
157             relative_date = notmuch_time_relative_date (ctx_quote, date);
158
159             if (format->is_text_printer) {
160                 /* Special case for the text formatter */
161                 printf ("thread:%s %12s [%d/%d] %s; %s (",
162                         thread_id,
163                         relative_date,
164                         matched,
165                         total,
166                         sanitize_string (ctx_quote, authors),
167                         sanitize_string (ctx_quote, subject));
168             } else { /* Structured Output */
169                 format->map_key (format, "thread");
170                 format->string (format, thread_id);
171                 format->map_key (format, "timestamp");
172                 format->integer (format, date);
173                 format->map_key (format, "date_relative");
174                 format->string (format, relative_date);
175                 format->map_key (format, "matched");
176                 format->integer (format, matched);
177                 format->map_key (format, "total");
178                 format->integer (format, total);
179                 format->map_key (format, "authors");
180                 format->string (format, authors);
181                 format->map_key (format, "subject");
182                 format->string (format, subject);
183                 if (notmuch_format_version >= 2) {
184                     char *matched_query, *unmatched_query;
185                     if (get_thread_query (thread, &matched_query,
186                                           &unmatched_query) < 0) {
187                         fprintf (stderr, "Out of memory\n");
188                         return 1;
189                     }
190                     format->map_key (format, "query");
191                     format->begin_list (format);
192                     if (matched_query)
193                         format->string (format, matched_query);
194                     else
195                         format->null (format);
196                     if (unmatched_query)
197                         format->string (format, unmatched_query);
198                     else
199                         format->null (format);
200                     format->end (format);
201                 }
202             }
203
204             talloc_free (ctx_quote);
205
206             format->map_key (format, "tags");
207             format->begin_list (format);
208
209             for (tags = notmuch_thread_get_tags (thread);
210                  notmuch_tags_valid (tags);
211                  notmuch_tags_move_to_next (tags))
212             {
213                 const char *tag = notmuch_tags_get (tags);
214
215                 if (format->is_text_printer) {
216                   /* Special case for the text formatter */
217                     if (first_tag)
218                         first_tag = FALSE;
219                     else
220                         fputc (' ', stdout);
221                     fputs (tag, stdout);
222                 } else { /* Structured Output */
223                     format->string (format, tag);
224                 }
225             }
226
227             if (format->is_text_printer)
228                 printf (")");
229
230             format->end (format);
231             format->end (format);
232             format->separator (format);
233         }
234
235         notmuch_thread_destroy (thread);
236     }
237
238     format->end (format);
239
240     return 0;
241 }
242
243 /* Returns TRUE iff name and/or addr is considered duplicite. */
244 static notmuch_bool_t
245 check_duplicite (const search_options_t *opt, GHashTable *addrs, const char *name, const char *addr)
246 {
247     notmuch_bool_t duplicite;
248     char *key;
249     mailbox_t *mailbox;
250
251     if (opt->filter_by == FILTER_BY_ADDRFOLD ||
252         opt->filter_by == FILTER_BY_NAMEADDRFOLD) {
253         gchar *folded = g_utf8_casefold (addr, -1);
254         addr = talloc_strdup (opt->format, folded);
255         g_free (folded);
256     }
257     switch (opt->filter_by) {
258     case FILTER_BY_NAMEADDR:
259     case FILTER_BY_NAMEADDRFOLD:
260         key = talloc_asprintf (opt->format, "%s <%s>", name, addr);
261         break;
262     case FILTER_BY_NAME:
263         key = talloc_strdup (opt->format, name); /* !name results in !key */
264         break;
265     case FILTER_BY_ADDR:
266     case FILTER_BY_ADDRFOLD:
267         key = talloc_strdup (opt->format, addr);
268         break;
269     default:
270         INTERNAL_ERROR("invalid --filter-by flags");
271     }
272
273     if (opt->filter_by == FILTER_BY_ADDRFOLD ||
274         opt->filter_by == FILTER_BY_NAMEADDRFOLD)
275         talloc_free ((char*)addr);
276
277     if (! key)
278         return FALSE;
279
280     duplicite = g_hash_table_lookup_extended (addrs, key, NULL, (gpointer)&mailbox);
281
282     if (! duplicite) {
283         mailbox = talloc (opt->format, mailbox_t);
284         mailbox->name = talloc_strdup (mailbox, name);
285         mailbox->addr = talloc_strdup (mailbox, addr);
286         mailbox->count = 1;
287         g_hash_table_insert (addrs, key, mailbox);
288     } else {
289         mailbox->count++;
290         talloc_free (key);
291     }
292
293     return duplicite;
294 }
295
296 static void
297 print_mailbox (const search_options_t *opt, const mailbox_t *mailbox)
298 {
299     const char *name = mailbox->name;
300     const char *addr = mailbox->addr;
301     int count = mailbox->count;
302
303     if (opt->format->is_text_printer) {
304         char *mailbox_str;
305
306         if (name && *name)
307             mailbox_str = talloc_asprintf (opt->format, "%s <%s>", name, addr);
308         else
309             mailbox_str = talloc_strdup (opt->format, addr);
310
311         if (! mailbox_str) {
312             fprintf (stderr, "Error: out of memory\n");
313             return;
314         }
315         if (count > 0) {
316             opt->format->integer (opt->format, count);
317             opt->format->string (opt->format, "\t");
318         }
319         opt->format->string (opt->format, mailbox_str);
320         opt->format->separator (opt->format);
321
322         talloc_free (mailbox_str);
323     } else {
324         opt->format->begin_map (opt->format);
325         opt->format->map_key (opt->format, "name");
326         opt->format->string (opt->format, name);
327         opt->format->map_key (opt->format, "address");
328         opt->format->string (opt->format, addr);
329         if (count > 0) {
330             opt->format->map_key (opt->format, "count");
331             opt->format->integer (opt->format, count);
332         }
333         opt->format->end (opt->format);
334         opt->format->separator (opt->format);
335     }
336 }
337
338 static void
339 process_address_list (const search_options_t *opt, GHashTable *addrs,
340                       InternetAddressList *list)
341 {
342     InternetAddress *address;
343     int i;
344
345     for (i = 0; i < internet_address_list_length (list); i++) {
346         address = internet_address_list_get_address (list, i);
347         if (INTERNET_ADDRESS_IS_GROUP (address)) {
348             InternetAddressGroup *group;
349             InternetAddressList *group_list;
350
351             group = INTERNET_ADDRESS_GROUP (address);
352             group_list = internet_address_group_get_members (group);
353             if (group_list == NULL)
354                 continue;
355
356             process_address_list (opt, addrs, group_list);
357         } else {
358             InternetAddressMailbox *mailbox = INTERNET_ADDRESS_MAILBOX (address);
359             mailbox_t mbx = {
360                 .name = internet_address_get_name (address),
361                 .addr = internet_address_mailbox_get_addr (mailbox),
362                 .count = 0,
363             };
364
365             if (check_duplicite (opt, addrs, mbx.name, mbx.addr))
366                 continue;
367
368             if (opt->output & OUTPUT_COUNT)
369                 continue;
370
371             print_mailbox (opt, &mbx);
372         }
373     }
374 }
375
376 static void
377 process_address_header (const search_options_t *opt, GHashTable *addrs, const char *value)
378 {
379     InternetAddressList *list;
380
381     if (value == NULL)
382         return;
383
384     list = internet_address_list_parse_string (value);
385     if (list == NULL)
386         return;
387
388     process_address_list (opt, addrs, list);
389 }
390
391 static void
392 _my_talloc_free_for_g_hash (void *ptr)
393 {
394     talloc_free (ptr);
395 }
396
397 static void
398 print_hash_value (unused (gpointer key), gpointer value, gpointer user_data)
399 {
400     const mailbox_t *mailbox = value;
401     search_options_t *opt = user_data;
402
403     print_mailbox (opt, mailbox);
404 }
405
406 static int
407 do_search_messages (search_options_t *opt)
408 {
409     notmuch_message_t *message;
410     notmuch_messages_t *messages;
411     notmuch_filenames_t *filenames;
412     sprinter_t *format = opt->format;
413     GHashTable *addresses = NULL;
414     int i;
415
416     if (opt->output & OUTPUT_ADDRESS_FLAGS)
417         addresses = g_hash_table_new_full (g_str_hash, g_str_equal,
418                                            _my_talloc_free_for_g_hash, _my_talloc_free_for_g_hash);
419
420     if (opt->offset < 0) {
421         opt->offset += notmuch_query_count_messages (opt->query);
422         if (opt->offset < 0)
423             opt->offset = 0;
424     }
425
426     messages = notmuch_query_search_messages (opt->query);
427     if (messages == NULL)
428         return 1;
429
430     format->begin_list (format);
431
432     for (i = 0;
433          notmuch_messages_valid (messages) && (opt->limit < 0 || i < opt->offset + opt->limit);
434          notmuch_messages_move_to_next (messages), i++)
435     {
436         if (i < opt->offset)
437             continue;
438
439         message = notmuch_messages_get (messages);
440
441         if (opt->output == OUTPUT_FILES) {
442             int j;
443             filenames = notmuch_message_get_filenames (message);
444
445             for (j = 1;
446                  notmuch_filenames_valid (filenames);
447                  notmuch_filenames_move_to_next (filenames), j++)
448             {
449                 if (opt->dupe < 0 || opt->dupe == j) {
450                     format->string (format, notmuch_filenames_get (filenames));
451                     format->separator (format);
452                 }
453             }
454             
455             notmuch_filenames_destroy( filenames );
456
457         } else if (opt->output == OUTPUT_MESSAGES) {
458             format->set_prefix (format, "id");
459             format->string (format,
460                             notmuch_message_get_message_id (message));
461             format->separator (format);
462         } else {
463             if (opt->output & OUTPUT_SENDER) {
464                 const char *addrs;
465
466                 addrs = notmuch_message_get_header (message, "from");
467                 process_address_header (opt, addresses, addrs);
468             }
469
470             if (opt->output & OUTPUT_RECIPIENTS) {
471                 const char *hdrs[] = { "to", "cc", "bcc" };
472                 const char *addrs;
473                 size_t j;
474
475                 for (j = 0; j < ARRAY_SIZE (hdrs); j++) {
476                     addrs = notmuch_message_get_header (message, hdrs[j]);
477                     process_address_header (opt, addresses, addrs);
478                 }
479             }
480         }
481
482         notmuch_message_destroy (message);
483     }
484
485     if (addresses && opt->output & OUTPUT_COUNT)
486         g_hash_table_foreach (addresses, print_hash_value, opt);
487
488     if (addresses)
489         g_hash_table_unref (addresses);
490
491     notmuch_messages_destroy (messages);
492
493     format->end (format);
494
495     return 0;
496 }
497
498 static int
499 do_search_tags (notmuch_database_t *notmuch,
500                 const search_options_t *opt)
501 {
502     notmuch_messages_t *messages = NULL;
503     notmuch_tags_t *tags;
504     const char *tag;
505     sprinter_t *format = opt->format;
506     notmuch_query_t *query = opt->query;
507
508     /* should the following only special case if no excluded terms
509      * specified? */
510
511     /* Special-case query of "*" for better performance. */
512     if (strcmp (notmuch_query_get_query_string (query), "*") == 0) {
513         tags = notmuch_database_get_all_tags (notmuch);
514     } else {
515         messages = notmuch_query_search_messages (query);
516         if (messages == NULL)
517             return 1;
518
519         tags = notmuch_messages_collect_tags (messages);
520     }
521     if (tags == NULL)
522         return 1;
523
524     format->begin_list (format);
525
526     for (;
527          notmuch_tags_valid (tags);
528          notmuch_tags_move_to_next (tags))
529     {
530         tag = notmuch_tags_get (tags);
531
532         format->string (format, tag);
533         format->separator (format);
534
535     }
536
537     notmuch_tags_destroy (tags);
538
539     if (messages)
540         notmuch_messages_destroy (messages);
541
542     format->end (format);
543
544     return 0;
545 }
546
547 int
548 notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
549 {
550     notmuch_database_t *notmuch;
551     search_options_t opt = {
552         .sort = NOTMUCH_SORT_NEWEST_FIRST,
553         .output = 0,
554         .offset = 0,
555         .limit = -1, /* unlimited */
556         .dupe = -1,
557         .filter_by = FILTER_BY_NAMEADDR,
558     };
559     char *query_str;
560     int opt_index, ret;
561     notmuch_exclude_t exclude = NOTMUCH_EXCLUDE_TRUE;
562     unsigned int i;
563
564     enum {
565         NOTMUCH_FORMAT_JSON,
566         NOTMUCH_FORMAT_TEXT,
567         NOTMUCH_FORMAT_TEXT0,
568         NOTMUCH_FORMAT_SEXP
569     } format_sel = NOTMUCH_FORMAT_TEXT;
570
571     notmuch_opt_desc_t options[] = {
572         { NOTMUCH_OPT_KEYWORD, &opt.sort, "sort", 's',
573           (notmuch_keyword_t []){ { "oldest-first", NOTMUCH_SORT_OLDEST_FIRST },
574                                   { "newest-first", NOTMUCH_SORT_NEWEST_FIRST },
575                                   { 0, 0 } } },
576         { NOTMUCH_OPT_KEYWORD, &format_sel, "format", 'f',
577           (notmuch_keyword_t []){ { "json", NOTMUCH_FORMAT_JSON },
578                                   { "sexp", NOTMUCH_FORMAT_SEXP },
579                                   { "text", NOTMUCH_FORMAT_TEXT },
580                                   { "text0", NOTMUCH_FORMAT_TEXT0 },
581                                   { 0, 0 } } },
582         { NOTMUCH_OPT_INT, &notmuch_format_version, "format-version", 0, 0 },
583         { NOTMUCH_OPT_KEYWORD_FLAGS, &opt.output, "output", 'o',
584           (notmuch_keyword_t []){ { "summary", OUTPUT_SUMMARY },
585                                   { "threads", OUTPUT_THREADS },
586                                   { "messages", OUTPUT_MESSAGES },
587                                   { "sender", OUTPUT_SENDER },
588                                   { "recipients", OUTPUT_RECIPIENTS },
589                                   { "files", OUTPUT_FILES },
590                                   { "tags", OUTPUT_TAGS },
591                                   { "count", OUTPUT_COUNT },
592                                   { 0, 0 } } },
593         { NOTMUCH_OPT_KEYWORD, &exclude, "exclude", 'x',
594           (notmuch_keyword_t []){ { "true", NOTMUCH_EXCLUDE_TRUE },
595                                   { "false", NOTMUCH_EXCLUDE_FALSE },
596                                   { "flag", NOTMUCH_EXCLUDE_FLAG },
597                                   { "all", NOTMUCH_EXCLUDE_ALL },
598                                   { 0, 0 } } },
599         { NOTMUCH_OPT_INT, &opt.offset, "offset", 'O', 0 },
600         { NOTMUCH_OPT_INT, &opt.limit, "limit", 'L', 0  },
601         { NOTMUCH_OPT_INT, &opt.dupe, "duplicate", 'D', 0  },
602         { NOTMUCH_OPT_KEYWORD, &opt.filter_by, "filter-by", 'b',
603           (notmuch_keyword_t []){ { "nameaddr", FILTER_BY_NAMEADDR },
604                                   { "name", FILTER_BY_NAME },
605                                   { "addr", FILTER_BY_ADDR },
606                                   { "addrfold", FILTER_BY_ADDRFOLD },
607                                   { "nameaddrfold", FILTER_BY_NAMEADDRFOLD },
608                                   { 0, 0 } } },
609         { 0, 0, 0, 0, 0 }
610     };
611
612     opt_index = parse_arguments (argc, argv, options, 1);
613     if (opt_index < 0)
614         return EXIT_FAILURE;
615
616     if (! opt.output)
617         opt.output = OUTPUT_SUMMARY;
618
619     if (opt.filter_by && !(opt.output & OUTPUT_ADDRESS_FLAGS)) {
620         fprintf (stderr, "Error: --filter-by can only be used with address output.\n");
621         return EXIT_FAILURE;
622     }
623
624     switch (format_sel) {
625     case NOTMUCH_FORMAT_TEXT:
626         opt.format = sprinter_text_create (config, stdout);
627         break;
628     case NOTMUCH_FORMAT_TEXT0:
629         if (opt.output == OUTPUT_SUMMARY) {
630             fprintf (stderr, "Error: --format=text0 is not compatible with --output=summary.\n");
631             return EXIT_FAILURE;
632         }
633         opt.format = sprinter_text0_create (config, stdout);
634         break;
635     case NOTMUCH_FORMAT_JSON:
636         opt.format = sprinter_json_create (config, stdout);
637         break;
638     case NOTMUCH_FORMAT_SEXP:
639         opt.format = sprinter_sexp_create (config, stdout);
640         break;
641     default:
642         /* this should never happen */
643         INTERNAL_ERROR("no output format selected");
644     }
645
646     notmuch_exit_if_unsupported_format ();
647
648     if (notmuch_database_open (notmuch_config_get_database_path (config),
649                                NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch))
650         return EXIT_FAILURE;
651
652     query_str = query_string_from_args (notmuch, argc-opt_index, argv+opt_index);
653     if (query_str == NULL) {
654         fprintf (stderr, "Out of memory.\n");
655         return EXIT_FAILURE;
656     }
657     if (*query_str == '\0') {
658         fprintf (stderr, "Error: notmuch search requires at least one search term.\n");
659         return EXIT_FAILURE;
660     }
661
662     opt.query = notmuch_query_create (notmuch, query_str);
663     if (opt.query == NULL) {
664         fprintf (stderr, "Out of memory\n");
665         return EXIT_FAILURE;
666     }
667
668     notmuch_query_set_sort (opt.query, opt.sort);
669
670     if (exclude == NOTMUCH_EXCLUDE_FLAG && opt.output != OUTPUT_SUMMARY) {
671         /* If we are not doing summary output there is nowhere to
672          * print the excluded flag so fall back on including the
673          * excluded messages. */
674         fprintf (stderr, "Warning: this output format cannot flag excluded messages.\n");
675         exclude = NOTMUCH_EXCLUDE_FALSE;
676     }
677
678     if (exclude != NOTMUCH_EXCLUDE_FALSE) {
679         const char **search_exclude_tags;
680         size_t search_exclude_tags_length;
681
682         search_exclude_tags = notmuch_config_get_search_exclude_tags
683             (config, &search_exclude_tags_length);
684         for (i = 0; i < search_exclude_tags_length; i++)
685             notmuch_query_add_tag_exclude (opt.query, search_exclude_tags[i]);
686         notmuch_query_set_omit_excluded (opt.query, exclude);
687     }
688
689     if (opt.output == OUTPUT_SUMMARY ||
690         opt.output == OUTPUT_THREADS)
691         ret = do_search_threads (&opt);
692     else if (opt.output == OUTPUT_MESSAGES ||
693              opt.output == OUTPUT_FILES ||
694              (opt.output & OUTPUT_ADDRESS_FLAGS && !(opt.output & ~OUTPUT_ADDRESS_FLAGS)))
695         ret = do_search_messages (&opt);
696     else if (opt.output == OUTPUT_TAGS)
697         ret = do_search_tags (notmuch, &opt);
698     else {
699         fprintf (stderr, "Error: the combination of outputs is not supported.\n");
700         ret = 1;
701     }
702
703     notmuch_query_destroy (opt.query);
704     notmuch_database_destroy (notmuch);
705
706     talloc_free (opt.format);
707
708     return ret ? EXIT_FAILURE : EXIT_SUCCESS;
709 }