doveadm-mail-save.c revision 5ba6009f4e5493c4e6be9ffb3134525004a7975c
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen/* Copyright (c) 2015-2016 Dovecot authors, see the included COPYING file */
2e29e4797a48d78d669821722bdb54fd0a1d3b94Timo Sirainencmd_save_to_mailbox(struct save_cmd_context *ctx, struct mailbox *box,
2e29e4797a48d78d669821722bdb54fd0a1d3b94Timo Sirainen struct mail_storage *storage = mailbox_get_storage(box);
b624773984e35dd894db8dff976c1a2114c70782Timo Sirainen mailbox_get_vname(box), mailbox_get_last_error(box, NULL));
2e29e4797a48d78d669821722bdb54fd0a1d3b94Timo Sirainen doveadm_mail_failed_storage(&ctx->ctx, storage);
2e29e4797a48d78d669821722bdb54fd0a1d3b94Timo Sirainen trans = mailbox_transaction_begin(box, MAILBOX_TRANSACTION_FLAG_EXTERNAL);
2e29e4797a48d78d669821722bdb54fd0a1d3b94Timo Sirainen if (mailbox_save_begin(&save_ctx, input) < 0) {
2e29e4797a48d78d669821722bdb54fd0a1d3b94Timo Sirainen i_error("Saving failed: %s", mailbox_get_last_error(box, NULL));
3a7113e3e2dac0e333e1a3f62af7d682896f59c6Timo Sirainen doveadm_mail_failed_storage(&ctx->ctx, storage);
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen while ((ret = i_stream_read(input)) > 0 || ret == -2) {
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen i_error("read(msg input) failed: %s", i_stream_get_error(input));
788a0754cfd38dcfec1902844b085e4e84cfe7e6Timo Sirainen doveadm_mail_failed_error(&ctx->ctx, MAIL_ERROR_TEMP);
788a0754cfd38dcfec1902844b085e4e84cfe7e6Timo Sirainen i_error("Saving failed: %s", mailbox_get_last_error(box, NULL));
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen doveadm_mail_failed_storage(&ctx->ctx, storage);
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen } else if (mailbox_save_finish(&save_ctx) < 0) {
f93c833d644ecff0b0f80bee4f1cdde3e697b5c8Timo Sirainen doveadm_mail_failed_storage(&ctx->ctx, storage);
f93c833d644ecff0b0f80bee4f1cdde3e697b5c8Timo Sirainen } else if (mailbox_transaction_commit(&trans) < 0) {
f93c833d644ecff0b0f80bee4f1cdde3e697b5c8Timo Sirainen doveadm_mail_failed_storage(&ctx->ctx, storage);
2e29e4797a48d78d669821722bdb54fd0a1d3b94Timo Sirainencmd_save_run(struct doveadm_mail_cmd_context *_ctx, struct mail_user *user)
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen struct save_cmd_context *ctx = (struct save_cmd_context *)_ctx;
2e29e4797a48d78d669821722bdb54fd0a1d3b94Timo Sirainen ns = mail_namespace_find(user->namespaces, ctx->mailbox);
31597236d79ac38a5cea7ab65a9d0a3df64ed201Timo Sirainen box = mailbox_alloc(ns->list, ctx->mailbox, MAILBOX_FLAG_SAVEONLY);
2e29e4797a48d78d669821722bdb54fd0a1d3b94Timo Sirainen ret = cmd_save_to_mailbox(ctx, box, _ctx->cmd_input);
2e29e4797a48d78d669821722bdb54fd0a1d3b94Timo Sirainenstatic void cmd_save_init(struct doveadm_mail_cmd_context *_ctx,
83d2e37f065eabe38dc92db485c5ca39ee43ce05Timo Sirainencmd_mailbox_save_parse_arg(struct doveadm_mail_cmd_context *_ctx, int c)
83d2e37f065eabe38dc92db485c5ca39ee43ce05Timo Sirainen struct save_cmd_context *ctx = (struct save_cmd_context *)_ctx;
798cfe56c9871262770384da1239162b3800cce1Timo Sirainenstatic struct doveadm_mail_cmd_context *cmd_save_alloc(void)
c0757c70cfd2c9b44de3504b753a4d2f38690ef0Timo Sirainen ctx = doveadm_mail_cmd_alloc(struct save_cmd_context);
e2a88d59c0d47d63ce1ad5b1fd95e487124a3fd4Timo Sirainen ctx->ctx.v.parse_arg = cmd_mailbox_save_parse_arg;
798cfe56c9871262770384da1239162b3800cce1Timo Sirainenstruct doveadm_cmd_ver2 doveadm_cmd_save_ver2 = {
a138ac12134564b151f00fdef86fba9cd9ba8af0Timo SirainenDOVEADM_CMD_PARAM('m', "mailbox", CMD_PARAM_STR, 0)