示例#1
0
static MuMsg*
get_message (MuMsgIter *iter, time_t after)
{
	MuMsg *msg;

	if (mu_msg_iter_is_done (iter))
		return NULL;

	msg = mu_msg_iter_get_msg_floating (iter);
	if (!msg)
		return NULL; /* error */

	if (!mu_msg_is_readable (msg)) {
		mu_msg_iter_next (iter);
		return get_message (iter, after);
	}


	if (after != 0 && after > mu_msg_get_timestamp (msg)) {
		mu_msg_iter_next (iter);
		return get_message (iter, after);
	}

	return msg;
}
示例#2
0
文件: mu-cmd-server.c 项目: Popsch/mu
static unsigned
print_sexps (MuMsgIter *iter, gboolean threads, unsigned maxnum)
{
	unsigned u;
	u = 0;

	while (!mu_msg_iter_is_done (iter) && u < maxnum && !MU_TERMINATE) {

		MuMsg *msg;
		msg = mu_msg_iter_get_msg_floating (iter);

		if (mu_msg_is_readable (msg)) {
			char *sexp;
			const MuMsgIterThreadInfo* ti;

			ti = threads ? mu_msg_iter_get_thread_info (iter) : NULL;
			sexp = mu_msg_to_sexp (msg, mu_msg_iter_get_docid (iter),
					       ti, MU_MSG_OPTION_HEADERS_ONLY);
			print_expr ("%s", sexp);
			g_free (sexp);
			++u;
		}
		mu_msg_iter_next (iter);
	}
	return u;
}
示例#3
0
文件: mu-threader.c 项目: nd/mu
/* step 1: create the containers, connect them, and fill the id_table */
static GHashTable*
create_containers (MuMsgIter *iter)
{
	GHashTable *id_table;
	id_table = g_hash_table_new_full (g_str_hash, g_str_equal,
					  NULL,
					  (GDestroyNotify)mu_container_destroy);

	for (mu_msg_iter_reset (iter); !mu_msg_iter_is_done (iter);
	     mu_msg_iter_next (iter)) {

		MuContainer *c;
		MuMsg *msg;
		unsigned docid;

		/* 1.A */
		msg   = mu_msg_iter_get_msg_floating (iter); /* don't unref */
		docid = mu_msg_iter_get_docid (iter);

		c = find_or_create (id_table, msg, docid);

		/* 1.B and C */
		if (c)
			handle_references (id_table, c);
	}

	return id_table;
}
示例#4
0
文件: mu-cmd-server.c 项目: Popsch/mu
/* get a *list* of all messages with the given message id */
static GSList*
get_docids_from_msgids (MuQuery *query, const char *str, GError **err)
{
	gchar *querystr;
	MuMsgIter *iter;
	GSList *lst;

	querystr = g_strdup_printf ("msgid:%s", str);
	iter = mu_query_run (query, querystr, FALSE,
			     MU_MSG_FIELD_ID_NONE, FALSE,-1 /*unlimited*/,
			     err);
	g_free (querystr);

	if (!iter || mu_msg_iter_is_done (iter)) {
		mu_util_g_set_error (err, MU_ERROR_NO_MATCHES,
				     "could not find message %s", str);
		return NULL;
	}

	lst = NULL;
	do {
		lst = g_slist_prepend
			(lst,
			 GSIZE_TO_POINTER(mu_msg_iter_get_docid (iter)));
	} while (mu_msg_iter_next (iter));

	mu_msg_iter_destroy (iter);

	return lst;
}
示例#5
0
文件: mu-cmd-find.c 项目: migadu/mu
static gboolean
output_query_results (MuMsgIter *iter, MuConfig *opts, GError **err)
{
        int              count;
        gboolean         rv;
        OutputFunc      *output_func;

        output_func = output_prepare (opts, err);
        if (!output_func)
                return FALSE;

        for (count = 0, rv = TRUE; !mu_msg_iter_is_done(iter);
             mu_msg_iter_next (iter)) {

                MuMsg *msg;

                if (count == opts->maxnum)
                        break;
                msg = get_message (iter, opts->after);
                if (!msg)
                        break;

                /* { */
                /*      const char* thread_id; */
                /*      thread_id = mu_msg_iter_get_thread_id (iter); */
                /*      g_print ("%s ", thread_id ? thread_id : "<none>"); */

                /* } */
                rv = output_func (msg, iter, opts, err);
                if (!rv)
                        break;
                else
                        ++count;
        }

        output_finish (opts);

        if (rv && count == 0) {
                mu_util_g_set_error (err, MU_ERROR_NO_MATCHES,
                                     "no matches for search expression");
                return FALSE;
        }

        return rv;
}
示例#6
0
static int
update_model (GtkListStore * store, const char *xpath, const char *query,
	      MugMsgListView * self)
{
	MuMsgIter *iter;
	int count;

	iter = run_query (xpath, query, self);
	if (!iter) {
		g_warning ("error: running query failed\n");
		return -1;
	}

	for (count = 0; !mu_msg_iter_is_done (iter);
	     mu_msg_iter_next (iter), ++count)
		add_row (store, mu_msg_iter_get_msg_floating(iter)); /* don't unref */

	mu_msg_iter_destroy (iter);

	return count;
}
示例#7
0
static int
update_model (GtkTreeStore *store, const char *xpath, const char *query,
	      MugMsgListView *self)
{
	MuMsgIter *iter;
	int count;
	const MuMsgIterThreadInfo *prev_ti = NULL;

	iter = run_query (xpath, query, self);
	if (!iter) {
		g_warning ("error: running query failed\n");
		return -1;
	}

	for (count = 0; !mu_msg_iter_is_done (iter);
	     mu_msg_iter_next (iter), ++count) {

		GtkTreeIter treeiter, prev_treeiter;
		const MuMsgIterThreadInfo *ti;

		ti = mu_msg_iter_get_thread_info (iter);

		if (!prev_ti || !g_str_has_prefix (ti->threadpath,
						   prev_ti->threadpath))
			gtk_tree_store_append (store, &treeiter, NULL);
		else
			gtk_tree_store_append (store, &treeiter, &prev_treeiter);

		/* don't unref msg */
		add_row (store, mu_msg_iter_get_msg_floating (iter), &treeiter);

		prev_ti = ti;
		prev_treeiter = treeiter;
	}

	mu_msg_iter_destroy (iter);

	return count;
}
示例#8
0
文件: mu-cmd-find.c 项目: Popsch/mu
static gboolean
output_query_results (MuMsgIter *iter, MuConfig *opts, GError **err)
{
	unsigned count;
	gboolean rv;
	OutputFunc *output_func;

	output_func = output_prepare (opts, err);
	if (!output_func)
		return FALSE;

	for (count = 0, rv = TRUE; !mu_msg_iter_is_done(iter);
	     mu_msg_iter_next (iter)) {

		MuMsg *msg;

		msg = get_message (iter, opts->after);
		if (!msg)
			break;

		rv = output_func (msg, iter, opts, err);
		if (!rv)
			break;
		else
			++count;
	}

	output_finish (opts);

	if (rv && count == 0) {
		mu_util_g_set_error (err, MU_ERROR_NO_MATCHES,
				     "no matches for search expression");
		return FALSE;
	}

	return rv;
}