Mercurial > dovecot > core-2.2
changeset 9885:af8424c95825 HEAD
dbox: Allow getting streams to messages being saved.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 06 Sep 2009 18:53:24 -0400 |
parents | 38fbf201824c |
children | ba690c9aea70 |
files | src/lib-storage/index/dbox/dbox-mail.c src/lib-storage/index/dbox/dbox-save.c src/lib-storage/index/dbox/dbox-storage.h |
diffstat | 3 files changed, 44 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/index/dbox/dbox-mail.c Sun Sep 06 17:20:04 2009 -0400 +++ b/src/lib-storage/index/dbox/dbox-mail.c Sun Sep 06 18:53:24 2009 -0400 @@ -143,12 +143,22 @@ return mail_set_aborted(_mail); do { - if (mail->open_file == NULL) { + if (mail->open_file != NULL) { + /* already open */ + } else if (_mail->uid != 0) { if (dbox_mail_lookup(mbox, mbox->ibox.view, _mail->seq, &mail->map_uid) < 0) return -1; if (dbox_mail_open_init(mail) < 0) return -1; + } else { + /* mail is being saved in this transaction */ + mail->open_file = + dbox_save_file_get_file(_mail->transaction, + _mail->seq, + &mail->offset); + mail->open_file->refcount++; + break; } if (!dbox_file_is_open(mail->open_file))
--- a/src/lib-storage/index/dbox/dbox-save.c Sun Sep 06 17:20:04 2009 -0400 +++ b/src/lib-storage/index/dbox/dbox-save.c Sun Sep 06 18:53:24 2009 -0400 @@ -53,6 +53,30 @@ unsigned int finished:1; }; +struct dbox_file * +dbox_save_file_get_file(struct mailbox_transaction_context *t, + uint32_t seq, uoff_t *offset_r) +{ + struct dbox_save_context *ctx = (struct dbox_save_context *)t->save_ctx; + const struct dbox_save_mail *mails, *mail; + unsigned int count; + + mails = array_get(&ctx->mails, &count); + i_assert(count > 0); + i_assert(seq >= mails[0].seq); + + mail = &mails[mails[0].seq - seq]; + i_assert(mail->seq == seq); + + if (o_stream_flush(mail->file->output) < 0) { + dbox_file_set_syscall_error(mail->file, "write()"); + ctx->failed = TRUE; + } + + *offset_r = mail->append_offset; + return mail->file; +} + struct mail_save_context * dbox_save_alloc(struct mailbox_transaction_context *t) { @@ -275,6 +299,11 @@ ctx->failed = TRUE; } T_END; + if (o_stream_flush(ctx->cur_output) < 0) { + dbox_file_set_syscall_error(save_mail->file, "write()"); + ctx->failed = TRUE; + } + o_stream_unref(&ctx->cur_output); i_stream_unref(&ctx->input);
--- a/src/lib-storage/index/dbox/dbox-storage.h Sun Sep 06 17:20:04 2009 -0400 +++ b/src/lib-storage/index/dbox/dbox-storage.h Sun Sep 06 18:53:24 2009 -0400 @@ -110,6 +110,10 @@ int dbox_save_finish(struct mail_save_context *ctx); void dbox_save_cancel(struct mail_save_context *ctx); +struct dbox_file * +dbox_save_file_get_file(struct mailbox_transaction_context *t, + uint32_t seq, uoff_t *offset_r); + int dbox_transaction_save_commit_pre(struct mail_save_context *ctx); void dbox_transaction_save_commit_post(struct mail_save_context *ctx); void dbox_transaction_save_rollback(struct mail_save_context *ctx);