Пример #1
0
/* 'add' adds a message to the database, and takes two parameters:
 * 'path', which is the full path to the message, and 'maildir', which
 * is the maildir this message lives in (e.g. "/inbox"). response with
 * an (:info ...) message with information about the newly added
 * message (details: see code below)
 */
static MuError
cmd_add (ServerContext *ctx, GSList *args, GError **err)
{
	unsigned docid;
	const char *maildir, *path;
	MuMsg *msg;
	gchar *sexp;

	GET_STRING_OR_ERROR_RETURN (args, "path", &path, err);
	GET_STRING_OR_ERROR_RETURN (args, "maildir", &maildir, err);

	docid = mu_store_add_path (ctx->store, path, maildir, err);
	if (docid == MU_STORE_INVALID_DOCID)
		print_and_clear_g_error (err);
	else {
		gchar *escpath;
		escpath = mu_str_escape_c_literal (path, TRUE);
		print_expr ("(:info add :path %s :docid %u)", escpath, docid);

		msg = mu_store_get_msg (ctx->store, docid, err);
		if (msg) {
			sexp = mu_msg_to_sexp (msg, docid, NULL,
					       MU_MSG_OPTION_VERIFY);
			print_expr ("(:update %s :move nil)", sexp);

			mu_msg_unref(msg);
			g_free (sexp);
		}
		g_free (escpath);
	}

	return MU_OK;
}
Пример #2
0
/* 'add' adds a message to the database, and takes two parameters:
 * 'path', which is the full path to the message, and 'maildir', which
 * is the maildir this message lives in (e.g. "/inbox"). response with
 * an (:info ...) message with information about the newly added
 * message (details: see code below)
 */
static MuError
cmd_add (ServerContext *ctx, GSList *args, GError **err)
{
	unsigned docid;
	const char *maildir, *path;

	GET_STRING_OR_ERROR_RETURN (args, "path", &path, err);
	GET_STRING_OR_ERROR_RETURN (args, "maildir", &maildir, err);

	docid = mu_store_add_path (ctx->store, path, maildir, err);
	if (docid == MU_STORE_INVALID_DOCID)
		print_and_clear_g_error (err);
	else {
		gchar *escpath;
		escpath = mu_str_escape_c_literal (path, TRUE);
		print_expr ("(:info add :path %s :docid %u)", escpath, docid);
		g_free (escpath);
	}

	return MU_OK;
}
Пример #3
0
Файл: mu-cmd.c Проект: antono/mu
MuError
mu_cmd_add (MuStore *store, MuConfig *opts, GError **err)
{
	gboolean allok;
	int i;

	g_return_val_if_fail (store, MU_ERROR_INTERNAL);
	g_return_val_if_fail (opts, MU_ERROR_INTERNAL);
	g_return_val_if_fail (opts->cmd == MU_CONFIG_CMD_ADD,
			      MU_ERROR_INTERNAL);

	/* note: params[0] will be 'add' */
	if (!opts->params[0] || !opts->params[1]) {
		g_message ("usage: mu add <file> [<files>]");
		g_set_error (err, 0, MU_ERROR_IN_PARAMETERS,
			     "missing source and/or target");
		return MU_ERROR_IN_PARAMETERS;
	}

	for (i = 1, allok = TRUE; opts->params[i]; ++i) {

		const char* src;
		src = opts->params[i];

		if (!check_file_okay (src, TRUE) ||
		    mu_store_add_path (store, src, NULL, err) ==
		    MU_STORE_INVALID_DOCID) {
			MU_WRITE_LOG ("failed to add %s", src);
			allok = FALSE;
		}
	}

	if (!allok) {
		g_set_error (err, 0, MU_ERROR_XAPIAN_STORE_FAILED,
			     "store failed for some message(s)");
		return MU_ERROR_XAPIAN_STORE_FAILED;
	}

	return MU_OK;
}