]> rtime.felk.cvut.cz Git - notmuch.git/blob - notmuch-search.c
cli: search: Add --filter-by option to configure address filtering
[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 duplicate. */
244 static notmuch_bool_t
245 is_duplicate (const search_options_t *opt, GHashTable *addrs, const char *name, const char *addr)
246 {
247     notmuch_bool_t duplicate;
248     char *key;
249     gchar *addrfold = NULL;
250     mailbox_t *mailbox;
251
252     if (opt->filter_by == FILTER_BY_ADDRFOLD ||
253         opt->filter_by == FILTER_BY_NAMEADDRFOLD)
254         addrfold = g_utf8_casefold (addr, -1);
255
256     switch (opt->filter_by) {
257     case FILTER_BY_NAMEADDR:
258         key = talloc_asprintf (opt->format, "%s <%s>", name, addr);
259         break;
260     case FILTER_BY_NAMEADDRFOLD:
261         key = talloc_asprintf (opt->format, "%s <%s>", name, addrfold);
262         break;
263     case FILTER_BY_NAME:
264         key = talloc_strdup (opt->format, name); /* !name results in !key */
265         break;
266     case FILTER_BY_ADDR:
267         key = talloc_strdup (opt->format, addr);
268         break;
269     case FILTER_BY_ADDRFOLD:
270         key = talloc_strdup (opt->format, addrfold);
271         break;
272     default:
273         INTERNAL_ERROR("invalid --filter-by flags");
274     }
275
276     if (addrfold)
277         g_free (addrfold);
278
279     if (! key)
280         return FALSE;
281
282     duplicate = g_hash_table_lookup_extended (addrs, key, NULL, (gpointer)&mailbox);
283
284     if (! duplicate) {
285         mailbox = talloc (opt->format, mailbox_t);
286         mailbox->name = talloc_strdup (mailbox, name);
287         mailbox->addr = talloc_strdup (mailbox, addr);
288         mailbox->count = 1;
289         g_hash_table_insert (addrs, key, mailbox);
290     } else {
291         mailbox->count++;
292         talloc_free (key);
293     }
294
295     return duplicate;
296 }
297
298 static void
299 print_mailbox (const search_options_t *opt, const mailbox_t *mailbox)
300 {
301     const char *name = mailbox->name;
302     const char *addr = mailbox->addr;
303     int count = mailbox->count;
304     sprinter_t *format = opt->format;
305     InternetAddress *ia = internet_address_mailbox_new (name, addr);
306     char *name_addr;
307
308     /* name_addr has the name part quoted if necessary. Compare
309      * 'John Doe <john@doe.com>' vs. '"Doe, John" <john@doe.com>' */
310     name_addr = internet_address_to_string (ia, FALSE);
311
312     if (format->is_text_printer) {
313         if (count > 0) {
314             format->integer (format, count);
315             format->string (format, "\t");
316         }
317         format->string (format, name_addr);
318         format->separator (format);
319     } else {
320         format->begin_map (format);
321         format->map_key (format, "name");
322         format->string (format, name);
323         format->map_key (format, "address");
324         format->string (format, addr);
325         format->map_key (format, "name-addr");
326         format->string (format, name_addr);
327         if (count > 0) {
328             format->map_key (format, "count");
329             format->integer (format, count);
330         }
331         format->end (format);
332         format->separator (format);
333     }
334
335     g_object_unref (ia);
336     g_free (name_addr);
337 }
338
339 /* Print or prepare for printing addresses from InternetAddressList. */
340 static void
341 process_address_list (const search_options_t *opt, GHashTable *addrs,
342                       InternetAddressList *list)
343 {
344     InternetAddress *address;
345     int i;
346
347     for (i = 0; i < internet_address_list_length (list); i++) {
348         address = internet_address_list_get_address (list, i);
349         if (INTERNET_ADDRESS_IS_GROUP (address)) {
350             InternetAddressGroup *group;
351             InternetAddressList *group_list;
352
353             group = INTERNET_ADDRESS_GROUP (address);
354             group_list = internet_address_group_get_members (group);
355             if (group_list == NULL)
356                 continue;
357
358             process_address_list (opt, addrs, group_list);
359         } else {
360             InternetAddressMailbox *mailbox = INTERNET_ADDRESS_MAILBOX (address);
361             mailbox_t mbx = {
362                 .name = internet_address_get_name (address),
363                 .addr = internet_address_mailbox_get_addr (mailbox),
364                 .count = 0,
365             };
366
367             if (is_duplicate (opt, addrs, mbx.name, mbx.addr))
368                 continue;
369
370             if (opt->output & OUTPUT_COUNT)
371                 continue;
372
373             print_mailbox (opt, &mbx);
374         }
375     }
376 }
377
378 /* Print or prepare for printing addresses from a message header. */
379 static void
380 process_address_header (const search_options_t *opt, GHashTable *addrs, const char *value)
381 {
382     InternetAddressList *list;
383
384     if (value == NULL)
385         return;
386
387     list = internet_address_list_parse_string (value);
388     if (list == NULL)
389         return;
390
391     process_address_list (opt, addrs, list);
392
393     g_object_unref (list);
394 }
395
396 static void
397 _my_talloc_free_for_g_hash (void *ptr)
398 {
399     talloc_free (ptr);
400 }
401
402 static void
403 print_hash_value (unused (gpointer key), gpointer value, gpointer user_data)
404 {
405     const mailbox_t *mailbox = value;
406     search_options_t *opt = user_data;
407
408     print_mailbox (opt, mailbox);
409 }
410
411 static int
412 do_search_messages (search_options_t *opt)
413 {
414     notmuch_message_t *message;
415     notmuch_messages_t *messages;
416     notmuch_filenames_t *filenames;
417     sprinter_t *format = opt->format;
418     GHashTable *addresses = NULL;
419     int i;
420
421     if (opt->output & OUTPUT_ADDRESS_FLAGS)
422         addresses = g_hash_table_new_full (g_str_hash, g_str_equal,
423                                            _my_talloc_free_for_g_hash, _my_talloc_free_for_g_hash);
424
425     if (opt->offset < 0) {
426         opt->offset += notmuch_query_count_messages (opt->query);
427         if (opt->offset < 0)
428             opt->offset = 0;
429     }
430
431     messages = notmuch_query_search_messages (opt->query);
432     if (messages == NULL)
433         return 1;
434
435     format->begin_list (format);
436
437     for (i = 0;
438          notmuch_messages_valid (messages) && (opt->limit < 0 || i < opt->offset + opt->limit);
439          notmuch_messages_move_to_next (messages), i++)
440     {
441         if (i < opt->offset)
442             continue;
443
444         message = notmuch_messages_get (messages);
445
446         if (opt->output == OUTPUT_FILES) {
447             int j;
448             filenames = notmuch_message_get_filenames (message);
449
450             for (j = 1;
451                  notmuch_filenames_valid (filenames);
452                  notmuch_filenames_move_to_next (filenames), j++)
453             {
454                 if (opt->dupe < 0 || opt->dupe == j) {
455                     format->string (format, notmuch_filenames_get (filenames));
456                     format->separator (format);
457                 }
458             }
459             
460             notmuch_filenames_destroy( filenames );
461
462         } else if (opt->output == OUTPUT_MESSAGES) {
463             format->set_prefix (format, "id");
464             format->string (format,
465                             notmuch_message_get_message_id (message));
466             format->separator (format);
467         } else {
468             if (opt->output & OUTPUT_SENDER) {
469                 const char *addrs;
470
471                 addrs = notmuch_message_get_header (message, "from");
472                 process_address_header (opt, addresses, addrs);
473             }
474
475             if (opt->output & OUTPUT_RECIPIENTS) {
476                 const char *hdrs[] = { "to", "cc", "bcc" };
477                 const char *addrs;
478                 size_t j;
479
480                 for (j = 0; j < ARRAY_SIZE (hdrs); j++) {
481                     addrs = notmuch_message_get_header (message, hdrs[j]);
482                     process_address_header (opt, addresses, addrs);
483                 }
484             }
485         }
486
487         notmuch_message_destroy (message);
488     }
489
490     if (addresses && opt->output & OUTPUT_COUNT)
491         g_hash_table_foreach (addresses, print_hash_value, opt);
492
493     if (addresses)
494         g_hash_table_unref (addresses);
495
496     notmuch_messages_destroy (messages);
497
498     format->end (format);
499
500     return 0;
501 }
502
503 static int
504 do_search_tags (notmuch_database_t *notmuch,
505                 const search_options_t *opt)
506 {
507     notmuch_messages_t *messages = NULL;
508     notmuch_tags_t *tags;
509     const char *tag;
510     sprinter_t *format = opt->format;
511     notmuch_query_t *query = opt->query;
512
513     /* should the following only special case if no excluded terms
514      * specified? */
515
516     /* Special-case query of "*" for better performance. */
517     if (strcmp (notmuch_query_get_query_string (query), "*") == 0) {
518         tags = notmuch_database_get_all_tags (notmuch);
519     } else {
520         messages = notmuch_query_search_messages (query);
521         if (messages == NULL)
522             return 1;
523
524         tags = notmuch_messages_collect_tags (messages);
525     }
526     if (tags == NULL)
527         return 1;
528
529     format->begin_list (format);
530
531     for (;
532          notmuch_tags_valid (tags);
533          notmuch_tags_move_to_next (tags))
534     {
535         tag = notmuch_tags_get (tags);
536
537         format->string (format, tag);
538         format->separator (format);
539
540     }
541
542     notmuch_tags_destroy (tags);
543
544     if (messages)
545         notmuch_messages_destroy (messages);
546
547     format->end (format);
548
549     return 0;
550 }
551
552 int
553 notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
554 {
555     notmuch_database_t *notmuch;
556     search_options_t opt = {
557         .sort = NOTMUCH_SORT_NEWEST_FIRST,
558         .output = 0,
559         .offset = 0,
560         .limit = -1, /* unlimited */
561         .dupe = -1,
562         .filter_by = FILTER_BY_NAMEADDR,
563     };
564     char *query_str;
565     int opt_index, ret;
566     notmuch_exclude_t exclude = NOTMUCH_EXCLUDE_TRUE;
567     unsigned int i;
568
569     enum {
570         NOTMUCH_FORMAT_JSON,
571         NOTMUCH_FORMAT_TEXT,
572         NOTMUCH_FORMAT_TEXT0,
573         NOTMUCH_FORMAT_SEXP
574     } format_sel = NOTMUCH_FORMAT_TEXT;
575
576     notmuch_opt_desc_t options[] = {
577         { NOTMUCH_OPT_KEYWORD, &opt.sort, "sort", 's',
578           (notmuch_keyword_t []){ { "oldest-first", NOTMUCH_SORT_OLDEST_FIRST },
579                                   { "newest-first", NOTMUCH_SORT_NEWEST_FIRST },
580                                   { 0, 0 } } },
581         { NOTMUCH_OPT_KEYWORD, &format_sel, "format", 'f',
582           (notmuch_keyword_t []){ { "json", NOTMUCH_FORMAT_JSON },
583                                   { "sexp", NOTMUCH_FORMAT_SEXP },
584                                   { "text", NOTMUCH_FORMAT_TEXT },
585                                   { "text0", NOTMUCH_FORMAT_TEXT0 },
586                                   { 0, 0 } } },
587         { NOTMUCH_OPT_INT, &notmuch_format_version, "format-version", 0, 0 },
588         { NOTMUCH_OPT_KEYWORD_FLAGS, &opt.output, "output", 'o',
589           (notmuch_keyword_t []){ { "summary", OUTPUT_SUMMARY },
590                                   { "threads", OUTPUT_THREADS },
591                                   { "messages", OUTPUT_MESSAGES },
592                                   { "sender", OUTPUT_SENDER },
593                                   { "recipients", OUTPUT_RECIPIENTS },
594                                   { "files", OUTPUT_FILES },
595                                   { "tags", OUTPUT_TAGS },
596                                   { "count", OUTPUT_COUNT },
597                                   { 0, 0 } } },
598         { NOTMUCH_OPT_KEYWORD, &exclude, "exclude", 'x',
599           (notmuch_keyword_t []){ { "true", NOTMUCH_EXCLUDE_TRUE },
600                                   { "false", NOTMUCH_EXCLUDE_FALSE },
601                                   { "flag", NOTMUCH_EXCLUDE_FLAG },
602                                   { "all", NOTMUCH_EXCLUDE_ALL },
603                                   { 0, 0 } } },
604         { NOTMUCH_OPT_INT, &opt.offset, "offset", 'O', 0 },
605         { NOTMUCH_OPT_INT, &opt.limit, "limit", 'L', 0  },
606         { NOTMUCH_OPT_INT, &opt.dupe, "duplicate", 'D', 0  },
607         { NOTMUCH_OPT_KEYWORD, &opt.filter_by, "filter-by", 'b',
608           (notmuch_keyword_t []){ { "nameaddr", FILTER_BY_NAMEADDR },
609                                   { "name", FILTER_BY_NAME },
610                                   { "addr", FILTER_BY_ADDR },
611                                   { "addrfold", FILTER_BY_ADDRFOLD },
612                                   { "nameaddrfold", FILTER_BY_NAMEADDRFOLD },
613                                   { 0, 0 } } },
614         { 0, 0, 0, 0, 0 }
615     };
616
617     opt_index = parse_arguments (argc, argv, options, 1);
618     if (opt_index < 0)
619         return EXIT_FAILURE;
620
621     if (! opt.output)
622         opt.output = OUTPUT_SUMMARY;
623
624     if (opt.filter_by && !(opt.output & OUTPUT_ADDRESS_FLAGS)) {
625         fprintf (stderr, "Error: --filter-by can only be used with address output.\n");
626         return EXIT_FAILURE;
627     }
628
629     switch (format_sel) {
630     case NOTMUCH_FORMAT_TEXT:
631         opt.format = sprinter_text_create (config, stdout);
632         break;
633     case NOTMUCH_FORMAT_TEXT0:
634         if (opt.output == OUTPUT_SUMMARY) {
635             fprintf (stderr, "Error: --format=text0 is not compatible with --output=summary.\n");
636             return EXIT_FAILURE;
637         }
638         opt.format = sprinter_text0_create (config, stdout);
639         break;
640     case NOTMUCH_FORMAT_JSON:
641         opt.format = sprinter_json_create (config, stdout);
642         break;
643     case NOTMUCH_FORMAT_SEXP:
644         opt.format = sprinter_sexp_create (config, stdout);
645         break;
646     default:
647         /* this should never happen */
648         INTERNAL_ERROR("no output format selected");
649     }
650
651     notmuch_exit_if_unsupported_format ();
652
653     if (notmuch_database_open (notmuch_config_get_database_path (config),
654                                NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch))
655         return EXIT_FAILURE;
656
657     query_str = query_string_from_args (notmuch, argc-opt_index, argv+opt_index);
658     if (query_str == NULL) {
659         fprintf (stderr, "Out of memory.\n");
660         return EXIT_FAILURE;
661     }
662     if (*query_str == '\0') {
663         fprintf (stderr, "Error: notmuch search requires at least one search term.\n");
664         return EXIT_FAILURE;
665     }
666
667     opt.query = notmuch_query_create (notmuch, query_str);
668     if (opt.query == NULL) {
669         fprintf (stderr, "Out of memory\n");
670         return EXIT_FAILURE;
671     }
672
673     notmuch_query_set_sort (opt.query, opt.sort);
674
675     if (exclude == NOTMUCH_EXCLUDE_FLAG && opt.output != OUTPUT_SUMMARY) {
676         /* If we are not doing summary output there is nowhere to
677          * print the excluded flag so fall back on including the
678          * excluded messages. */
679         fprintf (stderr, "Warning: this output format cannot flag excluded messages.\n");
680         exclude = NOTMUCH_EXCLUDE_FALSE;
681     }
682
683     if (exclude != NOTMUCH_EXCLUDE_FALSE) {
684         const char **search_exclude_tags;
685         size_t search_exclude_tags_length;
686
687         search_exclude_tags = notmuch_config_get_search_exclude_tags
688             (config, &search_exclude_tags_length);
689         for (i = 0; i < search_exclude_tags_length; i++)
690             notmuch_query_add_tag_exclude (opt.query, search_exclude_tags[i]);
691         notmuch_query_set_omit_excluded (opt.query, exclude);
692     }
693
694     if (opt.output == OUTPUT_SUMMARY ||
695         opt.output == OUTPUT_THREADS)
696         ret = do_search_threads (&opt);
697     else if (opt.output == OUTPUT_MESSAGES ||
698              opt.output == OUTPUT_FILES ||
699              (opt.output & OUTPUT_ADDRESS_FLAGS && !(opt.output & ~OUTPUT_ADDRESS_FLAGS)))
700         ret = do_search_messages (&opt);
701     else if (opt.output == OUTPUT_TAGS)
702         ret = do_search_tags (notmuch, &opt);
703     else {
704         fprintf (stderr, "Error: the combination of outputs is not supported.\n");
705         ret = 1;
706     }
707
708     notmuch_query_destroy (opt.query);
709     notmuch_database_destroy (notmuch);
710
711     talloc_free (opt.format);
712
713     return ret ? EXIT_FAILURE : EXIT_SUCCESS;
714 }