mdbox-save.c revision 7f735cb86b2d8abd8f230089065eacfc24e9e5d6
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen/* Copyright (c) 2007-2010 Dovecot authors, see the included COPYING file */
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen struct dbox_file_append_context *cur_file_append;
09c3a491f4f6ccebe290c7709bdc0d79a187610bTimo Sirainen struct mdbox_map_transaction_context *map_trans;
515f81466f673c1b4f72e053f1a9686e6fca6b61Timo Sirainenstatic struct dbox_file *
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenmdbox_copy_file_get_file(struct mailbox_transaction_context *t,
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen mail_index_lookup_ext(t->view, seq, ctx->mbox->ext_id,
aa38d1a0945f0bc13a225d043f53fad2eec666b1Timo Sirainen if (mdbox_map_lookup(ctx->mbox->storage->map, rec->map_uid,
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainen return mdbox_file_init(ctx->mbox->storage, file_id);
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainenmdbox_save_file_get_file(struct mailbox_transaction_context *t,
fee561b9d9162b130e662914fcebc9dd99b5c320Timo Sirainen unsigned int count;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen /* copied mail */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen return mdbox_copy_file_get_file(t, seq, offset_r);
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen /* saved mail */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen if (dbox_file_append_flush(mail->file_append) < 0)
a022088674a5ae72ed29ae001834cbad62a4f19fTimo Sirainenmdbox_save_alloc(struct mailbox_transaction_context *t)
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen struct mdbox_mailbox *mbox = (struct mdbox_mailbox *)t->box;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen i_assert((t->flags & MAILBOX_TRANSACTION_FLAG_EXTERNAL) != 0);
8872e5c991430f96138a46e36b7f3c2c40d8e5c2Timo Sirainen /* use the existing allocated structure */
985fa802913c96ce6f2e25bbc788ee39c416a7e0Timo Sirainen ctx->atomic = mdbox_map_atomic_begin(mbox->storage->map);
0c909e3461607eadcd66f4eac69b7f34e37fccf1Timo Sirainen ctx->append_ctx = mdbox_map_append_begin(ctx->atomic);
3fe9483b2b412a14493e3120751b0e99ecfe9388Timo Sirainenint mdbox_save_begin(struct mail_save_context *_ctx, struct istream *input)
3fe9483b2b412a14493e3120751b0e99ecfe9388Timo Sirainen struct mdbox_save_context *ctx = (struct mdbox_save_context *)_ctx;
515f81466f673c1b4f72e053f1a9686e6fca6b61Timo Sirainen /* get the size of the mail to be saved, if possible */
3fe9483b2b412a14493e3120751b0e99ecfe9388Timo Sirainen if (i_stream_get_size(input, TRUE, &mail_size) <= 0) {
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainen /* we couldn't find out the exact size. fallback to non-exact,
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainen maybe it'll give something useful. the mail size is used
02bb8313a711dfe50c7f01e8132e13ca93ecfb42Timo Sirainen only to figure out if it's causing mdbox file to grow
5e88e4624aa6d482b5b195acd2f4e02aeb385f20Timo Sirainen too large. */
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen mail_size = st->st_size > 0 ? st->st_size : 0;
0c909e3461607eadcd66f4eac69b7f34e37fccf1Timo Sirainen if (mdbox_map_append_next(ctx->append_ctx, mail_size, 0,
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen i_assert(ctx->ctx.dbox_output->offset <= (uint32_t)-1);
16c28dd75976f94acc4940d6ba68b6cd4853aac7Timo Sirainen ctx->ctx.cur_file = ctx->cur_file_append->file;
} 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;