X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=notmuch-search.c;h=8db09c7765afde6e4e2f89f9e90dea818d11560e;hp=41e317a221961ebdab9d82ada88a9f4dc0935fae;hb=8e95cf42324809d34638cdb29fb650cce0efad87;hpb=93dcc3b695e19dd36cc8f638c6e01ecbbd9a447d diff --git a/notmuch-search.c b/notmuch-search.c index 41e317a2..8db09c77 100644 --- a/notmuch-search.c +++ b/notmuch-search.c @@ -32,6 +32,39 @@ notmuch_search_command (void *ctx, int argc, char *argv[]) char *query_str; const char *relative_date; time_t date; + int i, first = 0, max_threads = -1; + char *opt, *end; + notmuch_sort_t sort = NOTMUCH_SORT_DATE; + + 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; + } + } else if (strcmp (argv[i], "--reverse") == 0) { + sort = NOTMUCH_SORT_DATE_REVERSE; + } else { + fprintf (stderr, "Unrecognized option: %s\n", argv[i]); + return 1; + } + } + + argc -= i; + argv += i; config = notmuch_config_open (ctx, NULL, NULL); if (config == NULL) @@ -53,7 +86,9 @@ notmuch_search_command (void *ctx, int argc, char *argv[]) return 1; } - for (threads = notmuch_query_search_threads (query, 0, -1); + notmuch_query_set_sort (query, sort); + + for (threads = notmuch_query_search_threads (query, first, max_threads); notmuch_threads_has_more (threads); notmuch_threads_advance (threads)) { @@ -61,12 +96,18 @@ notmuch_search_command (void *ctx, int argc, char *argv[]) thread = notmuch_threads_get (threads); - date = notmuch_thread_get_oldest_date (thread); + if (sort == NOTMUCH_SORT_DATE) + date = notmuch_thread_get_oldest_date (thread); + else + date = notmuch_thread_get_newest_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_matched_messages (thread), + notmuch_thread_get_total_messages (thread), notmuch_thread_get_authors (thread), notmuch_thread_get_subject (thread));