]> git.notmuchmail.org Git - notmuch/blobdiff - notmuch-search.c
notmuch search: Print the number of matched/total messages for each thread.
[notmuch] / notmuch-search.c
index 38ca75d63ade2582c40db3bf7db6f08ace0d5c68..a0a71bbd7992e02e4f3b42b1bf55939fac0bdc64 100644 (file)
@@ -32,6 +32,33 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
     char *query_str;
     const char *relative_date;
     time_t date;
     char *query_str;
     const char *relative_date;
     time_t date;
+    int i, first = 0, max_threads = -1;
+    char *opt, *end;
+
+    for (i = 0; i < argc && argv[i][0] == '-'; i++) {
+       if (strcmp (argv[i], "--") == 0) {
+           i++;
+           break;
+       }
+       if (STRNCMP_LITERAL (argv[i], "--first=") == 0) {
+           opt = argv[i] + sizeof ("--first=") - 1;
+           first = strtoul (opt, &end, 10);
+           if (*opt == '\0' || *end != '\0') {
+               fprintf (stderr, "Invalid value for --first: %s\n", opt);
+               return 1;
+           }
+       } else if (STRNCMP_LITERAL (argv[i], "--max-threads=") == 0) {
+           opt = argv[i] + sizeof ("--max-threads=") - 1;
+           max_threads = strtoul (opt, &end, 10);
+           if (*opt == '\0' || *end != '\0') {
+               fprintf (stderr, "Invalid value for --max-threads: %s\n", opt);
+               return 1;
+           }
+       }
+    }
+
+    argc -= i;
+    argv += i;
 
     config = notmuch_config_open (ctx, NULL, NULL);
     if (config == NULL)
 
     config = notmuch_config_open (ctx, NULL, NULL);
     if (config == NULL)
@@ -53,7 +80,7 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
        return 1;
     }
 
        return 1;
     }
 
-    for (threads = notmuch_query_search_threads (query);
+    for (threads = notmuch_query_search_threads (query, first, max_threads);
         notmuch_threads_has_more (threads);
         notmuch_threads_advance (threads))
     {
         notmuch_threads_has_more (threads);
         notmuch_threads_advance (threads))
     {
@@ -64,9 +91,11 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
        date = notmuch_thread_get_oldest_date (thread);
        relative_date = notmuch_time_relative_date (ctx, date);
 
        date = notmuch_thread_get_oldest_date (thread);
        relative_date = notmuch_time_relative_date (ctx, date);
 
-       printf ("thread:%s %12s %s; %s",
+       printf ("thread:%s %12s [%d/%d] %s; %s",
                notmuch_thread_get_thread_id (thread),
                relative_date,
                notmuch_thread_get_thread_id (thread),
                relative_date,
+               notmuch_thread_get_matched_messages (thread),
+               notmuch_thread_get_total_messages (thread),
                notmuch_thread_get_authors (thread),
                notmuch_thread_get_subject (thread));
 
                notmuch_thread_get_authors (thread),
                notmuch_thread_get_subject (thread));