Lines Matching refs:ctx
24 struct dbox_save_context ctx;
36 #define SDBOX_SAVECTX(s) container_of(DBOX_SAVECTX(s), struct sdbox_save_context, ctx)
41 struct sdbox_save_context *ctx = SDBOX_SAVECTX(t->save_ctx);
45 i_assert(seq >= ctx->first_saved_seq);
47 files = array_get(&ctx->files, &count);
49 i_assert(seq - ctx->first_saved_seq < count);
51 file = files[seq - ctx->first_saved_seq];
60 struct sdbox_save_context *ctx = SDBOX_SAVECTX(t->save_ctx);
64 if (ctx != NULL) {
66 ctx->cur_file = NULL;
67 ctx->ctx.failed = FALSE;
68 ctx->ctx.finished = FALSE;
69 ctx->ctx.dbox_output = NULL;
70 return &ctx->ctx.ctx;
73 ctx = i_new(struct sdbox_save_context, 1);
74 ctx->ctx.ctx.transaction = t;
75 ctx->ctx.trans = t->itrans;
76 ctx->mbox = mbox;
77 i_array_init(&ctx->files, 32);
78 t->save_ctx = &ctx->ctx.ctx;
84 struct sdbox_save_context *ctx = SDBOX_SAVECTX(_ctx);
88 if (ctx->first_saved_seq == 0)
89 ctx->first_saved_seq = ctx->ctx.seq;
91 files = array_get(&ctx->files, &count);
97 array_append(&ctx->files, &file, 1);
102 struct sdbox_save_context *ctx = SDBOX_SAVECTX(_ctx);
106 file = sdbox_file_create(ctx->mbox);
107 ctx->append_ctx = dbox_file_append_init(file);
108 ret = dbox_file_get_append_stream(ctx->append_ctx,
109 &ctx->ctx.dbox_output);
112 dbox_file_append_rollback(&ctx->append_ctx);
114 ctx->ctx.failed = TRUE;
117 ctx->cur_file = file;
118 dbox_save_begin(&ctx->ctx, input);
121 return ctx->ctx.failed ? -1 : 0;
124 static int dbox_save_mail_write_metadata(struct dbox_save_context *ctx,
137 message_size = ctx->dbox_output->offset -
140 dbox_save_write_metadata(&ctx->ctx, ctx->dbox_output,
143 if (o_stream_pwrite(ctx->dbox_output, &dbox_msg_hdr,
152 extrefs_arr = index_attachment_save_get_extrefs(&ctx->ctx);
175 struct sdbox_save_context *ctx = (struct sdbox_save_context *)_ctx;
178 ctx->ctx.finished = TRUE;
179 if (ctx->ctx.dbox_output == NULL)
189 dbox_save_end(&ctx->ctx);
191 files = array_idx_modifiable(&ctx->files, array_count(&ctx->files) - 1);
192 if (!ctx->ctx.failed) T_BEGIN {
193 if (dbox_save_mail_write_metadata(&ctx->ctx, *files) < 0)
194 ctx->ctx.failed = TRUE;
197 if (ctx->ctx.failed) {
198 index_storage_save_abort_last(&ctx->ctx.ctx, ctx->ctx.seq);
199 dbox_file_append_rollback(&ctx->append_ctx);
202 array_delete(&ctx->files, array_count(&ctx->files) - 1, 1);
204 dbox_file_append_checkpoint(ctx->append_ctx);
205 if (dbox_file_append_commit(&ctx->append_ctx) < 0)
206 ctx->ctx.failed = TRUE;
210 i_stream_unref(&ctx->ctx.input);
211 ctx->ctx.dbox_output = NULL;
213 return ctx->ctx.failed ? -1 : 0;
216 int sdbox_save_finish(struct mail_save_context *ctx)
220 ret = dbox_save_finish_write(ctx);
221 index_save_context_free(ctx);
227 struct dbox_save_context *ctx = DBOX_SAVECTX(_ctx);
229 ctx->failed = TRUE;
233 static int dbox_save_assign_uids(struct sdbox_save_context *ctx,
243 files = array_get(&ctx->files, &count);
251 if (ctx->ctx.highest_pop3_uidl_seq == i+1) {
252 index_pop3_uidl_set_max_uid(&ctx->mbox->box,
253 ctx->ctx.trans, uid);
260 static int dbox_save_assign_stub_uids(struct sdbox_save_context *ctx)
265 files = array_get(&ctx->files, &count);
270 mail_index_lookup_uid(ctx->ctx.trans->view,
271 ctx->first_saved_seq + i, &uid);
281 static void dbox_save_unref_files(struct sdbox_save_context *ctx)
286 files = array_get_modifiable(&ctx->files, &count);
288 if (ctx->ctx.failed) {
296 array_free(&ctx->files);
301 struct sdbox_save_context *ctx = SDBOX_SAVECTX(_ctx);
305 i_assert(ctx->ctx.finished);
307 if (array_count(&ctx->files) == 0) {
312 if (sdbox_sync_begin(ctx->mbox, SDBOX_SYNC_FLAG_FORCE |
313 SDBOX_SYNC_FLAG_FSYNC, &ctx->sync_ctx) < 0) {
319 dbox_save_update_header_flags(&ctx->ctx, ctx->sync_ctx->sync_view,
320 ctx->mbox->hdr_ext_id, offsetof(struct sdbox_index_header, flags));
322 hdr = mail_index_get_header(ctx->sync_ctx->sync_view);
326 mail_index_append_finish_uids(ctx->ctx.trans, hdr->next_uid,
328 if (dbox_save_assign_uids(ctx, &_t->changes->saved_uids) < 0) {
334 if (dbox_save_assign_stub_uids(ctx) < 0) {
347 struct sdbox_save_context *ctx = SDBOX_SAVECTX(_ctx);
352 if (array_count(&ctx->files) == 0) {
357 mail_index_sync_set_commit_result(ctx->sync_ctx->index_sync_ctx,
360 if (sdbox_sync_finish(&ctx->sync_ctx, TRUE) < 0)
361 ctx->ctx.failed = TRUE;
364 const char *box_path = mailbox_get_path(&ctx->mbox->box);
376 struct sdbox_save_context *ctx = SDBOX_SAVECTX(_ctx);
378 if (!ctx->ctx.finished)
380 dbox_save_unref_files(ctx);
382 if (ctx->sync_ctx != NULL)
383 (void)sdbox_sync_finish(&ctx->sync_ctx, FALSE);
384 i_free(ctx);