/* Return the number of files matching the query, or -1 for an error */ static int count_files (notmuch_query_t *query) { notmuch_messages_t *messages; notmuch_message_t *message; notmuch_filenames_t *filenames; notmuch_status_t status; int count = 0; status = notmuch_query_search_messages_st (query, &messages); if (print_status_query ("notmuch count", query, status)) return -1; for (; notmuch_messages_valid (messages); notmuch_messages_move_to_next (messages)) { message = notmuch_messages_get (messages); filenames = notmuch_message_get_filenames (message); for (; notmuch_filenames_valid (filenames); notmuch_filenames_move_to_next (filenames)) count++; notmuch_filenames_destroy (filenames); notmuch_message_destroy (message); } notmuch_messages_destroy (messages); return count; }
/* * call-seq: MESSAGES.destroy! => nil * * Destroys the messages, freeing all resources allocated for it. */ VALUE notmuch_rb_messages_destroy(VALUE self) { notmuch_messages_t *messages; Data_Get_Notmuch_Messages(self, messages); notmuch_messages_destroy(messages); DATA_PTR(self) = NULL; return Qnil; }
static int do_search_tags (notmuch_database_t *notmuch, const search_format_t *format, notmuch_query_t *query) { notmuch_messages_t *messages = NULL; notmuch_tags_t *tags; const char *tag; int first_tag = 1; /* Special-case query of "*" for better performance. */ if (strcmp (notmuch_query_get_query_string (query), "*") == 0) { tags = notmuch_database_get_all_tags (notmuch); } else { messages = notmuch_query_search_messages (query); if (messages == NULL) return 1; tags = notmuch_messages_collect_tags (messages); } if (tags == NULL) return 1; fputs (format->results_start, stdout); for (; notmuch_tags_valid (tags); notmuch_tags_move_to_next (tags)) { tag = notmuch_tags_get (tags); if (! first_tag) fputs (format->item_sep, stdout); format->item_id (tags, "", tag); first_tag = 0; } notmuch_tags_destroy (tags); if (messages) notmuch_messages_destroy (messages); if (first_tag) fputs (format->results_null, stdout); else fputs (format->results_end, stdout); return 0; }
static int do_search_tags (const search_context_t *ctx) { notmuch_messages_t *messages = NULL; notmuch_tags_t *tags; const char *tag; sprinter_t *format = ctx->format; notmuch_query_t *query = ctx->query; notmuch_database_t *notmuch = ctx->notmuch; /* should the following only special case if no excluded terms * specified? */ /* Special-case query of "*" for better performance. */ if (strcmp (notmuch_query_get_query_string (query), "*") == 0) { tags = notmuch_database_get_all_tags (notmuch); } else { notmuch_status_t status; status = notmuch_query_search_messages_st (query, &messages); if (print_status_query ("notmuch search", query, status)) return 1; tags = notmuch_messages_collect_tags (messages); } if (tags == NULL) return 1; format->begin_list (format); for (; notmuch_tags_valid (tags); notmuch_tags_move_to_next (tags)) { tag = notmuch_tags_get (tags); format->string (format, tag); format->separator (format); } notmuch_tags_destroy (tags); if (messages) notmuch_messages_destroy (messages); format->end (format); return 0; }
static int do_search_messages (const search_format_t *format, notmuch_query_t *query, output_t output) { notmuch_message_t *message; notmuch_messages_t *messages; int first_message = 1; messages = notmuch_query_search_messages (query); if (messages == NULL) return 1; fputs (format->results_start, stdout); for (; notmuch_messages_valid (messages); notmuch_messages_move_to_next (messages)) { message = notmuch_messages_get (messages); if (! first_message) fputs (format->item_sep, stdout); if (output == OUTPUT_FILES) { format->item_id (message, "", notmuch_message_get_filename (message)); } else { /* output == OUTPUT_MESSAGES */ format->item_id (message, "id:", notmuch_message_get_message_id (message)); } first_message = 0; notmuch_message_destroy (message); } notmuch_messages_destroy (messages); fputs (format->results_end, stdout); return 0; }
static int do_search_messages (search_context_t *ctx) { notmuch_message_t *message; notmuch_messages_t *messages; notmuch_filenames_t *filenames; sprinter_t *format = ctx->format; int i; notmuch_status_t status; if (ctx->offset < 0) { unsigned count; notmuch_status_t status; status = notmuch_query_count_messages_st (ctx->query, &count); if (print_status_query ("notmuch search", ctx->query, status)) return 1; ctx->offset += count; if (ctx->offset < 0) ctx->offset = 0; } status = notmuch_query_search_messages_st (ctx->query, &messages); if (print_status_query ("notmuch search", ctx->query, status)) return 1; format->begin_list (format); for (i = 0; notmuch_messages_valid (messages) && (ctx->limit < 0 || i < ctx->offset + ctx->limit); notmuch_messages_move_to_next (messages), i++) { if (i < ctx->offset) continue; message = notmuch_messages_get (messages); if (ctx->output == OUTPUT_FILES) { int j; filenames = notmuch_message_get_filenames (message); for (j = 1; notmuch_filenames_valid (filenames); notmuch_filenames_move_to_next (filenames), j++) { if (ctx->dupe < 0 || ctx->dupe == j) { format->string (format, notmuch_filenames_get (filenames)); format->separator (format); } } notmuch_filenames_destroy( filenames ); } else if (ctx->output == OUTPUT_MESSAGES) { /* special case 1 for speed */ if (ctx->dupe <= 1 || ctx->dupe <= _count_filenames (message)) { format->set_prefix (format, "id"); format->string (format, notmuch_message_get_message_id (message)); format->separator (format); } } else { if (ctx->output & OUTPUT_SENDER) { const char *addrs; addrs = notmuch_message_get_header (message, "from"); process_address_header (ctx, addrs); } if (ctx->output & OUTPUT_RECIPIENTS) { const char *hdrs[] = { "to", "cc", "bcc" }; const char *addrs; size_t j; for (j = 0; j < ARRAY_SIZE (hdrs); j++) { addrs = notmuch_message_get_header (message, hdrs[j]); process_address_header (ctx, addrs); } } } notmuch_message_destroy (message); } if (ctx->addresses && (ctx->output & OUTPUT_COUNT || ctx->dedup == DEDUP_ADDRESS)) g_hash_table_foreach (ctx->addresses, print_hash_value, ctx); notmuch_messages_destroy (messages); format->end (format); return 0; }
static int do_search_messages (const search_format_t *format, notmuch_query_t *query, output_t output, int offset, int limit) { notmuch_message_t *message; notmuch_messages_t *messages; notmuch_filenames_t *filenames; int first_message = 1; int i; if (offset < 0) { offset += notmuch_query_count_messages (query); if (offset < 0) offset = 0; } messages = notmuch_query_search_messages (query); if (messages == NULL) return 1; fputs (format->results_start, stdout); for (i = 0; notmuch_messages_valid (messages) && (limit < 0 || i < offset + limit); notmuch_messages_move_to_next (messages), i++) { if (i < offset) continue; message = notmuch_messages_get (messages); if (output == OUTPUT_FILES) { filenames = notmuch_message_get_filenames (message); for (; notmuch_filenames_valid (filenames); notmuch_filenames_move_to_next (filenames)) { if (! first_message) fputs (format->item_sep, stdout); format->item_id (message, "", notmuch_filenames_get (filenames)); first_message = 0; } notmuch_filenames_destroy( filenames ); } else { /* output == OUTPUT_MESSAGES */ if (! first_message) fputs (format->item_sep, stdout); format->item_id (message, "id:", notmuch_message_get_message_id (message)); first_message = 0; } notmuch_message_destroy (message); } notmuch_messages_destroy (messages); if (first_message) fputs (format->results_null, stdout); else fputs (format->results_end, stdout); return 0; }