doveadm-mail-mailbox.c revision a18da4410dcd47ab8d9b40c09a76a54fa55b9c86
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen/* Copyright (c) 2010-2016 Dovecot authors, see the included COPYING file */
b321df9603081896b70ec44635af96d674a9839aTimo Sirainenvoid doveadm_mailbox_args_check(const char *const args[])
c02a056b724abd6578fb8c4e439de0e94eaea6feTimo Sirainen unsigned int i;
a9c8c1f74e5d2911d3c15657727a30b649d3bbc4Timo Sirainenstatic bool cmd_mailbox_parse_arg(struct doveadm_mail_cmd_context *_ctx, int c)
48010d123abfac8cb19f33f1fe12f33a7090089eTimo Sirainen (type *)doveadm_mailbox_cmd_alloc_size(sizeof(type))
f968e62caa52a8924bd05ebf76ff515b5c18e17bTimo Sirainencmd_mailbox_list_parse_arg(struct doveadm_mail_cmd_context *_ctx, int c)
dc8ba4890b74bde400e0feef96114940129ab181Timo Sirainen struct list_cmd_context *ctx = (struct list_cmd_context *)_ctx;
f968e62caa52a8924bd05ebf76ff515b5c18e17bTimo Sirainencmd_mailbox_list_run(struct doveadm_mail_cmd_context *_ctx,
f968e62caa52a8924bd05ebf76ff515b5c18e17bTimo Sirainen struct list_cmd_context *ctx = (struct list_cmd_context *)_ctx;
f968e62caa52a8924bd05ebf76ff515b5c18e17bTimo Sirainen iter_flags |= MAILBOX_LIST_ITER_SELECT_SUBSCRIBED;
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen iter = doveadm_mailbox_list_iter_full_init(_ctx, user, ctx->search_args,
f968e62caa52a8924bd05ebf76ff515b5c18e17bTimo Sirainen while ((info = doveadm_mailbox_list_iter_next(iter)) != NULL) {
f968e62caa52a8924bd05ebf76ff515b5c18e17bTimo Sirainen if (doveadm_mailbox_list_iter_deinit(&iter) < 0)
3c9783956dea385b322cd7fa6bf8c98c17a907a0Timo Sirainendoveadm_mail_mailbox_search_args_build(const char *const args[])
3c9783956dea385b322cd7fa6bf8c98c17a907a0Timo Sirainen unsigned int i;
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen arg = mail_search_build_add(search_args, type);
38ceb710e2bc957a66a75c68957cb87746682a75Timo Sirainen arg->value.str = p_strdup(search_args->pool, args[i]);
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen struct mail_search_arg *subargs = search_args->args;
a7bee3930831a9261fa6180d02af29c484d862e9Timo Sirainen arg = mail_search_build_add(search_args, SEARCH_OR);
e4d34f2fbee451219599d71505594df704093ce3Timo Sirainenstatic void cmd_mailbox_list_init(struct doveadm_mail_cmd_context *_ctx,
43d32cbe60fdaef2699d99f1ca259053e9350411Timo Sirainen const char *const args[])
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen struct list_cmd_context *ctx = (struct list_cmd_context *)_ctx;
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen ctx->search_args = doveadm_mail_mailbox_search_args_build(args);
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenstatic void cmd_mailbox_list_deinit(struct doveadm_mail_cmd_context *_ctx)
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen struct list_cmd_context *ctx = (struct list_cmd_context *)_ctx;
e4d34f2fbee451219599d71505594df704093ce3Timo Sirainenstatic struct doveadm_mail_cmd_context *cmd_mailbox_list_alloc(void)
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen ctx = doveadm_mailbox_cmd_alloc(struct list_cmd_context);
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen ctx->ctx.ctx.v.deinit = cmd_mailbox_list_deinit;
2cfe9983ce7a6280636ee12beccc2e865111967bTimo Sirainen ctx->ctx.ctx.v.parse_arg = cmd_mailbox_list_parse_arg;
48010d123abfac8cb19f33f1fe12f33a7090089eTimo Sirainencmd_mailbox_create_run(struct doveadm_mail_cmd_context *_ctx,
bb2b3656ef7635acc374f7fc19b25aeeb454ae95Timo Sirainen struct create_cmd_context *ctx = (struct create_cmd_context *)_ctx;
6135260095e1704ed6edff9d00bdfc043c11429cTimo Sirainen const char *const *namep;
35136dd2baf8dc30e4e754294ed81ff48e8c1e64Timo Sirainen unsigned int len;
bb2b3656ef7635acc374f7fc19b25aeeb454ae95Timo Sirainen ns = mail_namespace_find(user->namespaces, name);
35136dd2baf8dc30e4e754294ed81ff48e8c1e64Timo Sirainen if (len > 0 && name[len-1] == mail_namespace_get_sep(ns)) {
35136dd2baf8dc30e4e754294ed81ff48e8c1e64Timo Sirainen if (mailbox_create(box, &ctx->update, directory) < 0) {
38ceb710e2bc957a66a75c68957cb87746682a75Timo Sirainen i_error("Can't subscribe to mailbox %s: %s", name,
35136dd2baf8dc30e4e754294ed81ff48e8c1e64Timo Sirainenstatic void cmd_mailbox_create_init(struct doveadm_mail_cmd_context *_ctx,
35136dd2baf8dc30e4e754294ed81ff48e8c1e64Timo Sirainen const char *const args[])
849969f639a00eab26791db3cb1b66430420c0cdTimo Sirainen struct mailbox_cmd_context *ctx = (struct mailbox_cmd_context *)_ctx;
b321df9603081896b70ec44635af96d674a9839aTimo Sirainen unsigned int i;
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainencmd_mailbox_create_parse_arg(struct doveadm_mail_cmd_context *_ctx, int c)
b321df9603081896b70ec44635af96d674a9839aTimo Sirainen struct create_cmd_context *ctx = (struct create_cmd_context *)_ctx;
b321df9603081896b70ec44635af96d674a9839aTimo Sirainen if (guid_128_from_string(optarg, ctx->update.mailbox_guid) < 0)
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainenstatic struct doveadm_mail_cmd_context *cmd_mailbox_create_alloc(void)
1f1e81aab38d833d1c9cdc244c91fd762e0080d4Timo Sirainen ctx = doveadm_mailbox_cmd_alloc(struct create_cmd_context);
1f1e81aab38d833d1c9cdc244c91fd762e0080d4Timo Sirainen ctx->ctx.ctx.v.init = cmd_mailbox_create_init;
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen ctx->ctx.ctx.v.parse_arg = cmd_mailbox_create_parse_arg;
e4d34f2fbee451219599d71505594df704093ce3Timo Sirainen p_array_init(&ctx->mailboxes, ctx->ctx.ctx.pool, 16);
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenstatic int i_strcmp_reverse_p(const char *const *s1, const char *const *s2)
const char *name)
const char *const *namep;
int ret = 0;
*namep) < 0) {
return ret;
const char *const args[])
const char *name;
return FALSE;
return TRUE;
int ret = 0;
return ret;
const char *const args[])
const char *const *namep;
int ret = 0;
return ret;
const char *const args[])
const char *name;
static struct doveadm_mail_cmd_context *