]> git.notmuchmail.org Git - notmuch/blobdiff - notmuch.c
Add notmuch_thread_get_tags
[notmuch] / notmuch.c
index 5ab155e51f930aad9ed789fd714c6a560b823aa2..bfcc2f6a57800f85cb48de756fd74e093b553a94 100644 (file)
--- a/notmuch.c
+++ b/notmuch.c
@@ -610,6 +610,7 @@ search_command (int argc, char *argv[])
     notmuch_query_t *query;
     notmuch_thread_results_t *results;
     notmuch_thread_t *thread;
+    notmuch_tags_t *tags;
     char *query_str;
     int i;
     notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
@@ -641,9 +642,23 @@ search_command (int argc, char *argv[])
         notmuch_thread_results_has_more (results);
         notmuch_thread_results_advance (results))
     {
+       int first = 1;
+
        thread = notmuch_thread_results_get (results);
 
-       printf ("%s\n", notmuch_thread_get_thread_id (thread));
+       printf ("%s (", notmuch_thread_get_thread_id (thread));
+
+       for (tags = notmuch_thread_get_tags (thread);
+            notmuch_tags_has_more (tags);
+            notmuch_tags_advance (tags))
+       {
+           if (! first)
+               printf (" ");
+           printf ("%s", notmuch_tags_get (tags));
+           first = 0;
+       }
+
+       printf (")\n");
 
        notmuch_thread_destroy (thread);
     }
@@ -668,7 +683,7 @@ show_command (unused (int argc), unused (char *argv[]))
 static int
 dump_command (int argc, char *argv[])
 {
-    FILE *output;
+    FILE *output = NULL;
     notmuch_database_t *notmuch = NULL;
     notmuch_query_t *query;
     notmuch_message_results_t *results;
@@ -735,7 +750,7 @@ dump_command (int argc, char *argv[])
   DONE:
     if (notmuch)
        notmuch_database_close (notmuch);
-    if (output != stdout)
+    if (output && output != stdout)
        fclose (output);
 
     return ret;
@@ -744,7 +759,7 @@ dump_command (int argc, char *argv[])
 static int
 restore_command (int argc, char *argv[])
 {
-    FILE *input;
+    FILE *input = NULL;
     notmuch_database_t *notmuch = NULL;
     char *line = NULL;
     size_t line_size;
@@ -845,6 +860,8 @@ restore_command (int argc, char *argv[])
        free (line);
     if (notmuch)
        notmuch_database_close (notmuch);
+    if (input && input != stdin)
+       fclose (input);
 
     return ret;
 }
@@ -922,11 +939,11 @@ main (int argc, char *argv[])
        strcmp (argv[1], "--help") == 0)
     {
        fprintf (stderr, "The notmuch mail system.\n\n");
+       usage ();
+       return 0;
     } else {
        fprintf (stderr, "Error: Unknown command '%s'\n\n", argv[1]);
+       usage ();
+       return 1;
     }
-    usage ();
-    exit (1);
-
-    return 0;
 }