bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2015-2018 Dovecot authors, see the included COPYING file */
e617d6e7db43c176502ac02b65d2dcb4d27103deTimo Sirainencmd_save_to_mailbox(struct save_cmd_context *ctx, struct mailbox *box,
e617d6e7db43c176502ac02b65d2dcb4d27103deTimo Sirainen struct mail_storage *storage = mailbox_get_storage(box);
bf7dc750b95039981c0e9d728f313d50cf38a156Martti Rannanjärvi mailbox_get_last_internal_error(box, NULL));
e617d6e7db43c176502ac02b65d2dcb4d27103deTimo Sirainen doveadm_mail_failed_storage(&ctx->ctx, storage);
0dab9cb35a976c49b28a11e28d5570f5191f1a7aMartti Rannanjärvi trans = mailbox_transaction_begin(box, MAILBOX_TRANSACTION_FLAG_EXTERNAL,
e617d6e7db43c176502ac02b65d2dcb4d27103deTimo Sirainen if (mailbox_save_begin(&save_ctx, input) < 0) {
bf7dc750b95039981c0e9d728f313d50cf38a156Martti Rannanjärvi mailbox_get_last_internal_error(box, NULL));
e617d6e7db43c176502ac02b65d2dcb4d27103deTimo Sirainen doveadm_mail_failed_storage(&ctx->ctx, storage);
e617d6e7db43c176502ac02b65d2dcb4d27103deTimo Sirainen i_error("read(msg input) failed: %s", i_stream_get_error(input));
e617d6e7db43c176502ac02b65d2dcb4d27103deTimo Sirainen doveadm_mail_failed_error(&ctx->ctx, MAIL_ERROR_TEMP);
bf7dc750b95039981c0e9d728f313d50cf38a156Martti Rannanjärvi mailbox_get_last_internal_error(box, NULL));
e617d6e7db43c176502ac02b65d2dcb4d27103deTimo Sirainen doveadm_mail_failed_storage(&ctx->ctx, storage);
e617d6e7db43c176502ac02b65d2dcb4d27103deTimo Sirainen } else if (mailbox_save_finish(&save_ctx) < 0) {
bf7dc750b95039981c0e9d728f313d50cf38a156Martti Rannanjärvi mailbox_get_last_internal_error(box, NULL));
e617d6e7db43c176502ac02b65d2dcb4d27103deTimo Sirainen doveadm_mail_failed_storage(&ctx->ctx, storage);
e617d6e7db43c176502ac02b65d2dcb4d27103deTimo Sirainen } else if (mailbox_transaction_commit(&trans) < 0) {
bf7dc750b95039981c0e9d728f313d50cf38a156Martti Rannanjärvi mailbox_get_last_internal_error(box, NULL));
e617d6e7db43c176502ac02b65d2dcb4d27103deTimo Sirainen doveadm_mail_failed_storage(&ctx->ctx, storage);
e617d6e7db43c176502ac02b65d2dcb4d27103deTimo Sirainencmd_save_run(struct doveadm_mail_cmd_context *_ctx, struct mail_user *user)
e617d6e7db43c176502ac02b65d2dcb4d27103deTimo Sirainen struct save_cmd_context *ctx = (struct save_cmd_context *)_ctx;
e617d6e7db43c176502ac02b65d2dcb4d27103deTimo Sirainen ns = mail_namespace_find(user->namespaces, ctx->mailbox);
e617d6e7db43c176502ac02b65d2dcb4d27103deTimo Sirainen box = mailbox_alloc(ns->list, ctx->mailbox, MAILBOX_FLAG_SAVEONLY);
e617d6e7db43c176502ac02b65d2dcb4d27103deTimo Sirainen ret = cmd_save_to_mailbox(ctx, box, _ctx->cmd_input);
e617d6e7db43c176502ac02b65d2dcb4d27103deTimo Sirainenstatic void cmd_save_init(struct doveadm_mail_cmd_context *_ctx,
e617d6e7db43c176502ac02b65d2dcb4d27103deTimo Sirainencmd_mailbox_save_parse_arg(struct doveadm_mail_cmd_context *_ctx, int c)
e617d6e7db43c176502ac02b65d2dcb4d27103deTimo Sirainen struct save_cmd_context *ctx = (struct save_cmd_context *)_ctx;
e617d6e7db43c176502ac02b65d2dcb4d27103deTimo Sirainenstatic struct doveadm_mail_cmd_context *cmd_save_alloc(void)
e617d6e7db43c176502ac02b65d2dcb4d27103deTimo Sirainen ctx = doveadm_mail_cmd_alloc(struct save_cmd_context);
e617d6e7db43c176502ac02b65d2dcb4d27103deTimo Sirainen ctx->ctx.v.parse_arg = cmd_mailbox_save_parse_arg;
c45a841bee3f42ec6524b8f62c3fd457115c3f97Timo Sirainen .usage = DOVEADM_CMD_MAIL_USAGE_PREFIX"[-m mailbox]",
5ba6009f4e5493c4e6be9ffb3134525004a7975cAki TuomiDOVEADM_CMD_PARAM('m', "mailbox", CMD_PARAM_STR, 0)