mdbox-save.c revision ddedc8b77c5bccc8d224ab5f8716d9874f5d8512
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen/* Copyright (c) 2007-2012 Dovecot authors, see the included COPYING file */
00fa8dcbc66f56daa737487c9dec7166c37de79eTimo Sirainen struct dbox_file_append_context *cur_file_append;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen struct mdbox_map_transaction_context *map_trans;
2598b2f36365b52d9754b9348a5be29569293e46Timo Sirainenstatic struct dbox_file *
6303191abcb37164f435ccdc56e9dbddf1288851Timo Sirainenmdbox_copy_file_get_file(struct mailbox_transaction_context *t,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen mail_index_lookup_ext(t->view, seq, ctx->mbox->ext_id,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen if (mdbox_map_lookup(ctx->mbox->storage->map, rec->map_uid,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen return mdbox_file_init(ctx->mbox->storage, file_id);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenmdbox_save_file_get_file(struct mailbox_transaction_context *t,
97db4761382024093f441e4bc78ba8b6a056504dTimo Sirainen unsigned int count;
97db4761382024093f441e4bc78ba8b6a056504dTimo Sirainen /* copied mail */
bf72c930996df0691932fb1143f360d260f27a06Timo Sirainen return mdbox_copy_file_get_file(t, seq, offset_r);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen /* saved mail */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen if (dbox_file_append_flush(mail->file_append) < 0)
3612ee5c737954d5fb88fd1775aad80f7bf1dc4eTimo Sirainenmdbox_save_alloc(struct mailbox_transaction_context *t)
c49a19168dab6fda80aee16ad799a8a56d3bc18fTimo Sirainen struct mdbox_mailbox *mbox = (struct mdbox_mailbox *)t->box;
38cb3d139aefb7c65919cf4aba5ded7b5fd50e6fTimo Sirainen i_assert((t->flags & MAILBOX_TRANSACTION_FLAG_EXTERNAL) != 0);
bf72c930996df0691932fb1143f360d260f27a06Timo Sirainen /* use the existing allocated structure */
89795c6bbbc52bb382e88bc8617d22092223e9a5Timo Sirainen ctx->atomic = mdbox_map_atomic_begin(mbox->storage->map);
c49a19168dab6fda80aee16ad799a8a56d3bc18fTimo Sirainen ctx->append_ctx = mdbox_map_append_begin(ctx->atomic);
c0a708fa3f7b8f4fbca32052da5faf7a0125189dTimo Sirainenint mdbox_save_begin(struct mail_save_context *_ctx, struct istream *input)
ad004e44be109684521494b5af2ad1da39b8bb27Timo Sirainen struct mdbox_save_context *ctx = (struct mdbox_save_context *)_ctx;
f059a046515f4b2b15a6c2a10a6f12f6166e39a5Timo Sirainen /* get the size of the mail to be saved, if possible */
f059a046515f4b2b15a6c2a10a6f12f6166e39a5Timo Sirainen if (i_stream_get_size(input, TRUE, &mail_size) <= 0) {
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen /* we couldn't find out the exact size. fallback to non-exact,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen maybe it'll give something useful. the mail size is used
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen only to figure out if it's causing mdbox file to grow
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen too large. */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen mail_size = st->st_size > 0 ? st->st_size : 0;
c0a708fa3f7b8f4fbca32052da5faf7a0125189dTimo Sirainen if (mdbox_map_append_next(ctx->append_ctx, mail_size, 0,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen i_assert(ctx->ctx.dbox_output->offset <= (uint32_t)-1);
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen ctx->ctx.cur_file = ctx->cur_file_append->file;
00fa8dcbc66f56daa737487c9dec7166c37de79eTimo Sirainen save_mail->file_append = ctx->cur_file_append;
46ec792dd4ccf6c34706c4774228301fafde6aa9Timo Sirainenstatic int mdbox_save_mail_write_metadata(struct mdbox_save_context *ctx,
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen struct dbox_file *file = mail->file_append->file;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen i_assert(file->msg_header_size == sizeof(dbox_msg_hdr));
71f1783adc89b4fe3588c72b23e059b320da8fadTimo Sirainen mail->append_offset - mail->file_append->file->msg_header_size;
c0a708fa3f7b8f4fbca32052da5faf7a0125189dTimo Sirainen dbox_save_write_metadata(&ctx->ctx.ctx, ctx->ctx.dbox_output,
caea325346da6fb1cf503b35a619467a997acbfaTimo Sirainen /* save the 128bit GUID to index so if the map index gets corrupted
caea325346da6fb1cf503b35a619467a997acbfaTimo Sirainen we can still find the message */
c0a708fa3f7b8f4fbca32052da5faf7a0125189dTimo Sirainen mail_index_update_ext(ctx->ctx.trans, ctx->ctx.seq,
} T_END;
int ret;
return ret;
unsigned int i, count;
const void *data;
bool expunged;
for (i = 0; i < count; i++) {
&last_map_uid) < 0) {
if (first_map_uid != 0)
result);
const void *data;
bool expunged;