/* Sort values for notmuch_query_set_sort */
typedef enum {
- NOTMUCH_SORT_DATE_OLDEST_FIRST,
- NOTMUCH_SORT_DATE_NEWEST_FIRST,
+ NOTMUCH_SORT_DATE,
+ NOTMUCH_SORT_DATE_REVERSE,
NOTMUCH_SORT_MESSAGE_ID
} notmuch_sort_t;
query->query_string = talloc_strdup (query, query_string);
- query->sort = NOTMUCH_SORT_DATE_OLDEST_FIRST;
+ query->sort = NOTMUCH_SORT_DATE;
return query;
}
}
switch (query->sort) {
- case NOTMUCH_SORT_DATE_OLDEST_FIRST:
+ case NOTMUCH_SORT_DATE:
enquire.set_sort_by_value (NOTMUCH_VALUE_TIMESTAMP, FALSE);
break;
- case NOTMUCH_SORT_DATE_NEWEST_FIRST:
+ case NOTMUCH_SORT_DATE_REVERSE:
enquire.set_sort_by_value (NOTMUCH_VALUE_TIMESTAMP, TRUE);
break;
case NOTMUCH_SORT_MESSAGE_ID:
thread->oldest = 0;
thread->newest = 0;
- notmuch_query_set_sort (thread_id_query, NOTMUCH_SORT_DATE_OLDEST_FIRST);
+ notmuch_query_set_sort (thread_id_query, NOTMUCH_SORT_DATE);
for (messages = notmuch_query_search_messages (thread_id_query, 0, -1);
notmuch_messages_has_more (messages);
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) {
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;
}
}
return 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))
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 [%d/%d] %s; %s",