/* * call-seq: QUERY.search_threads => THREADS * * Search for threads */ VALUE notmuch_rb_query_search_threads(VALUE self) { notmuch_query_t *query; notmuch_threads_t *threads; Data_Get_Notmuch_Query(self, query); threads = notmuch_query_search_threads(query); if (!threads) rb_raise(notmuch_rb_eMemoryError, "Out of memory"); return Data_Wrap_Struct(notmuch_rb_cThreads, NULL, NULL, threads); }
static void read_threads_query(CONTEXT *ctx, notmuch_query_t *q, int dedup, int limit) { struct nm_ctxdata *data = get_ctxdata(ctx); notmuch_threads_t *threads; if (!data) return; for (threads = notmuch_query_search_threads(q); notmuch_threads_valid(threads) && (limit == 0 || ctx->msgcount < limit); notmuch_threads_move_to_next(threads)) { notmuch_thread_t *thread = notmuch_threads_get(threads); append_thread(ctx, q, thread, dedup); notmuch_thread_destroy(thread); } }
/* Formatted output of threads */ static int do_show (void *ctx, notmuch_query_t *query, const notmuch_show_format_t *format, notmuch_show_params_t *params) { notmuch_threads_t *threads; notmuch_thread_t *thread; notmuch_messages_t *messages; int first_toplevel = 1; notmuch_status_t status, res = NOTMUCH_STATUS_SUCCESS; if (format->message_set_start) fputs (format->message_set_start, stdout); for (threads = notmuch_query_search_threads (query); notmuch_threads_valid (threads); notmuch_threads_move_to_next (threads)) { thread = notmuch_threads_get (threads); messages = notmuch_thread_get_toplevel_messages (thread); if (messages == NULL) INTERNAL_ERROR ("Thread %s has no toplevel messages.\n", notmuch_thread_get_thread_id (thread)); if (!first_toplevel && format->message_set_sep) fputs (format->message_set_sep, stdout); first_toplevel = 0; status = show_messages (ctx, format, messages, 0, params); if (status && !res) res = status; notmuch_thread_destroy (thread); } if (format->message_set_end) fputs (format->message_set_end, stdout); return res != NOTMUCH_STATUS_SUCCESS; }
/* Formatted output of threads */ static int do_show (void *ctx, notmuch_query_t *query, const notmuch_show_format_t *format, sprinter_t *sp, notmuch_show_params_t *params) { notmuch_threads_t *threads; notmuch_thread_t *thread; notmuch_messages_t *messages; notmuch_status_t status, res = NOTMUCH_STATUS_SUCCESS; threads = notmuch_query_search_threads (query); if (! threads) return 1; sp->begin_list (sp); for ( ; notmuch_threads_valid (threads); notmuch_threads_move_to_next (threads)) { thread = notmuch_threads_get (threads); messages = notmuch_thread_get_toplevel_messages (thread); if (messages == NULL) INTERNAL_ERROR ("Thread %s has no toplevel messages.\n", notmuch_thread_get_thread_id (thread)); status = show_messages (ctx, format, sp, messages, 0, params); if (status && !res) res = status; notmuch_thread_destroy (thread); } sp->end (sp); return res != NOTMUCH_STATUS_SUCCESS; }
/* Formatted output of threads */ static int do_show (void *ctx, notmuch_query_t *query, const notmuch_show_format_t *format, notmuch_show_params_t *params) { notmuch_threads_t *threads; notmuch_thread_t *thread; notmuch_messages_t *messages; int first_toplevel = 1; fputs (format->message_set_start, stdout); for (threads = notmuch_query_search_threads (query); notmuch_threads_valid (threads); notmuch_threads_move_to_next (threads)) { thread = notmuch_threads_get (threads); messages = notmuch_thread_get_toplevel_messages (thread); if (messages == NULL) INTERNAL_ERROR ("Thread %s has no toplevel messages.\n", notmuch_thread_get_thread_id (thread)); if (!first_toplevel) fputs (format->message_set_sep, stdout); first_toplevel = 0; show_messages (ctx, format, messages, 0, params); notmuch_thread_destroy (thread); } fputs (format->message_set_end, stdout); return 0; }
static int do_search_threads (const search_format_t *format, notmuch_query_t *query, notmuch_sort_t sort, output_t output) { notmuch_thread_t *thread; notmuch_threads_t *threads; notmuch_tags_t *tags; time_t date; int first_thread = 1; threads = notmuch_query_search_threads (query); if (threads == NULL) return 1; fputs (format->results_start, stdout); for (; notmuch_threads_valid (threads); notmuch_threads_move_to_next (threads)) { int first_tag = 1; if (! first_thread) fputs (format->item_sep, stdout); thread = notmuch_threads_get (threads); if (output == OUTPUT_THREADS) { format->item_id (thread, "thread:", notmuch_thread_get_thread_id (thread)); } else { /* output == OUTPUT_SUMMARY */ fputs (format->item_start, stdout); if (sort == NOTMUCH_SORT_OLDEST_FIRST) date = notmuch_thread_get_oldest_date (thread); else date = notmuch_thread_get_newest_date (thread); format->thread_summary (thread, notmuch_thread_get_thread_id (thread), date, notmuch_thread_get_matched_messages (thread), notmuch_thread_get_total_messages (thread), notmuch_thread_get_authors (thread), notmuch_thread_get_subject (thread)); fputs (format->tag_start, stdout); for (tags = notmuch_thread_get_tags (thread); notmuch_tags_valid (tags); notmuch_tags_move_to_next (tags)) { if (! first_tag) fputs (format->tag_sep, stdout); printf (format->tag, notmuch_tags_get (tags)); first_tag = 0; } fputs (format->tag_end, stdout); fputs (format->item_end, stdout); } first_thread = 0; notmuch_thread_destroy (thread); } fputs (format->results_end, stdout); return 0; }