doveadm-mail-mailbox.c revision 23878bd03d1de531e3261a25598beec621351910
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen/* Copyright (c) 2010 Dovecot authors, see the included COPYING file */
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch#include "lib.h"
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch#include "array.h"
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch#include "mail-namespace.h"
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch#include "mail-storage.h"
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch#include "mail-search-build.h"
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch#include "doveadm-mail-list-iter.h"
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch#include "doveadm-mail.h"
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch#include <stdio.h>
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstruct mailbox_cmd_context {
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch struct doveadm_mail_cmd_context ctx;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch ARRAY_TYPE(const_string) mailboxes;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch};
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstruct rename_cmd_context {
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch struct doveadm_mail_cmd_context ctx;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch const char *oldname, *newname;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch};
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch
de96afeeaa5242cffe89f1966457e935806b5746Stephan Boschstruct list_cmd_context {
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch struct doveadm_mail_cmd_context ctx;
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch struct mail_search_args *search_args;
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch};
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch
de96afeeaa5242cffe89f1966457e935806b5746Stephan Boschstatic void
de96afeeaa5242cffe89f1966457e935806b5746Stephan Boschcmd_mailbox_list_run(struct doveadm_mail_cmd_context *_ctx,
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch struct mail_user *user)
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch{
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch struct list_cmd_context *ctx = (struct list_cmd_context *)_ctx;
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch const enum mailbox_list_iter_flags iter_flags =
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch MAILBOX_LIST_ITER_RAW_LIST |
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch MAILBOX_LIST_ITER_VIRTUAL_NAMES |
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch MAILBOX_LIST_ITER_NO_AUTO_INBOX |
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch MAILBOX_LIST_ITER_RETURN_NO_FLAGS;
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch struct doveadm_mail_list_iter *iter;
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch const struct mailbox_info *info;
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch iter = doveadm_mail_list_iter_init(user, ctx->search_args, iter_flags);
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch while ((info = doveadm_mail_list_iter_next(iter)) != NULL) {
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch printf("%s\n", info->name);
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch }
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch doveadm_mail_list_iter_deinit(&iter);
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch}
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch
de96afeeaa5242cffe89f1966457e935806b5746Stephan Boschstatic void cmd_mailbox_list_init(struct doveadm_mail_cmd_context *_ctx,
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch const char *const args[])
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch{
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch struct list_cmd_context *ctx = (struct list_cmd_context *)_ctx;
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch struct mail_search_arg *arg;
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch unsigned int i;
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch ctx->search_args = mail_search_build_init();
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch for (i = 0; args[i] != NULL; i++) {
6ee9ce5ed955a1283dc22ad28980bf9cc23d4c4eStephan Bosch arg = mail_search_build_add(ctx->search_args,
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch SEARCH_MAILBOX_GLOB);
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch arg->value.str = p_strdup(ctx->search_args->pool, args[i]);
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch }
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch if (i > 1) {
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch struct mail_search_arg *subargs = ctx->search_args->args;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch ctx->search_args->args = NULL;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch arg = mail_search_build_add(ctx->search_args, SEARCH_OR);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch arg->value.subargs = subargs;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch }
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch}
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic struct doveadm_mail_cmd_context *cmd_mailbox_list_alloc(void)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch{
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch struct list_cmd_context *ctx;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch ctx = doveadm_mail_cmd_alloc(struct list_cmd_context);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch ctx->ctx.init = cmd_mailbox_list_init;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch ctx->ctx.run = cmd_mailbox_list_run;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch return &ctx->ctx;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch}
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic void
7384b4e78eaab44693c985192276e31322155e32Stephan Boschcmd_mailbox_create_run(struct doveadm_mail_cmd_context *_ctx,
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch struct mail_user *user)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch{
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch struct mailbox_cmd_context *ctx = (struct mailbox_cmd_context *)_ctx;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch struct mail_namespace *ns;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch struct mailbox *box;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch const char *const *namep;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch array_foreach(&ctx->mailboxes, namep) {
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch const char *storage_name = *namep;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch unsigned int len;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch bool directory = FALSE;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch ns = mail_namespace_find(user->namespaces, &storage_name);
c275cef636c79e1d08b3a82462c4abdca6f8cef3Martti Rannanjärvi if (ns == NULL)
7944646fad6aa1e7c649c3d33e454c516b0220b6Timo Sirainen i_fatal("Can't find namespace for: %s", *namep);
b99130e4cf4af4e6b103b949456222f3a2dff424Timo Sirainen
b99130e4cf4af4e6b103b949456222f3a2dff424Timo Sirainen len = strlen(storage_name);
b99130e4cf4af4e6b103b949456222f3a2dff424Timo Sirainen if (len > 0 && storage_name[len-1] == ns->real_sep) {
b99130e4cf4af4e6b103b949456222f3a2dff424Timo Sirainen storage_name = t_strndup(storage_name, len-1);
c275cef636c79e1d08b3a82462c4abdca6f8cef3Martti Rannanjärvi directory = TRUE;
5d31e4b38ef03b002e2ab245a7f8a4c0da3dd03dTimo Sirainen }
5d31e4b38ef03b002e2ab245a7f8a4c0da3dd03dTimo Sirainen
4219de12b28f1936219e27501b9c4b27a4f8d53cStephan Bosch box = mailbox_alloc(ns->list, storage_name, 0);
4219de12b28f1936219e27501b9c4b27a4f8d53cStephan Bosch if (mailbox_create(box, NULL, directory) < 0) {
4219de12b28f1936219e27501b9c4b27a4f8d53cStephan Bosch struct mail_storage *storage = mailbox_get_storage(box);
4219de12b28f1936219e27501b9c4b27a4f8d53cStephan Bosch
4219de12b28f1936219e27501b9c4b27a4f8d53cStephan Bosch i_error("Can't create mailbox %s: %s", *namep,
4219de12b28f1936219e27501b9c4b27a4f8d53cStephan Bosch mail_storage_get_last_error(storage, NULL));
4c4c4a740bbb1b674d4b0dae009d1919f8ad96b7Stephan Bosch }
4c4c4a740bbb1b674d4b0dae009d1919f8ad96b7Stephan Bosch mailbox_free(&box);
4c4c4a740bbb1b674d4b0dae009d1919f8ad96b7Stephan Bosch }
4c4c4a740bbb1b674d4b0dae009d1919f8ad96b7Stephan Bosch}
4c4c4a740bbb1b674d4b0dae009d1919f8ad96b7Stephan Bosch
4c4c4a740bbb1b674d4b0dae009d1919f8ad96b7Stephan Boschstatic void cmd_mailbox_create_init(struct doveadm_mail_cmd_context *_ctx,
4c4c4a740bbb1b674d4b0dae009d1919f8ad96b7Stephan Bosch const char *const args[])
4c4c4a740bbb1b674d4b0dae009d1919f8ad96b7Stephan Bosch{
4c4c4a740bbb1b674d4b0dae009d1919f8ad96b7Stephan Bosch struct mailbox_cmd_context *ctx = (struct mailbox_cmd_context *)_ctx;
4219de12b28f1936219e27501b9c4b27a4f8d53cStephan Bosch const char *name;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch unsigned int i;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch if (args[0] == NULL)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch doveadm_mail_help_name("mailbox create");
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch for (i = 0; args[i] != NULL; i++) {
9d746c6785d17e421c3f3c74cf29d059ae2ab233Stephan Bosch name = p_strdup(ctx->ctx.pool, args[i]);
fe2b0e3de834dd40b698bb579adc5357d5789ec9Stephan Bosch array_append(&ctx->mailboxes, &name, 1);
fe2b0e3de834dd40b698bb579adc5357d5789ec9Stephan Bosch }
fe2b0e3de834dd40b698bb579adc5357d5789ec9Stephan Bosch}
fe2b0e3de834dd40b698bb579adc5357d5789ec9Stephan Bosch
94d1b08c9e20d637db568a3eab3dfc2b9e96e62aStephan Boschstatic struct doveadm_mail_cmd_context *cmd_mailbox_create_alloc(void)
94d1b08c9e20d637db568a3eab3dfc2b9e96e62aStephan Bosch{
94d1b08c9e20d637db568a3eab3dfc2b9e96e62aStephan Bosch struct mailbox_cmd_context *ctx;
94d1b08c9e20d637db568a3eab3dfc2b9e96e62aStephan Bosch
ad03049781fc14807248007d524be4daf06c3ee2Stephan Bosch ctx = doveadm_mail_cmd_alloc(struct mailbox_cmd_context);
e47c2f17d8136c4d972d1074a3f84ba2ecef4fdcStephan Bosch ctx->ctx.init = cmd_mailbox_create_init;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch ctx->ctx.run = cmd_mailbox_create_run;
feba5e502b2131c9a1c766b7ef9ff041dbf71d1dStephan Bosch p_array_init(&ctx->mailboxes, ctx->ctx.pool, 16);
b66def5dadd3e7c250313a938d26ad113663f86bStephan Bosch return &ctx->ctx;
b66def5dadd3e7c250313a938d26ad113663f86bStephan Bosch}
5257840e8d31a6cb7051703b4cb0931c82aba638Stephan Bosch
5257840e8d31a6cb7051703b4cb0931c82aba638Stephan Boschstatic void
5257840e8d31a6cb7051703b4cb0931c82aba638Stephan Boschcmd_mailbox_delete_run(struct doveadm_mail_cmd_context *_ctx,
5257840e8d31a6cb7051703b4cb0931c82aba638Stephan Bosch struct mail_user *user)
a8c4e79ff50fac21b05a7368b052583d410ca15cTimo Sirainen{
70505f4839520ac67895992621c97d2480c22e7fTimo Sirainen struct mailbox_cmd_context *ctx = (struct mailbox_cmd_context *)_ctx;
93cc87bb22386e020cee1093b6bd59295e0b33f0Stephan Bosch struct mail_namespace *ns;
c972eaa3565e849df71b44cf0cd45d38c5567d07Stephan Bosch struct mailbox *box;
c972eaa3565e849df71b44cf0cd45d38c5567d07Stephan Bosch const char *const *namep;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch array_foreach(&ctx->mailboxes, namep) {
fca68889b287d8eed4babe72a231bd6079da012dStephan Bosch const char *storage_name = *namep;
fca68889b287d8eed4babe72a231bd6079da012dStephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch ns = mail_namespace_find(user->namespaces, &storage_name);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch if (ns == NULL)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch i_fatal("Can't find namespace for: %s", *namep);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch box = mailbox_alloc(ns->list, storage_name, 0);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch if (mailbox_delete(box) < 0) {
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch struct mail_storage *storage = mailbox_get_storage(box);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch i_error("Can't delete mailbox %s: %s", *namep,
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch mail_storage_get_last_error(storage, NULL));
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch }
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch mailbox_free(&box);
fca68889b287d8eed4babe72a231bd6079da012dStephan Bosch }
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch}
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic void cmd_mailbox_delete_init(struct doveadm_mail_cmd_context *_ctx,
f9d2a1f21ad65262bc630f0834d7eead06a1bac3Timo Sirainen const char *const args[])
f9d2a1f21ad65262bc630f0834d7eead06a1bac3Timo Sirainen{
fca68889b287d8eed4babe72a231bd6079da012dStephan Bosch struct mailbox_cmd_context *ctx = (struct mailbox_cmd_context *)_ctx;
fca68889b287d8eed4babe72a231bd6079da012dStephan Bosch const char *name;
fca68889b287d8eed4babe72a231bd6079da012dStephan Bosch unsigned int i;
fca68889b287d8eed4babe72a231bd6079da012dStephan Bosch
fca68889b287d8eed4babe72a231bd6079da012dStephan Bosch if (args[0] == NULL)
fca68889b287d8eed4babe72a231bd6079da012dStephan Bosch doveadm_mail_help_name("mailbox delete");
fca68889b287d8eed4babe72a231bd6079da012dStephan Bosch
fca68889b287d8eed4babe72a231bd6079da012dStephan Bosch for (i = 0; args[i] != NULL; i++) {
fca68889b287d8eed4babe72a231bd6079da012dStephan Bosch name = p_strdup(ctx->ctx.pool, args[i]);
fca68889b287d8eed4babe72a231bd6079da012dStephan Bosch array_append(&ctx->mailboxes, &name, 1);
fca68889b287d8eed4babe72a231bd6079da012dStephan Bosch }
fca68889b287d8eed4babe72a231bd6079da012dStephan Bosch}
fca68889b287d8eed4babe72a231bd6079da012dStephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic struct doveadm_mail_cmd_context *cmd_mailbox_delete_alloc(void)
9dc01e0d10a61cab14867b26bf0d2d1dcf8ad978Timo Sirainen{
9dc01e0d10a61cab14867b26bf0d2d1dcf8ad978Timo Sirainen struct mailbox_cmd_context *ctx;
ebe0f5e387744621b73c4db79d5891ccbe0a1321Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch ctx = doveadm_mail_cmd_alloc(struct mailbox_cmd_context);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch ctx->ctx.init = cmd_mailbox_delete_init;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch ctx->ctx.run = cmd_mailbox_delete_run;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch p_array_init(&ctx->mailboxes, ctx->ctx.pool, 16);
aacf2a69acc59e9382578d6f4e030788abc79706Timo Sirainen return &ctx->ctx;
aacf2a69acc59e9382578d6f4e030788abc79706Timo Sirainen}
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic void
7384b4e78eaab44693c985192276e31322155e32Stephan Boschcmd_mailbox_rename_run(struct doveadm_mail_cmd_context *_ctx,
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch struct mail_user *user)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch{
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainen struct rename_cmd_context *ctx = (struct rename_cmd_context *)_ctx;
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainen struct mail_namespace *oldns, *newns;
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainen struct mailbox *oldbox, *newbox;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch const char *oldname = ctx->oldname;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch const char *newname = ctx->newname;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch oldns = mail_namespace_find(user->namespaces, &oldname);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch if (oldns == NULL)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch i_fatal("Can't find namespace for: %s", oldname);
636d0f43138468f8efe685a681326b123f660e49Timo Sirainen newns = mail_namespace_find(user->namespaces, &newname);
fc94140acba51adafedafbc8491a3223a51db7a8Stephan Bosch if (newns == NULL)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch i_fatal("Can't find namespace for: %s", newname);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch oldbox = mailbox_alloc(oldns->list, oldname, 0);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch newbox = mailbox_alloc(newns->list, newname, 0);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch if (mailbox_rename(oldbox, newbox, TRUE) < 0) {
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch struct mail_storage *storage = mailbox_get_storage(oldbox);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch i_error("Can't rename mailbox %s to %s: %s", oldname, newname,
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch mail_storage_get_last_error(storage, NULL));
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch }
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch mailbox_free(&oldbox);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch mailbox_free(&newbox);
fc94140acba51adafedafbc8491a3223a51db7a8Stephan Bosch}
fc94140acba51adafedafbc8491a3223a51db7a8Stephan Bosch
fc94140acba51adafedafbc8491a3223a51db7a8Stephan Boschstatic void cmd_mailbox_rename_init(struct doveadm_mail_cmd_context *_ctx,
fc94140acba51adafedafbc8491a3223a51db7a8Stephan Bosch const char *const args[])
636d0f43138468f8efe685a681326b123f660e49Timo Sirainen{
636d0f43138468f8efe685a681326b123f660e49Timo Sirainen struct rename_cmd_context *ctx = (struct rename_cmd_context *)_ctx;
636d0f43138468f8efe685a681326b123f660e49Timo Sirainen
fca68889b287d8eed4babe72a231bd6079da012dStephan Bosch if (str_array_length(args) != 2)
fca68889b287d8eed4babe72a231bd6079da012dStephan Bosch doveadm_mail_help_name("mailbox rename");
fca68889b287d8eed4babe72a231bd6079da012dStephan Bosch
fca68889b287d8eed4babe72a231bd6079da012dStephan Bosch ctx->oldname = p_strdup(ctx->ctx.pool, args[0]);
fca68889b287d8eed4babe72a231bd6079da012dStephan Bosch ctx->newname = p_strdup(ctx->ctx.pool, args[1]);
fca68889b287d8eed4babe72a231bd6079da012dStephan Bosch}
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic struct doveadm_mail_cmd_context *cmd_mailbox_rename_alloc(void)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch{
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch struct rename_cmd_context *ctx;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch ctx = doveadm_mail_cmd_alloc(struct rename_cmd_context);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch ctx->ctx.init = cmd_mailbox_rename_init;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch ctx->ctx.run = cmd_mailbox_rename_run;
a991cfe2157e58ee43bc580f517ce9ef0dfb7acfStephan Bosch return &ctx->ctx;
fb1be3de0159d6a10e916ad992e2bc53be64c6d5Timo Sirainen}
fb1be3de0159d6a10e916ad992e2bc53be64c6d5Timo Sirainen
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstruct doveadm_mail_cmd cmd_mailbox_list = {
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch cmd_mailbox_list_alloc, "mailbox list",
856ae2ad98cee79b2719911a3cc131d7f4ec8a90Timo Sirainen "[-7|-8] [<mailbox> [...]]"
856ae2ad98cee79b2719911a3cc131d7f4ec8a90Timo Sirainen};
1a9a35a6b307f8d5b25345af55e40a99162b4072Timo Sirainenstruct doveadm_mail_cmd cmd_mailbox_create = {
1a9a35a6b307f8d5b25345af55e40a99162b4072Timo Sirainen cmd_mailbox_create_alloc, "mailbox create",
1a9a35a6b307f8d5b25345af55e40a99162b4072Timo Sirainen "[-7|-8] <mailbox> [...]"
1a9a35a6b307f8d5b25345af55e40a99162b4072Timo Sirainen};
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstruct doveadm_mail_cmd cmd_mailbox_delete = {
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch cmd_mailbox_delete_alloc, "mailbox delete",
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch "[-7|-8] <mailbox> [...]"
a991cfe2157e58ee43bc580f517ce9ef0dfb7acfStephan Bosch};
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstruct doveadm_mail_cmd cmd_mailbox_rename = {
a991cfe2157e58ee43bc580f517ce9ef0dfb7acfStephan Bosch cmd_mailbox_rename_alloc, "mailbox rename",
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch "[-7|-8] <old name> <new name>"
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch};
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch