doveadm-mail-mailbox.c revision 23878bd03d1de531e3261a25598beec621351910
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen/* Copyright (c) 2010 Dovecot authors, see the included COPYING file */
de96afeeaa5242cffe89f1966457e935806b5746Stephan Boschcmd_mailbox_list_run(struct doveadm_mail_cmd_context *_ctx,
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch struct list_cmd_context *ctx = (struct list_cmd_context *)_ctx;
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch const enum mailbox_list_iter_flags iter_flags =
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 Boschstatic void cmd_mailbox_list_init(struct doveadm_mail_cmd_context *_ctx,
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch const char *const args[])
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch struct list_cmd_context *ctx = (struct list_cmd_context *)_ctx;
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch unsigned int i;
de96afeeaa5242cffe89f1966457e935806b5746Stephan Bosch arg->value.str = p_strdup(ctx->search_args->pool, args[i]);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch struct mail_search_arg *subargs = ctx->search_args->args;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch arg = mail_search_build_add(ctx->search_args, SEARCH_OR);
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic struct doveadm_mail_cmd_context *cmd_mailbox_list_alloc(void)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch ctx = doveadm_mail_cmd_alloc(struct list_cmd_context);
7384b4e78eaab44693c985192276e31322155e32Stephan Boschcmd_mailbox_create_run(struct doveadm_mail_cmd_context *_ctx,
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch struct mailbox_cmd_context *ctx = (struct mailbox_cmd_context *)_ctx;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch const char *const *namep;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch unsigned int len;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch ns = mail_namespace_find(user->namespaces, &storage_name);
7944646fad6aa1e7c649c3d33e454c516b0220b6Timo Sirainen i_fatal("Can't find namespace for: %s", *namep);
b99130e4cf4af4e6b103b949456222f3a2dff424Timo Sirainen if (len > 0 && storage_name[len-1] == ns->real_sep) {
b99130e4cf4af4e6b103b949456222f3a2dff424Timo Sirainen storage_name = t_strndup(storage_name, len-1);
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 i_error("Can't create mailbox %s: %s", *namep,
4c4c4a740bbb1b674d4b0dae009d1919f8ad96b7Stephan Boschstatic void cmd_mailbox_create_init(struct doveadm_mail_cmd_context *_ctx,
4c4c4a740bbb1b674d4b0dae009d1919f8ad96b7Stephan Bosch const char *const args[])
4c4c4a740bbb1b674d4b0dae009d1919f8ad96b7Stephan Bosch struct mailbox_cmd_context *ctx = (struct mailbox_cmd_context *)_ctx;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch unsigned int i;
94d1b08c9e20d637db568a3eab3dfc2b9e96e62aStephan Boschstatic struct doveadm_mail_cmd_context *cmd_mailbox_create_alloc(void)
ad03049781fc14807248007d524be4daf06c3ee2Stephan Bosch ctx = doveadm_mail_cmd_alloc(struct mailbox_cmd_context);
feba5e502b2131c9a1c766b7ef9ff041dbf71d1dStephan Bosch p_array_init(&ctx->mailboxes, ctx->ctx.pool, 16);
5257840e8d31a6cb7051703b4cb0931c82aba638Stephan Boschcmd_mailbox_delete_run(struct doveadm_mail_cmd_context *_ctx,
70505f4839520ac67895992621c97d2480c22e7fTimo Sirainen struct mailbox_cmd_context *ctx = (struct mailbox_cmd_context *)_ctx;
c972eaa3565e849df71b44cf0cd45d38c5567d07Stephan Bosch const char *const *namep;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch ns = mail_namespace_find(user->namespaces, &storage_name);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch i_fatal("Can't find namespace for: %s", *namep);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch box = mailbox_alloc(ns->list, storage_name, 0);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch struct mail_storage *storage = mailbox_get_storage(box);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch i_error("Can't delete mailbox %s: %s", *namep,
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic void cmd_mailbox_delete_init(struct doveadm_mail_cmd_context *_ctx,
f9d2a1f21ad65262bc630f0834d7eead06a1bac3Timo Sirainen const char *const args[])
fca68889b287d8eed4babe72a231bd6079da012dStephan Bosch struct mailbox_cmd_context *ctx = (struct mailbox_cmd_context *)_ctx;
fca68889b287d8eed4babe72a231bd6079da012dStephan Bosch unsigned int i;
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic struct doveadm_mail_cmd_context *cmd_mailbox_delete_alloc(void)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch ctx = doveadm_mail_cmd_alloc(struct mailbox_cmd_context);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch p_array_init(&ctx->mailboxes, ctx->ctx.pool, 16);
7384b4e78eaab44693c985192276e31322155e32Stephan Boschcmd_mailbox_rename_run(struct doveadm_mail_cmd_context *_ctx,
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainen struct rename_cmd_context *ctx = (struct rename_cmd_context *)_ctx;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch oldns = mail_namespace_find(user->namespaces, &oldname);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch i_fatal("Can't find namespace for: %s", oldname);
636d0f43138468f8efe685a681326b123f660e49Timo Sirainen newns = mail_namespace_find(user->namespaces, &newname);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch i_fatal("Can't find namespace for: %s", newname);
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 i_error("Can't rename mailbox %s to %s: %s", oldname, newname,
fc94140acba51adafedafbc8491a3223a51db7a8Stephan Boschstatic void cmd_mailbox_rename_init(struct doveadm_mail_cmd_context *_ctx,
fc94140acba51adafedafbc8491a3223a51db7a8Stephan Bosch const char *const args[])
636d0f43138468f8efe685a681326b123f660e49Timo Sirainen struct rename_cmd_context *ctx = (struct rename_cmd_context *)_ctx;
fca68889b287d8eed4babe72a231bd6079da012dStephan Bosch ctx->oldname = p_strdup(ctx->ctx.pool, args[0]);
fca68889b287d8eed4babe72a231bd6079da012dStephan Bosch ctx->newname = p_strdup(ctx->ctx.pool, args[1]);
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic struct doveadm_mail_cmd_context *cmd_mailbox_rename_alloc(void)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch ctx = doveadm_mail_cmd_alloc(struct rename_cmd_context);
856ae2ad98cee79b2719911a3cc131d7f4ec8a90Timo Sirainen "[-7|-8] [<mailbox> [...]]"
1a9a35a6b307f8d5b25345af55e40a99162b4072Timo Sirainen "[-7|-8] <mailbox> [...]"
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch "[-7|-8] <mailbox> [...]"
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch "[-7|-8] <old name> <new name>"