示例#1
0
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;
}
示例#2
0
文件: messages.c 项目: alip/notmuch
/*
 * call-seq: MESSAGES.tags => TAGS
 *
 * Collect tags from the messages
 */
VALUE
notmuch_rb_messages_collect_tags(VALUE self)
{
    notmuch_tags_t *tags;
    notmuch_messages_t *messages;

    Data_Get_Notmuch_Messages(self, messages);

    tags = notmuch_messages_collect_tags(messages);
    if (!tags)
        rb_raise(notmuch_rb_eMemoryError, "Out of memory");

    return Data_Wrap_Struct(notmuch_rb_cTags, NULL, NULL, tags);
}
示例#3
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;
}