summaryrefslogtreecommitdiffstats
path: root/pigeonhole/src/managesieve/cmd-renamescript.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 17:36:47 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 17:36:47 +0000
commit0441d265f2bb9da249c7abf333f0f771fadb4ab5 (patch)
tree3f3789daa2f6db22da6e55e92bee0062a7d613fe /pigeonhole/src/managesieve/cmd-renamescript.c
parentInitial commit. (diff)
downloaddovecot-0441d265f2bb9da249c7abf333f0f771fadb4ab5.tar.xz
dovecot-0441d265f2bb9da249c7abf333f0f771fadb4ab5.zip
Adding upstream version 1:2.3.21+dfsg1.upstream/1%2.3.21+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'pigeonhole/src/managesieve/cmd-renamescript.c')
-rw-r--r--pigeonhole/src/managesieve/cmd-renamescript.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/pigeonhole/src/managesieve/cmd-renamescript.c b/pigeonhole/src/managesieve/cmd-renamescript.c
new file mode 100644
index 0000000..bc7a99d
--- /dev/null
+++ b/pigeonhole/src/managesieve/cmd-renamescript.c
@@ -0,0 +1,54 @@
+/* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file
+ */
+
+#include "lib.h"
+#include "str.h"
+
+#include "sieve.h"
+#include "sieve-script.h"
+#include "sieve-storage.h"
+
+#include "managesieve-common.h"
+#include "managesieve-commands.h"
+
+bool cmd_renamescript(struct client_command_context *cmd)
+{
+ struct client *client = cmd->client;
+ struct sieve_storage *storage = client->storage;
+ const char *scriptname, *newname;
+ struct sieve_script *script;
+
+ /* <oldname> <newname> */
+ if (!client_read_string_args(cmd, TRUE, 2, &scriptname, &newname))
+ return FALSE;
+
+ event_add_str(cmd->event, "old_script_name", scriptname);
+ event_add_str(cmd->event, "new_script_name", newname);
+
+ script = sieve_storage_open_script(storage, scriptname, NULL);
+ if (script == NULL) {
+ client_command_storage_error(
+ cmd, "Failed to open script `%s' for rename to `%s'",
+ scriptname, newname);
+ return TRUE;
+ }
+
+ if (sieve_script_rename(script, newname) < 0) {
+ client_command_storage_error(
+ cmd, "Failed to rename script `%s' to `%s'",
+ scriptname, newname);
+ } else {
+ client->renamed_count++;
+
+ struct event_passthrough *e =
+ client_command_create_finish_event(cmd);
+ e_debug(e->event(), "Renamed script `%s' to `%s'",
+ scriptname, newname);
+
+ client_send_ok(client, "Renamescript completed.");
+ }
+
+ sieve_script_unref(&script);
+ return TRUE;
+}
+