Пример #1
0
/* 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;
}
Пример #2
0
/* NOTE: this assumes there is only _one_ docid (message) for the
 * particular message id */
static unsigned
get_docid_from_msgid (MuQuery *query, const char *str, GError **err)
{
	gchar *querystr;
	unsigned docid;
	MuMsgIter *iter;

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

	docid = MU_STORE_INVALID_DOCID;
	if (!iter || mu_msg_iter_is_done (iter))
		mu_util_g_set_error (err, MU_ERROR_NO_MATCHES,
				     "could not find message %s", str);
	else {
		MuMsg *msg;
		msg = mu_msg_iter_get_msg_floating (iter);
		if (!mu_msg_is_readable(msg)) {
			mu_util_g_set_error (err, MU_ERROR_FILE_CANNOT_READ,
					     "'%s' is not readable",
					     mu_msg_get_path(msg));
		} else
			docid = mu_msg_iter_get_docid (iter);

		mu_msg_iter_destroy (iter);
	}

	return docid;
}
Пример #3
0
static gboolean
process_query (MuQuery *xapian, const gchar *query, MuConfig *opts, GError **err)
{
	MuMsgIter *iter;
	gboolean rv;

	iter = run_query (xapian, query, opts, err);
	if (!iter)
		return FALSE;

	rv = output_query_results (iter, opts, err);
	mu_msg_iter_destroy (iter);

	return rv;
}
Пример #4
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;
}
Пример #5
0
/*
 * 'find' finds a list of messages matching some query, and takes a
 * parameter 'query' with the search query, and (optionally) a
 * parameter 'maxnum' with the maximum number of messages to return.
 *
 * returns:
 * => list of s-expressions, each describing a message =>
 * (:found <number of found messages>)
 */
static MuError
cmd_find (ServerContext *ctx, GSList *args, GError **err)
{
	MuMsgIter *iter;
	unsigned foundnum;
	int maxnum;
	gboolean threads, reverse;
	MuMsgFieldId sortfield;
	const char *querystr;

	GET_STRING_OR_ERROR_RETURN (args, "query", &querystr, err);
	if (get_find_params (args, &threads, &sortfield,
			     &reverse, &maxnum, err) != MU_OK) {
		print_and_clear_g_error (err);
		return MU_OK;
	}

	/* note: when we're threading, we get *all* matching messages,
	 * and then only return maxnum; this is so that we maximimize
	 * the change of all messages in a thread showing up */
	iter = mu_query_run (ctx->query, querystr, threads,
			     sortfield, reverse,
			     threads ? -1 : maxnum, err);
	if (!iter) {
		print_and_clear_g_error (err);
		return MU_OK;
	}

	/* before sending new results, send an 'erase' message, so the
	 * frontend knows it should erase the headers buffer. this
	 * will ensure that the output of two finds will not be
	 * mixed. */
	print_expr ("(:erase t)");
	foundnum = print_sexps (iter, threads,
				maxnum > 0 ? maxnum : G_MAXINT32);
	print_expr ("(:found %u)", foundnum);
	mu_msg_iter_destroy (iter);

	return MU_OK;
}
Пример #6
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;
}