doveadm-mail-mailbox-status.c revision a18da4410dcd47ab8d9b40c09a76a54fa55b9c86
76b43e4417bab52e913da39b5f5bc2a130d3f149Timo Sirainen/* Copyright (c) 2010-2016 Dovecot authors, see the included COPYING file */
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen (MAILBOX_METADATA_VIRTUAL_SIZE | MAILBOX_METADATA_GUID)
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen (STATUS_MESSAGES | STATUS_RECENT | STATUS_UNSEEN)
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenstatic void status_parse_fields(struct status_cmd_context *ctx,
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen const char *const *fields)
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen ctx->metadata_items |= MAILBOX_METADATA_VIRTUAL_SIZE;
4fdf60e22b5340fe35f083b9ea5eb3fd1cf2e742Timo Sirainen ((ctx->status_items & ~TOTAL_STATUS_ITEMS) != 0 ||
4fdf60e22b5340fe35f083b9ea5eb3fd1cf2e742Timo Sirainen (ctx->metadata_items & ~TOTAL_METADATA_ITEMS) != 0)) {
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen "Status field %s can't be used with -t", field);
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenstatus_output(struct status_cmd_context *ctx, struct mailbox *box,
4fdf60e22b5340fe35f083b9ea5eb3fd1cf2e742Timo Sirainen if ((ctx->status_items & STATUS_MESSAGES) != 0)
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen if ((ctx->status_items & STATUS_UIDNEXT) != 0)
a94936bafd127680184da114c6a177b37ff656e5Timo Sirainen if ((ctx->status_items & STATUS_UIDVALIDITY) != 0)
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen if ((ctx->status_items & STATUS_HIGHESTMODSEQ) != 0)
74f810327aca91b3375d3fc963bce8076785b1cbTimo Sirainen if ((ctx->metadata_items & MAILBOX_METADATA_VIRTUAL_SIZE) != 0)
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen if ((ctx->metadata_items & MAILBOX_METADATA_GUID) != 0)
a94936bafd127680184da114c6a177b37ff656e5Timo Sirainen doveadm_print(guid_128_to_string(metadata->guid));
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen struct mailbox_status *dest = &ctx->total_status;
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen ctx->total_metadata.virtual_size += metadata->virtual_size;
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenstatus_mailbox(struct status_cmd_context *ctx, const struct mailbox_info *info)
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen box = doveadm_mailbox_find(ctx->ctx.cur_mail_user, info->vname);
0a70a2e71658d168f75d1f075661d7936701343cTimo Sirainen if (mailbox_get_status(box, ctx->status_items, &status) < 0 ||
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen mailbox_get_metadata(box, ctx->metadata_items, &metadata) < 0) {
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen i_error("Mailbox %s: Failed to lookup mailbox status: %s",
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen mailbox_get_vname(box), mailbox_get_last_error(box, NULL));
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainencmd_mailbox_status_run(struct doveadm_mail_cmd_context *_ctx,
a94936bafd127680184da114c6a177b37ff656e5Timo Sirainen struct status_cmd_context *ctx = (struct status_cmd_context *)_ctx;
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen memset(&ctx->total_status, 0, sizeof(ctx->total_status));
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen memset(&ctx->total_metadata, 0, sizeof(ctx->total_metadata));
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen iter = doveadm_mailbox_list_iter_init(_ctx, user, ctx->search_args,
a94936bafd127680184da114c6a177b37ff656e5Timo Sirainen while ((info = doveadm_mailbox_list_iter_next(iter)) != NULL) {
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen if (doveadm_mailbox_list_iter_deinit(&iter) < 0)
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainenstatic void cmd_mailbox_status_init(struct doveadm_mail_cmd_context *_ctx,
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen const char *const args[])
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen struct status_cmd_context *ctx = (struct status_cmd_context *)_ctx;
fe363b433b8038a69b55169da9dca27892ad7d18Timo Sirainen status_parse_fields(ctx, t_strsplit_spaces(fields, " "));
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen ctx->search_args = doveadm_mail_mailbox_search_args_build(args+1);
597dba3488c648ffb375ee4a552bd52ac4346979Timo Sirainen if ((ctx->status_items & STATUS_MESSAGES) != 0)
a94936bafd127680184da114c6a177b37ff656e5Timo Sirainen if ((ctx->status_items & STATUS_UIDNEXT) != 0)
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen if ((ctx->status_items & STATUS_UIDVALIDITY) != 0)
a94936bafd127680184da114c6a177b37ff656e5Timo Sirainen if ((ctx->status_items & STATUS_HIGHESTMODSEQ) != 0)
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen if ((ctx->metadata_items & MAILBOX_METADATA_VIRTUAL_SIZE) != 0)
ea37a9aedfc3a6ff5f4ea10bc4eff4ca23f62a15Timo Sirainen if ((ctx->metadata_items & MAILBOX_METADATA_GUID) != 0)
return FALSE;
return TRUE;
DOVEADM_CMD_PARAM('\0', "fieldstr", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL | CMD_PARAM_FLAG_DO_NOT_EXPOSE) /* FIXME: horrible hack, remove me when possible */