/* * call-seq: THREAD.toplevel_messages => MESSAGES * * Get a Notmuch::Messages iterator for the top level messages in thread. */ VALUE notmuch_rb_thread_get_toplevel_messages (VALUE self) { notmuch_messages_t *messages; notmuch_thread_t *thread; Data_Get_Notmuch_Thread (self, thread); messages = notmuch_thread_get_toplevel_messages (thread); if (!messages) rb_raise (notmuch_rb_eMemoryError, "Out of memory"); return Data_Wrap_Struct (notmuch_rb_cMessages, NULL, NULL, messages); }
/* * add each top level reply in the thread, and then add each * reply to the top level replies */ static void append_thread(CONTEXT *ctx, notmuch_thread_t *thread) { notmuch_messages_t *msgs; for (msgs = notmuch_thread_get_toplevel_messages(thread); notmuch_messages_valid(msgs); notmuch_messages_move_to_next(msgs)) { notmuch_message_t *m = notmuch_messages_get(msgs); append_message(ctx, m); append_replies(ctx, m); notmuch_message_destroy(m); } }
/* 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; }