Beispiel #1
0
/* 'remove' removes the message with either docid: or msgid:, sends a
 * (:remove ...) message when it succeeds
 */
static MuError
cmd_remove (ServerContext *ctx, GSList *args, GError **err)
{
	unsigned docid;
	const char *path;

	docid = determine_docid (ctx->query, args, err);
	if (docid == MU_STORE_INVALID_DOCID) {
		print_and_clear_g_error (err);
		return MU_OK;
	}

	path = get_path_from_docid (ctx->store, docid, err);
	if (!path) {
		print_and_clear_g_error (err);
		return MU_OK;
	}

	if (unlink (path) != 0) {
		mu_util_g_set_error (err, MU_ERROR_FILE_CANNOT_UNLINK,
				     "%s", strerror (errno));
		print_and_clear_g_error (err);
		return MU_OK;
	}

	if (!mu_store_remove_path (ctx->store, path)) {
		print_error (MU_ERROR_XAPIAN_REMOVE_FAILED,
			     "failed to remove from database");
		return MU_OK;
	}

	print_expr ("(:remove %u)", docid);
	return MU_OK;
}
Beispiel #2
0
/*
 * 'move' moves a message to a different maildir and/or changes its
 * flags. parameters are *either* a 'docid:' or 'msgid:' pointing to
 * the message, a 'maildir:' for the target maildir, and a 'flags:'
 * parameter for the new flags.
 *
 * returns an (:update <new-msg-sexp>)
 *
 */
static MuError
cmd_move (ServerContext *ctx, GHashTable *args, GError **err)
{
	unsigned docid;
	MuMsg *msg;
	MuFlags flags;
	const char *maildir, *flagstr;
	gboolean new_name;

	/* check if the move is based on the message id; if so, handle
	 * it in move_msgid_maybe */
	if (move_msgid_maybe (ctx, args, err))
		return MU_OK;

	maildir	 = get_string_from_args (args, "maildir", TRUE, err);
	flagstr	 = get_string_from_args (args, "flags", TRUE, err);
	new_name = get_bool_from_args (args, "newname", TRUE, err);

	docid = determine_docid (ctx->query, args, err);
	if (docid == MU_STORE_INVALID_DOCID ||
	    !(msg = mu_store_get_msg (ctx->store, docid, err))) {
		print_and_clear_g_error (err);
		return MU_OK;
	}

	/* if maildir was not specified, take the current one */
	if (!maildir)
		maildir = mu_msg_get_maildir (msg);

	/* determine the real target flags, which come from the
	 * flags-parameter we received (ie., flagstr), if any, plus
	 * the existing message flags. */
	if (flagstr)
		flags = get_flags (mu_msg_get_path(msg), flagstr);
	else
		flags = mu_msg_get_flags (msg);

	if (flags == MU_FLAG_INVALID) {
		print_error (MU_ERROR_IN_PARAMETERS, "invalid flags");
		goto leave;
	}

	if ((do_move (ctx->store, docid, msg, maildir, flags, new_name, err)
	     != MU_OK))
		print_and_clear_g_error (err);

leave:
	mu_msg_unref (msg);
	return MU_OK;
}
Beispiel #3
0
/* 'extract' extracts some mime part from a message */
static MuError
cmd_extract (ServerContext *ctx, GHashTable *args, GError **err)
{
	MuMsg *msg;
	int docid, index, action;
	MuError rv;
	MuMsgOptions opts;
	const char* actionstr, *indexstr;

	opts = get_encrypted_msg_opts (args);
	rv = MU_ERROR;

	/* read parameters */
	GET_STRING_OR_ERROR_RETURN (args, "action", &actionstr, err);
	GET_STRING_OR_ERROR_RETURN (args, "index",  &indexstr, err);
	index = atoi (indexstr);
	docid = determine_docid (ctx->query, args, err);
	if (docid == MU_STORE_INVALID_DOCID) {
		print_and_clear_g_error (err);
		return MU_OK;
	}

	if ((action = action_type (actionstr)) == INVALID_ACTION) {
		print_error (MU_ERROR_IN_PARAMETERS, "invalid action");
		return MU_OK;
	}
	msg = mu_store_get_msg (ctx->store, docid, err);
	if (!msg) {
		print_error (MU_ERROR, "failed to get message");
		return MU_OK;
	}

	switch (action) {
	case SAVE: rv = save_part (msg, docid, index, opts, args, err); break;
	case OPEN: rv = open_part (msg, docid, index, opts, err); break;
	case TEMP: rv = temp_part (msg, docid, index, opts, args, err); break;
	default: print_error (MU_ERROR_INTERNAL, "unknown action");
	}

	if (rv != MU_OK)
		print_and_clear_g_error (err);

	mu_msg_unref (msg);
	return MU_OK;
}
Beispiel #4
0
/* 'view' gets a full (including body etc.) sexp for some message,
 * identified by either docid: or msgid:; return a (:view <sexp>)
 */
static MuError
cmd_view (ServerContext *ctx, GSList *args, GError **err)
{
	MuMsg *msg;
	const gchar *path;
	char *sexp;
	MuMsgOptions opts;
	unsigned docid;

	opts = get_view_msg_opts (args);

	/* when 'path' is specified, get the message at path */
	path = get_string_from_args (args, "path", FALSE, NULL);

	if (path) {
		docid = 0;
		msg   = mu_msg_new_from_file (path, NULL, err);
	} else {
		docid = determine_docid (ctx->query, args, err);
		if (docid == MU_STORE_INVALID_DOCID) {
			print_and_clear_g_error (err);
			return MU_OK;
		}
		msg = mu_store_get_msg (ctx->store, docid, err);
	}

	if (!msg) {
		print_and_clear_g_error (err);
		return MU_OK;
	}

	sexp = mu_msg_to_sexp (msg, docid, NULL, opts);
	mu_msg_unref (msg);

	print_expr ("(:view %s)\n", sexp);
	g_free (sexp);

	return MU_OK;
}