imapc-save.c revision 29371e68adc180501454783b44ec8e43b4e6ddc1
5a580c3a38ced62d4bcc95b8ac7c4f2935b5d294Timo Sirainen/* Copyright (c) 2011 Dovecot authors, see the included COPYING file */
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainenvoid imapc_transaction_save_rollback(struct mail_save_context *_ctx);
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainenimapc_save_alloc(struct mailbox_transaction_context *t)
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen struct imapc_mailbox *mbox = (struct imapc_mailbox *)t->box;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen i_assert((t->flags & MAILBOX_TRANSACTION_FLAG_EXTERNAL) != 0);
d24f5d5563b9d444920e57d0c5cfc5797fcf687dTimo Sirainenint imapc_save_begin(struct mail_save_context *_ctx, struct istream *input)
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen struct imapc_save_context *ctx = (struct imapc_save_context *)_ctx;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen struct mail_storage *storage = _ctx->transaction->box->storage;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen ctx->fd = imapc_client_create_temp_fd(ctx->mbox->storage->client, &path);
9d8f243a8765cb8dc0b513df7add7475affed0bbTimo Sirainen /* we may not know the size of the input, or be sure that it contains
9d8f243a8765cb8dc0b513df7add7475affed0bbTimo Sirainen only CRLFs. so we'll always first write the mail to a temp file and
9d8f243a8765cb8dc0b513df7add7475affed0bbTimo Sirainen upload it from there to remote server. */
9d8f243a8765cb8dc0b513df7add7475affed0bbTimo Sirainen _ctx->output = o_stream_create_fd_file(ctx->fd, 0, FALSE);
d24f5d5563b9d444920e57d0c5cfc5797fcf687dTimo Sirainenint imapc_save_continue(struct mail_save_context *_ctx)
d24f5d5563b9d444920e57d0c5cfc5797fcf687dTimo Sirainen struct imapc_save_context *ctx = (struct imapc_save_context *)_ctx;
d24f5d5563b9d444920e57d0c5cfc5797fcf687dTimo Sirainen struct mail_storage *storage = _ctx->transaction->box->storage;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen if (o_stream_send_istream(_ctx->output, ctx->input) < 0) {
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen if (!mail_storage_set_error_from_errno(storage)) {
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen "o_stream_send_istream(%s) failed: %m",
36723cf206a7b64b9d972ab0719bbfaacc9316faTimo Sirainenstatic void imapc_save_appenduid(struct imapc_save_context *ctx,
36723cf206a7b64b9d972ab0719bbfaacc9316faTimo Sirainen const char *const *args;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen /* <uidvalidity> <dest uid-set> */
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen args = t_strsplit(reply->resp_text_value, " ");
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen if (str_to_uint32(args[0], &uid_validity) < 0)
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen else if (ctx->dest_uid_validity != uid_validity)
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen seq_range_array_add(&ctx->dest_saved_uids, 0, dest_uid);
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainenstatic void imapc_save_callback(const struct imapc_command_reply *reply,
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen if (strcasecmp(reply->resp_text_key, "APPENDUID") == 0)
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen } else if (reply->state == IMAPC_COMMAND_STATE_NO) {
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen imapc_copy_error_from_reply(ctx->ctx->mbox->storage,
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen mail_storage_set_critical(&ctx->ctx->mbox->storage->storage,
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen imapc_client_stop(ctx->ctx->mbox->storage->client);
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainenimapc_append_keywords(string_t *str, struct mail_keywords *kw)
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen const char *const *kw_p;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen unsigned int i;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainenstatic int imapc_save_append(struct imapc_save_context *ctx)
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen if (_ctx->flags != 0 || _ctx->keywords != NULL) {
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen imap_write_flags(str, _ctx->flags & ~MAIL_RECENT, NULL);
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen input = i_stream_create_fd(ctx->fd, IO_BLOCK_SIZE, FALSE);
const char *const *args;
void *context)