Mercurial > dovecot > core-2.2
changeset 10660:56b1d4dd9c7d HEAD
lib-storage: *_mailboxes don't descend from index_mailbox anymore, it's now a context.
line wrap: on
line diff
--- a/src/lib-storage/index/cydir/cydir-save.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/cydir/cydir-save.c Sun Feb 07 17:30:24 2010 +0200 @@ -50,8 +50,7 @@ { const char *dir; - dir = mailbox_list_get_path(ctx->mbox->ibox.box.list, - ctx->mbox->ibox.box.name, + dir = mailbox_list_get_path(ctx->mbox->box.list, ctx->mbox->box.name, MAILBOX_LIST_PATH_TYPE_MAILBOX); return t_strdup_printf("%s/%s.%u", dir, ctx->tmp_basename, num); } @@ -262,8 +261,7 @@ &_t->changes->saved_uids); _t->changes->uid_validity = ctx->sync_ctx->uid_validity; - dir = mailbox_list_get_path(ctx->mbox->ibox.box.list, - ctx->mbox->ibox.box.name, + dir = mailbox_list_get_path(ctx->mbox->box.list, ctx->mbox->box.name, MAILBOX_LIST_PATH_TYPE_MAILBOX); src_path = t_str_new(256);
--- a/src/lib-storage/index/cydir/cydir-storage.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/cydir/cydir-storage.c Sun Feb 07 17:30:24 2010 +0200 @@ -54,6 +54,7 @@ enum mailbox_flags flags) { struct cydir_mailbox *mbox; + struct index_mailbox_context *ibox; pool_t pool; /* cydir can't work without index files */ @@ -61,24 +62,25 @@ pool = pool_alloconly_create("cydir mailbox", 1024+512); mbox = p_new(pool, struct cydir_mailbox, 1); - mbox->ibox.box = cydir_mailbox; - mbox->ibox.box.pool = pool; - mbox->ibox.box.storage = storage; - mbox->ibox.box.list = list; - mbox->ibox.box.mail_vfuncs = &cydir_mail_vfuncs; + mbox->box = cydir_mailbox; + mbox->box.pool = pool; + mbox->box.storage = storage; + mbox->box.list = list; + mbox->box.mail_vfuncs = &cydir_mail_vfuncs; - mbox->ibox.save_commit_pre = cydir_transaction_save_commit_pre; - mbox->ibox.save_commit_post = cydir_transaction_save_commit_post; - mbox->ibox.save_rollback = cydir_transaction_save_rollback; - - index_storage_mailbox_alloc(&mbox->ibox, name, input, flags, + index_storage_mailbox_alloc(&mbox->box, name, input, flags, CYDIR_INDEX_PREFIX); - mail_index_set_fsync_types(mbox->ibox.box.index, + mail_index_set_fsync_types(mbox->box.index, MAIL_INDEX_SYNC_TYPE_APPEND | MAIL_INDEX_SYNC_TYPE_EXPUNGE); + ibox = INDEX_STORAGE_CONTEXT(&mbox->box); + ibox->save_commit_pre = cydir_transaction_save_commit_pre; + ibox->save_commit_post = cydir_transaction_save_commit_post; + ibox->save_rollback = cydir_transaction_save_rollback; + mbox->storage = (struct cydir_storage *)storage; - return &mbox->ibox.box; + return &mbox->box; } static int cydir_mailbox_open(struct mailbox *box) @@ -111,7 +113,7 @@ box->path); return -1; } - return index_storage_mailbox_open(box); + return index_storage_mailbox_open(box, FALSE); } static int @@ -222,9 +224,9 @@ struct cydir_mailbox *mbox = (struct cydir_mailbox *)box; if (box->notify_callback == NULL) - index_mailbox_check_remove_all(&mbox->ibox); + index_mailbox_check_remove_all(&mbox->box); else - index_mailbox_check_add(&mbox->ibox, mbox->ibox.box.path); + index_mailbox_check_add(&mbox->box, mbox->box.path); } static int cydir_list_iter_is_mailbox(struct mailbox_list_iterate_context *ctx
--- a/src/lib-storage/index/cydir/cydir-storage.h Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/cydir/cydir-storage.h Sun Feb 07 17:30:24 2010 +0200 @@ -14,7 +14,7 @@ }; struct cydir_mailbox { - struct index_mailbox ibox; + struct mailbox box; struct cydir_storage *storage; };
--- a/src/lib-storage/index/cydir/cydir-sync.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/cydir/cydir-sync.c Sun Feb 07 17:30:24 2010 +0200 @@ -21,7 +21,7 @@ string_t *path = str_new(default_pool, 256); const char *dir; - dir = mailbox_list_get_path(mbox->ibox.box.list, mbox->ibox.box.name, + dir = mailbox_list_get_path(mbox->box.list, mbox->box.name, MAILBOX_LIST_PATH_TYPE_MAILBOX); str_append(path, dir); str_append_c(path, '/'); @@ -31,7 +31,7 @@ static void cydir_sync_expunge(struct cydir_sync_context *ctx, uint32_t seq1, uint32_t seq2) { - struct mailbox *box = &ctx->mbox->ibox.box; + struct mailbox *box = &ctx->mbox->box; uint32_t uid; if (ctx->path == NULL) { @@ -60,7 +60,7 @@ static void cydir_sync_index(struct cydir_sync_context *ctx) { - struct mailbox *box = &ctx->mbox->ibox.box; + struct mailbox *box = &ctx->mbox->box; const struct mail_index_header *hdr; struct mail_index_sync_rec sync_rec; uint32_t seq1, seq2; @@ -74,7 +74,7 @@ /* mark the newly seen messages as recent */ if (mail_index_lookup_seq_range(ctx->sync_view, hdr->first_recent_uid, hdr->next_uid, &seq1, &seq2)) { - index_mailbox_set_recent_seq(&ctx->mbox->ibox, ctx->sync_view, + index_mailbox_set_recent_seq(&ctx->mbox->box, ctx->sync_view, seq1, seq2); } @@ -117,17 +117,17 @@ ctx->mbox = mbox; sync_flags = MAIL_INDEX_SYNC_FLAG_FLUSH_DIRTY; - if ((mbox->ibox.box.flags & MAILBOX_FLAG_KEEP_RECENT) == 0) + if ((mbox->box.flags & MAILBOX_FLAG_KEEP_RECENT) == 0) sync_flags |= MAIL_INDEX_SYNC_FLAG_DROP_RECENT; if (!force) sync_flags |= MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES; - ret = mail_index_sync_begin(mbox->ibox.box.index, &ctx->index_sync_ctx, + ret = mail_index_sync_begin(mbox->box.index, &ctx->index_sync_ctx, &ctx->sync_view, &ctx->trans, sync_flags); if (ret <= 0) { if (ret < 0) - mail_storage_set_index_error(&mbox->ibox.box); + mail_storage_set_index_error(&mbox->box); i_free(ctx); *ctx_r = NULL; return ret; @@ -146,7 +146,7 @@ *_ctx = NULL; if (success) { if (mail_index_sync_commit(&ctx->index_sync_ctx) < 0) { - mail_storage_set_index_error(&ctx->mbox->ibox.box); + mail_storage_set_index_error(&ctx->mbox->box); ret = -1; } } else { @@ -180,7 +180,7 @@ ret = -1; } - if (index_mailbox_want_full_sync(&mbox->ibox, flags) && ret == 0) + if (index_mailbox_want_full_sync(&mbox->box, flags) && ret == 0) ret = cydir_sync(mbox); return index_mailbox_sync_init(box, flags, ret < 0);
--- a/src/lib-storage/index/dbox-common/dbox-mail.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/dbox-common/dbox-mail.c Sun Feb 07 17:30:24 2010 +0200 @@ -148,7 +148,8 @@ const char **value_r) { struct index_mail *imail = &mail->imail; - const struct mail_cache_field *cache_fields = imail->ibox->cache_fields; + struct index_mailbox_context *ibox = + INDEX_STORAGE_CONTEXT(imail->mail.mail.box); struct dbox_file *file; const char *value; string_t *str; @@ -156,7 +157,7 @@ str = str_new(imail->data_pool, 64); if (mail_cache_lookup_field(imail->trans->cache_view, str, imail->mail.mail.seq, - cache_fields[cache_field].idx) > 0) { + ibox->cache_fields[cache_field].idx) > 0) { *value_r = str_c(str); return 0; } @@ -167,7 +168,7 @@ value = dbox_file_metadata_get(file, key); if (value == NULL) value = ""; - index_mail_cache_add_idx(imail, cache_fields[cache_field].idx, + index_mail_cache_add_idx(imail, ibox->cache_fields[cache_field].idx, value, strlen(value)+1); *value_r = value; return 0;
--- a/src/lib-storage/index/dbox-common/dbox-storage.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/dbox-common/dbox-storage.c Sun Feb 07 17:30:24 2010 +0200 @@ -39,16 +39,15 @@ void dbox_notify_changes(struct mailbox *box) { - struct index_mailbox *ibox = (struct index_mailbox *)box; const char *dir, *path; if (box->notify_callback == NULL) - index_mailbox_check_remove_all(ibox); + index_mailbox_check_remove_all(box); else { dir = mailbox_list_get_path(box->list, box->name, MAILBOX_LIST_PATH_TYPE_INDEX); path = t_strdup_printf("%s/"DBOX_INDEX_PREFIX".log", dir); - index_mailbox_check_add(ibox, path); + index_mailbox_check_add(box, path); } } @@ -86,7 +85,7 @@ mailbox_list_get_dir_permissions(box->list, NULL, &mode, &gid, &origin); if (mkdir_parents_chgrp(box->path, mode, gid, origin) == 0) { /* create indexes immediately with the dbox header */ - if (index_storage_mailbox_open(box) < 0) + if (index_storage_mailbox_open(box, FALSE) < 0) return -1; if (storage->v.mailbox_create_indexes(box, update) < 0) return -1; @@ -109,7 +108,7 @@ } if (dbox_cleanup_if_exists(box->list, box->path)) { - return index_storage_mailbox_open(box); + return index_storage_mailbox_open(box, FALSE); } else if (errno == ENOENT) { if (strcmp(box->name, "INBOX") == 0 && (box->list->ns->flags & NAMESPACE_FLAG_INBOX) != 0) { @@ -117,7 +116,7 @@ if (dbox_mailbox_create_indexes(box, NULL) < 0) return -1; return box->opened ? 0 : - index_storage_mailbox_open(box); + index_storage_mailbox_open(box, FALSE); } mail_storage_set_error(box->storage, MAIL_ERROR_NOTFOUND, @@ -163,7 +162,7 @@ (box->list->props & MAILBOX_LIST_PROP_NO_NOSELECT) == 0) return 0; - if (index_storage_mailbox_open(box) < 0) + if (index_storage_mailbox_open(box, FALSE) < 0) return -1; if (storage->v.mailbox_create_indexes(box, update) < 0) return -1;
--- a/src/lib-storage/index/dbox-common/dbox-sync-rebuild.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/dbox-common/dbox-sync-rebuild.c Sun Feb 07 17:30:24 2010 +0200 @@ -84,21 +84,20 @@ } struct dbox_sync_rebuild_context * -dbox_sync_index_rebuild_init(struct index_mailbox *ibox, +dbox_sync_index_rebuild_init(struct mailbox *box, struct mail_index_view *view, struct mail_index_transaction *trans) { - struct mailbox *box = &ibox->box; struct dbox_sync_rebuild_context *ctx; const char *index_dir; enum mail_index_open_flags open_flags = MAIL_INDEX_OPEN_FLAG_READONLY; ctx = i_new(struct dbox_sync_rebuild_context, 1); - ctx->ibox = ibox; + ctx->box = box; ctx->view = view; ctx->trans = trans; mail_index_reset(ctx->trans); - index_mailbox_reset_uidvalidity(ibox); + index_mailbox_reset_uidvalidity(box); mail_index_ext_lookup(box->index, "cache", &ctx->cache_ext_id); /* if backup index file exists, try to use it */
--- a/src/lib-storage/index/dbox-common/dbox-sync-rebuild.h Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/dbox-common/dbox-sync-rebuild.h Sun Feb 07 17:30:24 2010 +0200 @@ -2,7 +2,7 @@ #define DBOX_SYNC_REBUILD_H struct dbox_sync_rebuild_context { - struct index_mailbox *ibox; + struct mailbox *box; struct mail_index_view *view; struct mail_index_transaction *trans; @@ -16,7 +16,7 @@ }; struct dbox_sync_rebuild_context * -dbox_sync_index_rebuild_init(struct index_mailbox *mbox, +dbox_sync_index_rebuild_init(struct mailbox *box, struct mail_index_view *view, struct mail_index_transaction *trans); void dbox_sync_index_rebuild_deinit(struct dbox_sync_rebuild_context **ctx);
--- a/src/lib-storage/index/dbox-multi/mdbox-mail.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/dbox-multi/mdbox-mail.c Sun Feb 07 17:30:24 2010 +0200 @@ -28,7 +28,7 @@ mail_index_lookup_uid(view, seq, &uid); mail_storage_set_critical(&mbox->storage->storage.storage, "dbox %s: map uid lost for uid %u", - mbox->ibox.box.path, uid); + mbox->box.path, uid); mbox->storage->storage.files_corrupted = TRUE; return -1; } @@ -47,7 +47,7 @@ if (cur_map_uid_validity != mbox->map_uid_validity) { mail_storage_set_critical(&mbox->storage->storage.storage, "dbox %s: map uidvalidity mismatch (%u vs %u)", - mbox->ibox.box.path, mbox->map_uid_validity, + mbox->box.path, mbox->map_uid_validity, cur_map_uid_validity); mbox->storage->storage.files_corrupted = TRUE; return -1; @@ -58,8 +58,8 @@ static void dbox_mail_set_expunged(struct dbox_mail *mail, uint32_t map_uid) { - struct mdbox_mailbox *mbox = (struct mdbox_mailbox *)mail->imail.ibox; struct mail *_mail = &mail->imail.mail.mail; + struct mdbox_mailbox *mbox = (struct mdbox_mailbox *)_mail->box; (void)mail_index_refresh(_mail->box->index); if (mail_index_is_expunged(_mail->box->view, _mail->seq)) { @@ -75,7 +75,8 @@ static int dbox_mail_open_init(struct dbox_mail *mail, uint32_t map_uid) { - struct mdbox_mailbox *mbox = (struct mdbox_mailbox *)mail->imail.ibox; + struct mdbox_mailbox *mbox = + (struct mdbox_mailbox *)mail->imail.mail.mail.box; uint32_t file_id; int ret; @@ -98,8 +99,8 @@ int mdbox_mail_open(struct dbox_mail *mail, uoff_t *offset_r, struct dbox_file **file_r) { - struct mdbox_mailbox *mbox = (struct mdbox_mailbox *)mail->imail.ibox; struct mail *_mail = &mail->imail.mail.mail; + struct mdbox_mailbox *mbox = (struct mdbox_mailbox *)_mail->box; uint32_t prev_file_id = 0, map_uid = 0; bool deleted;
--- a/src/lib-storage/index/dbox-multi/mdbox-save.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/dbox-multi/mdbox-save.c Sun Feb 07 17:30:24 2010 +0200 @@ -146,7 +146,7 @@ mail->append_offset - mail->file_append->file->msg_header_size; dbox_save_write_metadata(&ctx->ctx.ctx, ctx->ctx.cur_output, - ctx->mbox->ibox.box.name, guid_128); + ctx->mbox->box.name, guid_128); /* save the 128bit GUID to index so if the map index gets corrupted we can still find the message */ mail_index_update_ext(ctx->ctx.trans, ctx->ctx.seq, @@ -298,9 +298,9 @@ dbox_map_append_free(&ctx->append_ctx); if (!ctx->mbox->storage->storage.storage.set->fsync_disable) { - if (fdatasync_path(ctx->mbox->ibox.box.path) < 0) { + if (fdatasync_path(ctx->mbox->box.path) < 0) { i_error("fdatasync_path(%s) failed: %m", - ctx->mbox->ibox.box.path); + ctx->mbox->box.path); } } mdbox_transaction_save_rollback(_ctx);
--- a/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c Sun Feb 07 17:30:24 2010 +0200 @@ -429,7 +429,7 @@ return -1; } - rebuild_ctx = dbox_sync_index_rebuild_init(&mbox->ibox, view, trans); + rebuild_ctx = dbox_sync_index_rebuild_init(&mbox->box, view, trans); rebuild_mailbox_multi(ctx, rebuild_ctx, mbox, view, trans); dbox_sync_index_rebuild_deinit(&rebuild_ctx);
--- a/src/lib-storage/index/dbox-multi/mdbox-storage.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/dbox-multi/mdbox-storage.c Sun Feb 07 17:30:24 2010 +0200 @@ -105,6 +105,7 @@ enum mailbox_flags flags) { struct mdbox_mailbox *mbox; + struct index_mailbox_context *ibox; pool_t pool; /* dbox can't work without index files */ @@ -112,37 +113,37 @@ pool = pool_alloconly_create("mdbox mailbox", 1024+512); mbox = p_new(pool, struct mdbox_mailbox, 1); - mbox->ibox.box = mdbox_mailbox; - mbox->ibox.box.pool = pool; - mbox->ibox.box.storage = storage; - mbox->ibox.box.list = list; - mbox->ibox.box.mail_vfuncs = &mdbox_mail_vfuncs; + mbox->box = mdbox_mailbox; + mbox->box.pool = pool; + mbox->box.storage = storage; + mbox->box.list = list; + mbox->box.mail_vfuncs = &mdbox_mail_vfuncs; - mbox->ibox.save_commit_pre = mdbox_transaction_save_commit_pre; - mbox->ibox.save_commit_post = mdbox_transaction_save_commit_post; - mbox->ibox.save_rollback = mdbox_transaction_save_rollback; - - index_storage_mailbox_alloc(&mbox->ibox, name, input, flags, + index_storage_mailbox_alloc(&mbox->box, name, input, flags, DBOX_INDEX_PREFIX); - mail_index_set_fsync_types(mbox->ibox.box.index, + mail_index_set_fsync_types(mbox->box.index, MAIL_INDEX_SYNC_TYPE_APPEND | MAIL_INDEX_SYNC_TYPE_EXPUNGE); - mbox->ibox.index_flags |= MAIL_INDEX_OPEN_FLAG_KEEP_BACKUPS | + ibox = INDEX_STORAGE_CONTEXT(&mbox->box); + ibox->save_commit_pre = mdbox_transaction_save_commit_pre; + ibox->save_commit_post = mdbox_transaction_save_commit_post; + ibox->save_rollback = mdbox_transaction_save_rollback; + ibox->index_flags |= MAIL_INDEX_OPEN_FLAG_KEEP_BACKUPS | MAIL_INDEX_OPEN_FLAG_NEVER_IN_MEMORY; mbox->storage = (struct mdbox_storage *)storage; mbox->ext_id = - mail_index_ext_register(mbox->ibox.box.index, "mdbox", 0, + mail_index_ext_register(mbox->box.index, "mdbox", 0, sizeof(struct mdbox_mail_index_record), sizeof(uint32_t)); mbox->hdr_ext_id = - mail_index_ext_register(mbox->ibox.box.index, "mdbox-hdr", + mail_index_ext_register(mbox->box.index, "mdbox-hdr", sizeof(struct mdbox_index_header), 0, 0); mbox->guid_ext_id = - mail_index_ext_register(mbox->ibox.box.index, "guid", + mail_index_ext_register(mbox->box.index, "guid", 0, MAIL_GUID_128_SIZE, 1); - return &mbox->ibox.box; + return &mbox->box; } int mdbox_read_header(struct mdbox_mailbox *mbox, @@ -151,13 +152,13 @@ const void *data; size_t data_size; - mail_index_get_header_ext(mbox->ibox.box.view, mbox->hdr_ext_id, + mail_index_get_header_ext(mbox->box.view, mbox->hdr_ext_id, &data, &data_size); if (data_size < MDBOX_INDEX_HEADER_MIN_SIZE && (!mbox->creating || data_size != 0)) { mail_storage_set_critical(&mbox->storage->storage.storage, "dbox %s: Invalid dbox header size", - mbox->ibox.box.path); + mbox->box.path); return -1; } memset(hdr, 0, sizeof(*hdr)); @@ -285,7 +286,7 @@ mdbox_mailbox_update(struct mailbox *box, const struct mailbox_update *update) { if (!box->opened) { - if (index_storage_mailbox_open(box) < 0) + if (index_storage_mailbox_open(box, FALSE) < 0) return -1; } return mdbox_write_index_header(box, update);
--- a/src/lib-storage/index/dbox-multi/mdbox-storage.h Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/dbox-multi/mdbox-storage.h Sun Feb 07 17:30:24 2010 +0200 @@ -38,7 +38,7 @@ }; struct mdbox_mailbox { - struct index_mailbox ibox; + struct mailbox box; struct mdbox_storage *storage; uint32_t map_uid_validity;
--- a/src/lib-storage/index/dbox-multi/mdbox-sync.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/dbox-multi/mdbox-sync.c Sun Feb 07 17:30:24 2010 +0200 @@ -32,7 +32,7 @@ mail_storage_set_critical(&ctx->mbox->storage->storage.storage, "Mailbox %s: Expunged GUID mismatch for UID %u: %s vs %s", - ctx->mbox->ibox.box.vname, uid, + ctx->mbox->box.vname, uid, binary_to_hex(data, MAIL_GUID_128_SIZE), binary_to_hex(guid_128, MAIL_GUID_128_SIZE)); ctx->mbox->storage->storage.files_corrupted = TRUE; @@ -86,7 +86,7 @@ static void dbox_sync_mark_expunges(struct mdbox_sync_context *ctx) { - struct mailbox *box = &ctx->mbox->ibox.box; + struct mailbox *box = &ctx->mbox->box; struct seq_range_iter iter; unsigned int n; const void *data; @@ -123,7 +123,7 @@ static int mdbox_sync_index(struct mdbox_sync_context *ctx) { - struct mailbox *box = &ctx->mbox->ibox.box; + struct mailbox *box = &ctx->mbox->box; const struct mail_index_header *hdr; struct mail_index_sync_rec sync_rec; uint32_t seq1, seq2; @@ -138,7 +138,7 @@ /* mark the newly seen messages as recent */ if (mail_index_lookup_seq_range(ctx->sync_view, hdr->first_recent_uid, hdr->next_uid, &seq1, &seq2)) { - index_mailbox_set_recent_seq(&ctx->mbox->ibox, ctx->sync_view, + index_mailbox_set_recent_seq(&ctx->mbox->box, ctx->sync_view, seq1, seq2); } @@ -167,14 +167,14 @@ struct mdbox_index_header hdr; int ret; - view = mail_index_view_open(mbox->ibox.box.index); + view = mail_index_view_open(mbox->box.index); ret = mdbox_read_header(mbox, &hdr); mail_index_view_close(&view); if (ret == 0) { ret = mbox->storage->storage.files_corrupted ? -1 : 0; } else if (retry) { - (void)mail_index_refresh(mbox->ibox.box.index); + (void)mail_index_refresh(mbox->box.index); return mdbox_refresh_header(mbox, FALSE); } return ret; @@ -183,7 +183,7 @@ int mdbox_sync_begin(struct mdbox_mailbox *mbox, enum mdbox_sync_flags flags, struct mdbox_sync_context **ctx_r) { - struct mail_storage *storage = mbox->ibox.box.storage; + struct mail_storage *storage = mbox->box.storage; struct mdbox_sync_context *ctx; enum mail_index_sync_flags sync_flags = 0; unsigned int i; @@ -195,7 +195,7 @@ if (rebuild) { if (mdbox_storage_rebuild(mbox->storage) < 0) return -1; - index_mailbox_reset_uidvalidity(&mbox->ibox); + index_mailbox_reset_uidvalidity(&mbox->box); storage_rebuilt = TRUE; } @@ -203,7 +203,7 @@ ctx->mbox = mbox; ctx->flags = flags; - if ((mbox->ibox.box.flags & MAILBOX_FLAG_KEEP_RECENT) == 0) + if ((mbox->box.flags & MAILBOX_FLAG_KEEP_RECENT) == 0) sync_flags |= MAIL_INDEX_SYNC_FLAG_DROP_RECENT; if (!rebuild && (flags & MDBOX_SYNC_FLAG_FORCE) == 0) sync_flags |= MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES; @@ -213,13 +213,13 @@ sync_flags |= MAIL_INDEX_SYNC_FLAG_AVOID_FLAG_UPDATES; for (i = 0;; i++) { - ret = mail_index_sync_begin(mbox->ibox.box.index, + ret = mail_index_sync_begin(mbox->box.index, &ctx->index_sync_ctx, &ctx->sync_view, &ctx->trans, sync_flags); if (ret <= 0) { if (ret < 0) - mail_storage_set_index_error(&mbox->ibox.box); + mail_storage_set_index_error(&mbox->box); i_free(ctx); *ctx_r = NULL; return ret; @@ -246,7 +246,7 @@ } mail_storage_set_critical(storage, "dbox %s: Storage keeps breaking", - ctx->mbox->ibox.box.path); + ctx->mbox->box.path); ret = -1; } mail_index_sync_rollback(&ctx->index_sync_ctx); @@ -269,7 +269,7 @@ if (success) { if (mail_index_sync_commit(&ctx->index_sync_ctx) < 0) { - mail_storage_set_index_error(&ctx->mbox->ibox.box); + mail_storage_set_index_error(&ctx->mbox->box); ret = -1; } } else { @@ -304,7 +304,7 @@ ret = -1; } - if (ret == 0 && (index_mailbox_want_full_sync(&mbox->ibox, flags) || + if (ret == 0 && (index_mailbox_want_full_sync(&mbox->box, flags) || mbox->storage->storage.files_corrupted)) { if ((flags & MAILBOX_SYNC_FLAG_FORCE_RESYNC) != 0) mdbox_sync_flags |= MDBOX_SYNC_FLAG_FORCE_REBUILD;
--- a/src/lib-storage/index/dbox-single/sdbox-file.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/dbox-single/sdbox-file.c Sun Feb 07 17:30:24 2010 +0200 @@ -13,7 +13,7 @@ i_free(file->file.primary_path); i_free(file->file.alt_path); file->file.primary_path = - i_strdup_printf("%s/%s", file->mbox->ibox.box.path, fname); + i_strdup_printf("%s/%s", file->mbox->box.path, fname); if (file->mbox->alt_path != NULL) { file->file.alt_path = i_strdup_printf("%s/%s", file->mbox->alt_path, fname); @@ -36,7 +36,7 @@ } else { file->file.primary_path = i_strdup_printf("%s/%s", - file->mbox->ibox.box.path, + file->mbox->box.path, dbox_generate_tmp_filename()); } } T_END; @@ -59,7 +59,7 @@ old_path = file->file.cur_path; new_fname = t_strdup_printf(SDBOX_MAIL_FILE_FORMAT, uid); - new_path = t_strdup_printf("%s/%s", file->mbox->ibox.box.path, + new_path = t_strdup_printf("%s/%s", file->mbox->box.path, new_fname); if (rename(old_path, new_path) < 0) { mail_storage_set_critical(&file->file.storage->storage, @@ -75,7 +75,7 @@ int sdbox_file_create_fd(struct dbox_file *file, const char *path, bool parents) { struct sdbox_file *sfile = (struct sdbox_file *)file; - struct mailbox *box = &sfile->mbox->ibox.box; + struct mailbox *box = &sfile->mbox->box; const char *p, *dir; mode_t old_mask; int fd;
--- a/src/lib-storage/index/dbox-single/sdbox-mail.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/dbox-single/sdbox-mail.c Sun Feb 07 17:30:24 2010 +0200 @@ -14,8 +14,8 @@ static void sdbox_mail_set_expunged(struct dbox_mail *mail) { - struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)mail->imail.ibox; struct mail *_mail = &mail->imail.mail.mail; + struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)_mail->box; (void)mail_index_refresh(_mail->box->index); if (mail_index_is_expunged(_mail->box->view, _mail->seq)) {
--- a/src/lib-storage/index/dbox-single/sdbox-save.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/dbox-single/sdbox-save.c Sun Feb 07 17:30:24 2010 +0200 @@ -270,9 +270,9 @@ ctx->ctx.failed = TRUE; if (!ctx->mbox->storage->storage.storage.set->fsync_disable) { - if (fdatasync_path(ctx->mbox->ibox.box.path) < 0) { + if (fdatasync_path(ctx->mbox->box.path) < 0) { i_error("fdatasync_path(%s) failed: %m", - ctx->mbox->ibox.box.path); + ctx->mbox->box.path); } } sdbox_transaction_save_rollback(_ctx);
--- a/src/lib-storage/index/dbox-single/sdbox-storage.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/dbox-single/sdbox-storage.c Sun Feb 07 17:30:24 2010 +0200 @@ -54,6 +54,7 @@ enum mailbox_flags flags) { struct sdbox_mailbox *mbox; + struct index_mailbox_context *ibox; pool_t pool; /* dbox can't work without index files */ @@ -61,23 +62,23 @@ pool = pool_alloconly_create("dbox mailbox", 1024+512); mbox = p_new(pool, struct sdbox_mailbox, 1); - mbox->ibox.box = sdbox_mailbox; - mbox->ibox.box.pool = pool; - mbox->ibox.box.storage = storage; - mbox->ibox.box.list = list; - mbox->ibox.box.mail_vfuncs = &sdbox_mail_vfuncs; + mbox->box = sdbox_mailbox; + mbox->box.pool = pool; + mbox->box.storage = storage; + mbox->box.list = list; + mbox->box.mail_vfuncs = &sdbox_mail_vfuncs; - mbox->ibox.save_commit_pre = sdbox_transaction_save_commit_pre; - mbox->ibox.save_commit_post = sdbox_transaction_save_commit_post; - mbox->ibox.save_rollback = sdbox_transaction_save_rollback; - - index_storage_mailbox_alloc(&mbox->ibox, name, input, flags, + index_storage_mailbox_alloc(&mbox->box, name, input, flags, DBOX_INDEX_PREFIX); - mail_index_set_fsync_types(mbox->ibox.box.index, + mail_index_set_fsync_types(mbox->box.index, MAIL_INDEX_SYNC_TYPE_APPEND | MAIL_INDEX_SYNC_TYPE_EXPUNGE); - mbox->ibox.index_flags |= MAIL_INDEX_OPEN_FLAG_KEEP_BACKUPS | + ibox = INDEX_STORAGE_CONTEXT(&mbox->box); + ibox->save_commit_pre = sdbox_transaction_save_commit_pre; + ibox->save_commit_post = sdbox_transaction_save_commit_post; + ibox->save_rollback = sdbox_transaction_save_rollback; + ibox->index_flags |= MAIL_INDEX_OPEN_FLAG_KEEP_BACKUPS | MAIL_INDEX_OPEN_FLAG_NEVER_IN_MEMORY; mbox->storage = (struct sdbox_storage *)storage; @@ -85,9 +86,9 @@ p_strconcat(pool, list->set.alt_dir, "/", list->set.maildir_name, NULL); mbox->hdr_ext_id = - mail_index_ext_register(mbox->ibox.box.index, "dbox-hdr", + mail_index_ext_register(mbox->box.index, "dbox-hdr", sizeof(struct sdbox_index_header), 0, 0); - return &mbox->ibox.box; + return &mbox->box; } int sdbox_read_header(struct sdbox_mailbox *mbox, @@ -96,13 +97,13 @@ const void *data; size_t data_size; - mail_index_get_header_ext(mbox->ibox.box.view, mbox->hdr_ext_id, + mail_index_get_header_ext(mbox->box.view, mbox->hdr_ext_id, &data, &data_size); if (data_size < SDBOX_INDEX_HEADER_MIN_SIZE && (!mbox->creating || data_size != 0)) { mail_storage_set_critical(&mbox->storage->storage.storage, "dbox %s: Invalid dbox header size", - mbox->ibox.box.path); + mbox->box.path); return -1; } memset(hdr, 0, sizeof(*hdr)); @@ -224,7 +225,7 @@ dbox_mailbox_update(struct mailbox *box, const struct mailbox_update *update) { if (!box->opened) { - if (index_storage_mailbox_open(box) < 0) + if (index_storage_mailbox_open(box, FALSE) < 0) return -1; } return sdbox_write_index_header(box, update);
--- a/src/lib-storage/index/dbox-single/sdbox-storage.h Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/dbox-single/sdbox-storage.h Sun Feb 07 17:30:24 2010 +0200 @@ -24,7 +24,7 @@ }; struct sdbox_mailbox { - struct index_mailbox ibox; + struct mailbox box; struct sdbox_storage *storage; uint32_t hdr_ext_id;
--- a/src/lib-storage/index/dbox-single/sdbox-sync-file.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/dbox-single/sdbox-sync-file.c Sun Feb 07 17:30:24 2010 +0200 @@ -32,7 +32,7 @@ dbox_sync_mark_single_file_expunged(struct sdbox_sync_context *ctx, const struct sdbox_sync_file_entry *entry) { - struct mailbox *box = &ctx->mbox->ibox.box; + struct mailbox *box = &ctx->mbox->box; uint32_t seq; mail_index_lookup_seq(ctx->sync_view, entry->uid, &seq);
--- a/src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c Sun Feb 07 17:30:24 2010 +0200 @@ -12,13 +12,12 @@ static void sdbox_sync_set_uidvalidity(struct dbox_sync_rebuild_context *ctx) { - struct mailbox *box = &ctx->ibox->box; uint32_t uid_validity; /* if uidvalidity is set in the old index, use it */ uid_validity = mail_index_get_header(ctx->view)->uid_validity; if (uid_validity == 0) - uid_validity = dbox_get_uidvalidity_next(box->list); + uid_validity = dbox_get_uidvalidity_next(ctx->box->list); mail_index_update_header(ctx->trans, offsetof(struct mail_index_header, uid_validity), @@ -58,7 +57,7 @@ sdbox_sync_add_file(struct dbox_sync_rebuild_context *ctx, const char *fname, bool primary) { - struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)ctx->ibox; + struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)ctx->box; struct dbox_file *file; unsigned long uid; char *p; @@ -72,7 +71,7 @@ uid = strtoul(fname, &p, 10); if (*p != '\0' || uid == 0 || uid >= (uint32_t)-1) { i_warning("dbox %s: Ignoring invalid filename %s", - ctx->ibox->box.path, fname); + ctx->box->path, fname); return 0; } @@ -87,7 +86,7 @@ static int sdbox_sync_index_rebuild_dir(struct dbox_sync_rebuild_context *ctx, const char *path, bool primary) { - struct mail_storage *storage = ctx->ibox->box.storage; + struct mail_storage *storage = ctx->box->storage; DIR *dir; struct dirent *d; int ret = 0; @@ -99,7 +98,7 @@ /* alt directory doesn't exist, ignore */ return 0; } - mailbox_set_deleted(&ctx->ibox->box); + mailbox_set_deleted(ctx->box); return -1; } mail_storage_set_critical(storage, @@ -129,7 +128,7 @@ static void sdbox_sync_update_header(struct dbox_sync_rebuild_context *ctx) { - struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)ctx->ibox; + struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)ctx->box; struct sdbox_index_header hdr; if (sdbox_read_header(mbox, &hdr) < 0) @@ -143,11 +142,11 @@ static int sdbox_sync_index_rebuild_singles(struct dbox_sync_rebuild_context *ctx) { - struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)ctx->ibox; + struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)ctx->box; int ret = 0; sdbox_sync_set_uidvalidity(ctx); - if (sdbox_sync_index_rebuild_dir(ctx, ctx->ibox->box.path, TRUE) < 0) + if (sdbox_sync_index_rebuild_dir(ctx, ctx->box->path, TRUE) < 0) ret = -1; else if (mbox->alt_path != NULL) ret = sdbox_sync_index_rebuild_dir(ctx, mbox->alt_path, FALSE); @@ -162,11 +161,11 @@ struct mail_index_transaction *trans; int ret; - view = mail_index_view_open(mbox->ibox.box.index); + view = mail_index_view_open(mbox->box.index); trans = mail_index_transaction_begin(view, MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL); - ctx = dbox_sync_index_rebuild_init(&mbox->ibox, view, trans); + ctx = dbox_sync_index_rebuild_init(&mbox->box, view, trans); ret = sdbox_sync_index_rebuild_singles(ctx); dbox_sync_index_rebuild_deinit(&ctx);
--- a/src/lib-storage/index/dbox-single/sdbox-sync.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/dbox-single/sdbox-sync.c Sun Feb 07 17:30:24 2010 +0200 @@ -90,7 +90,7 @@ static int sdbox_sync_index(struct sdbox_sync_context *ctx) { - struct mailbox *box = &ctx->mbox->ibox.box; + struct mailbox *box = &ctx->mbox->box; const struct mail_index_header *hdr; struct mail_index_sync_rec sync_rec; struct hash_iterate_context *iter; @@ -107,7 +107,7 @@ /* mark the newly seen messages as recent */ if (mail_index_lookup_seq_range(ctx->sync_view, hdr->first_recent_uid, hdr->next_uid, &seq1, &seq2)) { - index_mailbox_set_recent_seq(&ctx->mbox->ibox, ctx->sync_view, + index_mailbox_set_recent_seq(&ctx->mbox->box, ctx->sync_view, seq1, seq2); } @@ -148,14 +148,14 @@ struct sdbox_index_header hdr; int ret; - view = mail_index_view_open(mbox->ibox.box.index); + view = mail_index_view_open(mbox->box.index); ret = sdbox_read_header(mbox, &hdr); mail_index_view_close(&view); if (ret == 0) { ret = mbox->sync_rebuild ? -1 : 0; } else if (retry) { - (void)mail_index_refresh(mbox->ibox.box.index); + (void)mail_index_refresh(mbox->box.index); return sdbox_refresh_header(mbox, FALSE); } return ret; @@ -164,7 +164,7 @@ int sdbox_sync_begin(struct sdbox_mailbox *mbox, enum sdbox_sync_flags flags, struct sdbox_sync_context **ctx_r) { - struct mail_storage *storage = mbox->ibox.box.storage; + struct mail_storage *storage = mbox->box.storage; struct sdbox_sync_context *ctx; enum mail_index_sync_flags sync_flags = 0; unsigned int i; @@ -178,7 +178,7 @@ ctx->mbox = mbox; ctx->flags = flags; - if ((mbox->ibox.box.flags & MAILBOX_FLAG_KEEP_RECENT) == 0) + if ((mbox->box.flags & MAILBOX_FLAG_KEEP_RECENT) == 0) sync_flags |= MAIL_INDEX_SYNC_FLAG_DROP_RECENT; if (!rebuild && (flags & SDBOX_SYNC_FLAG_FORCE) == 0) sync_flags |= MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES; @@ -188,13 +188,13 @@ sync_flags |= MAIL_INDEX_SYNC_FLAG_AVOID_FLAG_UPDATES; for (i = 0;; i++) { - ret = mail_index_sync_begin(mbox->ibox.box.index, + ret = mail_index_sync_begin(mbox->box.index, &ctx->index_sync_ctx, &ctx->sync_view, &ctx->trans, sync_flags); if (ret <= 0) { if (ret < 0) - mail_storage_set_index_error(&mbox->ibox.box); + mail_storage_set_index_error(&mbox->box); i_free(ctx); *ctx_r = NULL; return ret; @@ -214,12 +214,12 @@ if (i >= SDBOX_REBUILD_COUNT) { mail_storage_set_critical(storage, "dbox %s: Index keeps breaking", - ctx->mbox->ibox.box.path); + ctx->mbox->box.path); ret = -1; } else { /* do a full resync and try again. */ i_warning("dbox %s: Rebuilding index", - ctx->mbox->ibox.box.path); + ctx->mbox->box.path); ret = sdbox_sync_index_rebuild(mbox); } } @@ -243,7 +243,7 @@ if (success) { if (mail_index_sync_commit(&ctx->index_sync_ctx) < 0) { - mail_storage_set_index_error(&ctx->mbox->ibox.box); + mail_storage_set_index_error(&ctx->mbox->box); ret = -1; } } else { @@ -280,7 +280,7 @@ ret = -1; } - if (ret == 0 && (index_mailbox_want_full_sync(&mbox->ibox, flags) || + if (ret == 0 && (index_mailbox_want_full_sync(&mbox->box, flags) || mbox->sync_rebuild)) { if ((flags & MAILBOX_SYNC_FLAG_FORCE_RESYNC) != 0) sdbox_sync_flags |= SDBOX_SYNC_FLAG_FORCE_REBUILD;
--- a/src/lib-storage/index/index-mail-headers.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/index-mail-headers.c Sun Feb 07 17:30:24 2010 +0200 @@ -180,7 +180,7 @@ unsigned int i, count; all_cache_fields = - mail_cache_register_get_list(mail->ibox->box.cache, + mail_cache_register_get_list(mail->mail.mail.box->cache, pool_datastack_create(), &count); for (i = 0; i < count; i++) { if (strncasecmp(all_cache_fields[i].name, "hdr.", 4) != 0) @@ -248,7 +248,7 @@ Date: header. if we have Date field's index set at this point we know that we want it. otherwise add it and remember that we don't want it cached. */ - field_idx = get_header_field_idx(&mail->ibox->box, "Date", + field_idx = get_header_field_idx(mail->mail.mail.box, "Date", MAIL_CACHE_DECISION_NO); match = array_get(&mail->header_match, &match_count); if (field_idx < match_count && @@ -284,6 +284,7 @@ struct message_header_line *hdr, struct index_mail *mail) { + struct mail *_mail = &mail->mail.mail; struct index_mail_data *data = &mail->data; unsigned int field_idx, count; uint8_t *match; @@ -319,7 +320,7 @@ const char *cache_field_name = t_strconcat("hdr.", hdr->name, NULL); data->parse_line.field_idx = - mail_cache_register_lookup(mail->ibox->box.cache, + mail_cache_register_lookup(_mail->box->cache, cache_field_name); } T_END; } @@ -481,7 +482,7 @@ mail->data.stream->v_offset; mail->data.save_envelope = TRUE; - header_ctx = mailbox_header_lookup_init(&mail->ibox->box, + header_ctx = mailbox_header_lookup_init(mail->mail.mail.box, imap_envelope_headers); if (mail_get_header_stream(&mail->mail.mail, header_ctx, &stream) < 0) { mailbox_header_lookup_unref(&header_ctx); @@ -606,7 +607,7 @@ i_assert(field != NULL); - field_idx = get_header_field_idx(&mail->ibox->box, field, + field_idx = get_header_field_idx(mail->mail.mail.box, field, MAIL_CACHE_DECISION_TEMP); dest = str_new(mail->data_pool, 128); @@ -620,7 +621,7 @@ /* parse */ headers[0] = field; headers[1] = NULL; headers_ctx = mailbox_header_lookup_init( - &mail->ibox->box, headers); + mail->mail.mail.box, headers); ret = index_mail_parse_headers(mail, headers_ctx); mailbox_header_lookup_unref(&headers_ctx); if (ret < 0)
--- a/src/lib-storage/index/index-mail.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/index-mail.c Sun Feb 07 17:30:24 2010 +0200 @@ -69,7 +69,7 @@ parts = message_part_deserialize(mail->data_pool, part_buf->data, part_buf->used, &error); if (parts == NULL) { - mail_cache_set_corrupted(mail->ibox->box.cache, + mail_cache_set_corrupted(mail->mail.mail.box->cache, "Corrupted cached message_part data (%s)", error); } return parts; @@ -134,7 +134,7 @@ flags = rec->flags & (MAIL_FLAGS_NONRECENT | MAIL_INDEX_MAIL_FLAG_BACKEND); - if (index_mailbox_is_recent(mail->ibox, _mail->uid)) + if (index_mailbox_is_recent(_mail->box, _mail->uid)) flags |= MAIL_RECENT; return flags; @@ -423,13 +423,14 @@ void index_mail_cache_add_idx(struct index_mail *mail, unsigned int field_idx, const void *data, size_t data_size) { - const struct mail_storage_settings *set = mail->ibox->box.storage->set; + const struct mail_storage_settings *set = + mail->mail.mail.box->storage->set; const struct mail_index_header *hdr; if (set->mail_cache_min_mail_count > 0) { /* First check if we've configured caching not to be used with low enough message count. */ - hdr = mail_index_get_header(mail->ibox->box.view); + hdr = mail_index_get_header(mail->mail.mail.box->view); if (hdr->messages_count < set->mail_cache_min_mail_count) return; } @@ -527,7 +528,7 @@ return; } - decision = mail_cache_field_get_decision(mail->ibox->box.cache, + decision = mail_cache_field_get_decision(mail->mail.mail.box->cache, cache_field); if (decision == (MAIL_CACHE_DECISION_NO | MAIL_CACHE_DECISION_FORCED)) { /* we never want it cached */ @@ -611,7 +612,7 @@ /* normally don't cache both BODY and BODYSTRUCTURE, but do it if BODY is forced to be cached */ - dec = mail_cache_field_get_decision(mail->ibox->box.cache, + dec = mail_cache_field_get_decision(mail->mail.mail.box->cache, cache_field_body); if (plain_bodystructure || (bodystructure_cached && @@ -1080,7 +1081,6 @@ enum mail_fetch_field wanted_fields, struct mailbox_header_lookup_ctx *_wanted_headers) { - struct index_mailbox *ibox = (struct index_mailbox *)_t->box; struct index_transaction_context *t = (struct index_transaction_context *)_t; struct index_header_lookup_ctx *wanted_headers = @@ -1090,18 +1090,18 @@ array_create(&mail->mail.module_contexts, mail->mail.pool, sizeof(void *), 5); - mail->mail.v = *ibox->box.mail_vfuncs; - mail->mail.mail.box = &ibox->box; + mail->mail.v = *_t->box->mail_vfuncs; + mail->mail.mail.box = _t->box; mail->mail.mail.transaction = &t->mailbox_ctx; mail->mail.wanted_fields = wanted_fields; mail->mail.wanted_headers = _wanted_headers; - hdr = mail_index_get_header(ibox->box.view); + hdr = mail_index_get_header(_t->box->view); mail->uid_validity = hdr->uid_validity; t->mail_ref_count++; mail->data_pool = pool_alloconly_create("index_mail", 16384); - mail->ibox = ibox; + mail->ibox = INDEX_STORAGE_CONTEXT(_t->box); mail->trans = t; mail->wanted_fields = wanted_fields; if (wanted_headers != NULL) { @@ -1183,7 +1183,7 @@ /* don't waste time doing full checks for all required headers. assume that if we have "hdr.message-id" cached, we don't need to parse the header. */ - cache_field_hdr = mail_cache_register_lookup(mail->ibox->box.cache, + cache_field_hdr = mail_cache_register_lookup(mail->mail.mail.box->cache, "hdr.message-id"); if (cache_field_hdr == (unsigned int)-1 || mail_cache_field_exists(mail->trans->cache_view, @@ -1307,7 +1307,7 @@ /* open the stream only if we didn't get here from mailbox_save_init() */ - hdr = mail_index_get_header(mail->ibox->box.view); + hdr = mail_index_get_header(_mail->box->view); if (_mail->uid != 0 && _mail->uid < hdr->next_uid) (void)mail_get_stream(_mail, NULL, NULL, &input); } @@ -1432,7 +1432,7 @@ struct index_mail *imail = (struct index_mail *)mail; if ((flags & MAIL_RECENT) == 0 && - index_mailbox_is_recent(imail->ibox, mail->uid)) + index_mailbox_is_recent(mail->box, mail->uid)) index_mail_drop_recent_flag(imail); flags &= MAIL_FLAGS_NONRECENT | MAIL_INDEX_MAIL_FLAG_BACKEND;
--- a/src/lib-storage/index/index-mail.h Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/index-mail.h Sun Feb 07 17:30:24 2010 +0200 @@ -116,9 +116,9 @@ struct index_mail { struct mail_private mail; struct index_mail_data data; + struct index_mailbox_context *ibox; pool_t data_pool; - struct index_mailbox *ibox; struct index_transaction_context *trans; uint32_t uid_validity;
--- a/src/lib-storage/index/index-mailbox-check.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/index-mailbox-check.c Sun Feb 07 17:30:24 2010 +0200 @@ -23,15 +23,18 @@ struct io *io; }; -static void notify_delay_callback(struct index_mailbox *ibox) +static void notify_delay_callback(struct mailbox *box) { + struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box); + if (ibox->notify_delay_to != NULL) timeout_remove(&ibox->notify_delay_to); - ibox->box.notify_callback(&ibox->box, ibox->box.notify_context); + box->notify_callback(box, box->notify_context); } -static void check_timeout(struct index_mailbox *ibox) +static void check_timeout(struct mailbox *box) { + struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box); struct index_notify_file *file; struct stat st; bool notify = FALSE; @@ -45,29 +48,31 @@ } if (notify) - notify_delay_callback(ibox); + notify_delay_callback(box); } -static void notify_callback(struct index_mailbox *ibox) +static void notify_callback(struct mailbox *box) { + struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box); + timeout_reset(ibox->notify_to); if (ibox->notify_delay_to == NULL) { ibox->notify_delay_to = timeout_add(NOTIFY_DELAY_MSECS, - notify_delay_callback, ibox); + notify_delay_callback, box); } } -void index_mailbox_check_add(struct index_mailbox *ibox, - const char *path) +void index_mailbox_check_add(struct mailbox *box, const char *path) { + struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box); struct index_notify_file *file; struct stat st; struct io *io = NULL; struct index_notify_io *aio; - (void)io_add_notify(path, notify_callback, ibox, &io); + (void)io_add_notify(path, notify_callback, box, &io); if (io != NULL) { aio = i_new(struct index_notify_io, 1); aio->io = io; @@ -87,13 +92,14 @@ * when the filesystem is remote (NFS, ...) */ if (ibox->notify_to == NULL) { ibox->notify_to = - timeout_add(ibox->box.notify_min_interval * 1000, - check_timeout, ibox); + timeout_add(box->notify_min_interval * 1000, + check_timeout, box); } } -void index_mailbox_check_remove_all(struct index_mailbox *ibox) +void index_mailbox_check_remove_all(struct mailbox *box) { + struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box); struct index_notify_file *file; struct index_notify_io *aio;
--- a/src/lib-storage/index/index-search.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/index-search.c Sun Feb 07 17:30:24 2010 +0200 @@ -40,7 +40,7 @@ struct index_search_context { struct mail_search_context mail_ctx; struct mail_index_view *view; - struct index_mailbox *ibox; + struct mailbox *box; uint32_t seq1, seq2; struct mail *mail; @@ -96,7 +96,7 @@ case SEARCH_KEYWORDS: case SEARCH_MODSEQ: if (arg->type == SEARCH_MODSEQ) - mail_index_modseq_enable(ctx->ibox->box.index); + mail_index_modseq_enable(ctx->box->index); ctx->have_index_args = TRUE; break; case SEARCH_ALL: @@ -162,7 +162,7 @@ may contain it. */ flags = rec->flags & ~MAIL_RECENT; if ((arg->value.flags & MAIL_RECENT) != 0 && - index_mailbox_is_recent(ctx->ibox, rec->uid)) + index_mailbox_is_recent(ctx->box, rec->uid)) flags |= MAIL_RECENT; return (flags & arg->value.flags) == arg->value.flags; case SEARCH_KEYWORDS: @@ -605,8 +605,7 @@ /* FIXME: do this once in init */ i_assert(*headers != NULL); headers_ctx = - mailbox_header_lookup_init(&ctx->ibox->box, - headers); + mailbox_header_lookup_init(ctx->box, headers); if (mail_get_header_stream(ctx->mail, headers_ctx, &input) < 0) { mailbox_header_lookup_unref(&headers_ctx); @@ -1017,7 +1016,7 @@ ctx = i_new(struct index_search_context, 1); ctx->mail_ctx.transaction = _t; - ctx->ibox = (struct index_mailbox *)_t->box; + ctx->box = _t->box; ctx->view = t->trans_view; ctx->mail_ctx.args = args; ctx->mail_ctx.sort_program = index_sort_program_init(_t, sort_program); @@ -1067,7 +1066,7 @@ ret = ctx->failed || ctx->error != NULL ? -1 : 0; if (ctx->error != NULL) { - mail_storage_set_error(ctx->ibox->box.storage, + mail_storage_set_error(ctx->box->storage, MAIL_ERROR_PARAMS, ctx->error); }
--- a/src/lib-storage/index/index-status.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/index-status.c Sun Feb 07 17:30:24 2010 +0200 @@ -34,7 +34,6 @@ enum mailbox_status_items items, struct mailbox_status *status_r) { - struct index_mailbox *ibox = (struct index_mailbox *)box; const struct mail_index_header *hdr; i_assert(box->opened); @@ -45,7 +44,7 @@ hdr = mail_index_get_header(box->view); status_r->messages = hdr->messages_count; if ((items & STATUS_RECENT) != 0) { - status_r->recent = index_mailbox_get_recent_count(ibox); + status_r->recent = index_mailbox_get_recent_count(box); i_assert(status_r->recent <= status_r->messages); } status_r->unseen = hdr->messages_count - hdr->seen_messages_count;
--- a/src/lib-storage/index/index-storage.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/index-storage.c Sun Feb 07 17:30:24 2010 +0200 @@ -22,6 +22,9 @@ #define LOCK_NOTIFY_INTERVAL 30 +struct index_storage_module index_storage_module = + MODULE_CONTEXT_INIT(&mail_storage_module_register); + int index_list_create_missing_index_dir(struct mailbox_list *list, const char *name) { @@ -104,11 +107,12 @@ } } -static void index_cache_register_defaults(struct index_mailbox *ibox) +static void index_cache_register_defaults(struct mailbox *box) { - const struct mail_storage_settings *set = ibox->box.storage->set; + struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box); + const struct mail_storage_settings *set = box->storage->set; static bool initialized = FALSE; - struct mail_cache *cache = ibox->box.cache; + struct mail_cache *cache = box->cache; if (!initialized) { initialized = TRUE; @@ -129,11 +133,12 @@ MAIL_INDEX_CACHE_FIELD_COUNT); } -void index_storage_lock_notify(struct index_mailbox *ibox, +void index_storage_lock_notify(struct mailbox *box, enum mailbox_lock_notify_type notify_type, unsigned int secs_left) { - struct mail_storage *storage = ibox->box.storage; + struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box); + struct mail_storage *storage = box->storage; const char *str; time_t now; @@ -162,8 +167,8 @@ str = t_strdup_printf("Mailbox is locked, will abort in " "%u seconds", secs_left); - storage->callbacks.notify_no(&ibox->box, str, - storage->callback_context); + storage->callbacks. + notify_no(box, str, storage->callback_context); break; case MAILBOX_LOCK_NOTIFY_MAILBOX_OVERRIDE: if (storage->callbacks.notify_ok == NULL) @@ -171,21 +176,23 @@ str = t_strdup_printf("Stale mailbox lock file detected, " "will override in %u seconds", secs_left); - storage->callbacks.notify_ok(&ibox->box, str, - storage->callback_context); + storage->callbacks. + notify_ok(box, str, storage->callback_context); break; } } -void index_storage_lock_notify_reset(struct index_mailbox *ibox) +void index_storage_lock_notify_reset(struct mailbox *box) { + struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box); + ibox->next_lock_notify = time(NULL) + LOCK_NOTIFY_INTERVAL; ibox->last_notify_type = MAILBOX_LOCK_NOTIFY_NONE; } -int index_storage_mailbox_open(struct mailbox *box) +int index_storage_mailbox_open(struct mailbox *box, bool move_to_memory) { - struct index_mailbox *ibox = (struct index_mailbox *)box; + struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box); enum file_lock_method lock_method = box->storage->set->parsed_lock_method; enum mail_index_open_flags index_flags; @@ -194,7 +201,7 @@ i_assert(!box->opened); index_flags = ibox->index_flags; - if (ibox->move_to_memory) + if (move_to_memory) ibox->index_flags &= ~MAIL_INDEX_OPEN_FLAG_CREATE; if ((index_flags & MAIL_INDEX_OPEN_FLAG_NEVER_IN_MEMORY) != 0) { @@ -211,7 +218,7 @@ } ret = mail_index_open(box->index, index_flags, lock_method); - if (ret <= 0 || ibox->move_to_memory) { + if (ret <= 0 || move_to_memory) { if ((index_flags & MAIL_INDEX_OPEN_FLAG_NEVER_IN_MEMORY) != 0) { mail_storage_set_index_error(box); return -1; @@ -228,13 +235,13 @@ } box->cache = mail_index_get_cache(box->index); - index_cache_register_defaults(ibox); + index_cache_register_defaults(box); box->view = mail_index_view_open(box->index); ibox->keyword_names = mail_index_get_keywords(box->index); box->opened = TRUE; - index_thread_mailbox_opened(ibox); + index_thread_mailbox_opened(box); if (hook_mailbox_opened != NULL) hook_mailbox_opened(box); @@ -245,12 +252,12 @@ return 0; } -void index_storage_mailbox_alloc(struct index_mailbox *ibox, const char *name, +void index_storage_mailbox_alloc(struct mailbox *box, const char *name, struct istream *input, enum mailbox_flags flags, const char *index_prefix) { - struct mailbox *box = &ibox->box; + struct index_mailbox_context *ibox; const char *path; string_t *vname; @@ -276,16 +283,16 @@ array_create(&box->module_contexts, box->pool, sizeof(void *), 5); + ibox = p_new(box->pool, struct index_mailbox_context, 1); + ibox->index_flags = MAIL_INDEX_OPEN_FLAG_CREATE | + mail_storage_settings_to_index_flags(box->storage->set); + ibox->next_lock_notify = time(NULL) + LOCK_NOTIFY_INTERVAL; + MODULE_CONTEXT_SET(box, index_storage_module, ibox); + path = mailbox_list_get_path(box->list, name, MAILBOX_LIST_PATH_TYPE_MAILBOX); - ibox->box.path = p_strdup(box->pool, path); - - ibox->index_flags = MAIL_INDEX_OPEN_FLAG_CREATE | - mail_storage_settings_to_index_flags(box->storage->set); - - ibox->next_lock_notify = time(NULL) + LOCK_NOTIFY_INTERVAL; + box->path = p_strdup(box->pool, path); box->index = index_storage_alloc(box->list, name, flags, index_prefix); - if (box->file_create_mode == 0) mailbox_refresh_permissions(box); mail_index_set_permissions(box->index, box->file_create_mode, @@ -311,14 +318,14 @@ void index_storage_mailbox_close(struct mailbox *box) { - struct index_mailbox *ibox = (struct index_mailbox *) box; + struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box); if (box->view != NULL) mail_index_view_close(&box->view); - index_mailbox_check_remove_all(ibox); - if (ibox->box.input != NULL) - i_stream_unref(&ibox->box.input); + index_mailbox_check_remove_all(box); + if (box->input != NULL) + i_stream_unref(&box->input); if (box->index != NULL) mail_index_alloc_cache_unref(box->index); if (array_is_created(&ibox->recent_flags)) @@ -329,7 +336,7 @@ } static void -index_storage_mailbox_update_cache_fields(struct index_mailbox *ibox, +index_storage_mailbox_update_cache_fields(struct mailbox *box, const struct mailbox_update *update) { const char *const *field_names = update->cache_fields; @@ -338,7 +345,7 @@ struct mail_cache_field field; unsigned int i, j, old_count; - old_fields = mail_cache_register_get_list(ibox->box.cache, + old_fields = mail_cache_register_get_list(box->cache, pool_datastack_create(), &old_count); @@ -368,7 +375,7 @@ } } if (array_count(&new_fields) > 0) { - mail_cache_register_fields(ibox->box.cache, + mail_cache_register_fields(box->cache, array_idx_modifiable(&new_fields, 0), array_count(&new_fields)); } @@ -377,7 +384,6 @@ int index_storage_mailbox_update(struct mailbox *box, const struct mailbox_update *update) { - struct index_mailbox *ibox = (struct index_mailbox *)box; const struct mail_index_header *hdr; struct mail_index_view *view; struct mail_index_transaction *trans; @@ -388,11 +394,11 @@ return -1; } if (update->cache_fields != NULL) - index_storage_mailbox_update_cache_fields(ibox, update); + index_storage_mailbox_update_cache_fields(box, update); /* make sure we get the latest index info */ - (void)mail_index_refresh(ibox->box.index); - view = mail_index_view_open(ibox->box.index); + (void)mail_index_refresh(box->index); + view = mail_index_view_open(box->index); hdr = mail_index_get_header(view); trans = mail_index_transaction_begin(view, @@ -427,10 +433,8 @@ bool index_storage_is_readonly(struct mailbox *box) { - struct index_mailbox *ibox = (struct index_mailbox *) box; - return (box->flags & MAILBOX_FLAG_READONLY) != 0 || - ibox->backend_readonly; + box->backend_readonly; } bool index_storage_allow_new_keywords(struct mailbox *box) @@ -447,7 +451,6 @@ bool index_keyword_is_valid(struct mailbox *box, const char *keyword, const char **error_r) { - struct index_mailbox *ibox = (struct index_mailbox *)box; unsigned int i, idx; /* if it already exists, skip validity checks */ @@ -471,7 +474,7 @@ return FALSE; } } - if (i > ibox->box.storage->set->mail_max_keyword_length) { + if (i > box->storage->set->mail_max_keyword_length) { *error_r = "Keyword length too long"; return FALSE; } @@ -479,7 +482,7 @@ } static struct mail_keywords * -index_keywords_create_skip(struct index_mailbox *ibox, +index_keywords_create_skip(struct mailbox *box, const char *const keywords[]) { ARRAY_DEFINE(valid_keywords, const char *); @@ -487,39 +490,37 @@ t_array_init(&valid_keywords, 32); for (; *keywords != NULL; keywords++) { - if (mailbox_keyword_is_valid(&ibox->box, *keywords, &error)) + if (mailbox_keyword_is_valid(box, *keywords, &error)) array_append(&valid_keywords, keywords, 1); } (void)array_append_space(&valid_keywords); /* NULL-terminate */ - return mail_index_keywords_create(ibox->box.index, keywords); + return mail_index_keywords_create(box->index, keywords); } -int index_keywords_create(struct mailbox *_box, const char *const keywords[], +int index_keywords_create(struct mailbox *box, const char *const keywords[], struct mail_keywords **keywords_r, bool skip_invalid) { - struct index_mailbox *ibox = (struct index_mailbox *)_box; const char *error; unsigned int i; for (i = 0; keywords[i] != NULL; i++) { - if (mailbox_keyword_is_valid(_box, keywords[i], &error)) + if (mailbox_keyword_is_valid(box, keywords[i], &error)) continue; if (!skip_invalid) { - mail_storage_set_error(_box->storage, + mail_storage_set_error(box->storage, MAIL_ERROR_PARAMS, error); return -1; } /* found invalid keywords, do this the slow way */ T_BEGIN { - *keywords_r = index_keywords_create_skip(ibox, - keywords); + *keywords_r = index_keywords_create_skip(box, keywords); } T_END; return 0; } - *keywords_r = mail_index_keywords_create(ibox->box.index, keywords); + *keywords_r = mail_index_keywords_create(box->index, keywords); return 0; }
--- a/src/lib-storage/index/index-storage.h Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/index-storage.h Sun Feb 07 17:30:24 2010 +0200 @@ -29,8 +29,8 @@ struct mail_cache_transaction_ctx *cache_trans; }; -struct index_mailbox { - struct mailbox box; +struct index_mailbox_context { + union mailbox_module_context module_ctx; enum mail_index_open_flags index_flags; int (*save_commit_pre)(struct mail_save_context *save_ctx); @@ -54,22 +54,23 @@ uint32_t recent_flags_count; time_t sync_last_check; - - /* we've discovered there aren't enough permissions to modify mailbox */ - unsigned int backend_readonly:1; - unsigned int move_to_memory:1; }; -void index_storage_lock_notify(struct index_mailbox *ibox, +#define INDEX_STORAGE_CONTEXT(obj) \ + MODULE_CONTEXT(obj, index_storage_module) +extern MODULE_CONTEXT_DEFINE(index_storage_module, + &mail_storage_module_register); + +void index_storage_lock_notify(struct mailbox *box, enum mailbox_lock_notify_type notify_type, unsigned int secs_left); -void index_storage_lock_notify_reset(struct index_mailbox *ibox); +void index_storage_lock_notify_reset(struct mailbox *box); -void index_storage_mailbox_alloc(struct index_mailbox *ibox, const char *name, +void index_storage_mailbox_alloc(struct mailbox *box, const char *name, struct istream *input, enum mailbox_flags flags, const char *index_prefix); -int index_storage_mailbox_open(struct mailbox *box); +int index_storage_mailbox_open(struct mailbox *box, bool move_to_memory); int index_storage_mailbox_enable(struct mailbox *box, enum mailbox_feature feature); void index_storage_mailbox_close(struct mailbox *box); @@ -90,19 +91,18 @@ bool index_keyword_is_valid(struct mailbox *box, const char *keyword, const char **error_r); -void index_mailbox_set_recent_uid(struct index_mailbox *ibox, uint32_t uid); -void index_mailbox_set_recent_seq(struct index_mailbox *ibox, +void index_mailbox_set_recent_uid(struct mailbox *box, uint32_t uid); +void index_mailbox_set_recent_seq(struct mailbox *box, struct mail_index_view *view, uint32_t seq1, uint32_t seq2); -bool index_mailbox_is_recent(struct index_mailbox *ibox, uint32_t uid); -unsigned int index_mailbox_get_recent_count(struct index_mailbox *ibox); -void index_mailbox_reset_uidvalidity(struct index_mailbox *ibox); +bool index_mailbox_is_recent(struct mailbox *box, uint32_t uid); +unsigned int index_mailbox_get_recent_count(struct mailbox *box); +void index_mailbox_reset_uidvalidity(struct mailbox *box); -void index_mailbox_check_add(struct index_mailbox *ibox, - const char *path); -void index_mailbox_check_remove_all(struct index_mailbox *ibox); +void index_mailbox_check_add(struct mailbox *box, const char *path); +void index_mailbox_check_remove_all(struct mailbox *box); -bool index_mailbox_want_full_sync(struct index_mailbox *ibox, +bool index_mailbox_want_full_sync(struct mailbox *box, enum mailbox_sync_flags flags); struct mailbox_sync_context * index_mailbox_sync_init(struct mailbox *box, enum mailbox_sync_flags flags,
--- a/src/lib-storage/index/index-sync-changes.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/index-sync-changes.c Sun Feb 07 17:30:24 2010 +0200 @@ -6,7 +6,6 @@ #include "index-sync-changes.h" struct index_sync_changes_context { - struct index_mailbox *ibox; struct mail_index_sync_ctx *index_sync_ctx; struct mail_index_view *sync_view; struct mail_index_transaction *sync_trans; @@ -17,8 +16,7 @@ }; struct index_sync_changes_context * -index_sync_changes_init(struct index_mailbox *ibox, - struct mail_index_sync_ctx *index_sync_ctx, +index_sync_changes_init(struct mail_index_sync_ctx *index_sync_ctx, struct mail_index_view *sync_view, struct mail_index_transaction *sync_trans, bool dirty_flag_updates) @@ -26,7 +24,6 @@ struct index_sync_changes_context *ctx; ctx = i_new(struct index_sync_changes_context, 1); - ctx->ibox = ibox; ctx->index_sync_ctx = index_sync_ctx; ctx->sync_view = sync_view; ctx->sync_trans = sync_trans;
--- a/src/lib-storage/index/index-sync-changes.h Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/index-sync-changes.h Sun Feb 07 17:30:24 2010 +0200 @@ -2,8 +2,7 @@ #define INDEX_SYNC_CHANGES_H struct index_sync_changes_context * -index_sync_changes_init(struct index_mailbox *ibox, - struct mail_index_sync_ctx *index_sync_ctx, +index_sync_changes_init(struct mail_index_sync_ctx *index_sync_ctx, struct mail_index_view *sync_view, struct mail_index_transaction *sync_trans, bool dirty_flag_updates);
--- a/src/lib-storage/index/index-sync-private.h Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/index-sync-private.h Sun Feb 07 17:30:24 2010 +0200 @@ -5,7 +5,6 @@ struct index_mailbox_sync_context { struct mailbox_sync_context ctx; - struct index_mailbox *ibox; struct mail_index_view_sync_ctx *sync_ctx; uint32_t messages_count;
--- a/src/lib-storage/index/index-sync-search.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/index-sync-search.c Sun Feb 07 17:30:24 2010 +0200 @@ -27,7 +27,7 @@ array_foreach(changes, range) { for (seq = range->seq1; seq <= range->seq2; seq++) { - mail_index_lookup_uid(ctx->ibox->box.view, seq, &uid); + mail_index_lookup_uid(ctx->ctx.box->view, seq, &uid); seq_range_array_add(&ctx->all_flag_update_uids, 0, uid); } } @@ -52,7 +52,7 @@ i_assert(!array_is_created(&ctx->all_flag_update_uids)); - results = array_get(&ctx->ibox->box.search_results, &count); + results = array_get(&ctx->ctx.box->search_results, &count); for (i = 0; i < count; i++) { if ((results[i]->flags & MAILBOX_SEARCH_RESULT_FLAG_UPDATE) != 0 && search_result_want_flag_updates(results[i])) { @@ -83,7 +83,7 @@ struct mail_search_result *const *results; unsigned int i, count; - results = array_get(&ctx->ibox->box.search_results, &count); + results = array_get(&ctx->ctx.box->search_results, &count); for (i = 0; i < count; i++) search_result_update(ctx, results[i]); } @@ -91,7 +91,7 @@ void index_sync_search_results_expunge(struct index_mailbox_sync_context *ctx) { if (ctx->expunges != NULL) { - index_search_results_update_expunges(&ctx->ibox->box, + index_search_results_update_expunges(ctx->ctx.box, ctx->expunges); } }
--- a/src/lib-storage/index/index-sync.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/index-sync.c Sun Feb 07 17:30:24 2010 +0200 @@ -6,9 +6,11 @@ #include "array.h" #include "index-sync-private.h" -bool index_mailbox_want_full_sync(struct index_mailbox *ibox, +bool index_mailbox_want_full_sync(struct mailbox *box, enum mailbox_sync_flags flags) { + struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box); + if ((flags & MAILBOX_SYNC_FLAG_FAST) != 0 && ioloop_time < ibox->sync_last_check + MAILBOX_FULL_SYNC_INTERVAL) return FALSE; @@ -19,8 +21,10 @@ return TRUE; } -void index_mailbox_set_recent_uid(struct index_mailbox *ibox, uint32_t uid) +void index_mailbox_set_recent_uid(struct mailbox *box, uint32_t uid) { + struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box); + if (uid <= ibox->recent_flags_prev_uid) { i_assert(seq_range_exists(&ibox->recent_flags, uid)); return; @@ -31,7 +35,7 @@ ibox->recent_flags_count++; } -void index_mailbox_set_recent_seq(struct index_mailbox *ibox, +void index_mailbox_set_recent_seq(struct mailbox *box, struct mail_index_view *view, uint32_t seq1, uint32_t seq2) { @@ -39,18 +43,22 @@ for (; seq1 <= seq2; seq1++) { mail_index_lookup_uid(view, seq1, &uid); - index_mailbox_set_recent_uid(ibox, uid); + index_mailbox_set_recent_uid(box, uid); } } -bool index_mailbox_is_recent(struct index_mailbox *ibox, uint32_t uid) +bool index_mailbox_is_recent(struct mailbox *box, uint32_t uid) { + struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box); + return array_is_created(&ibox->recent_flags) && seq_range_exists(&ibox->recent_flags, uid); } -void index_mailbox_reset_uidvalidity(struct index_mailbox *ibox) +void index_mailbox_reset_uidvalidity(struct mailbox *box) { + struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box); + /* can't trust the currently cached recent flags anymore */ if (array_is_created(&ibox->recent_flags)) array_clear(&ibox->recent_flags); @@ -58,8 +66,9 @@ ibox->recent_flags_prev_uid = 0; } -unsigned int index_mailbox_get_recent_count(struct index_mailbox *ibox) +unsigned int index_mailbox_get_recent_count(struct mailbox *box) { + struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box); const struct mail_index_header *hdr; const struct seq_range *range; unsigned int i, count, recent_count; @@ -67,7 +76,7 @@ if (!array_is_created(&ibox->recent_flags)) return 0; - hdr = mail_index_get_header(ibox->box.view); + hdr = mail_index_get_header(box->view); recent_count = ibox->recent_flags_count; range = array_get(&ibox->recent_flags, &count); for (i = count; i > 0; ) { @@ -87,16 +96,17 @@ return recent_count; } -static void index_mailbox_expunge_recent(struct index_mailbox *ibox, - uint32_t seq1, uint32_t seq2) +static void +index_mailbox_expunge_recent(struct mailbox *box, uint32_t seq1, uint32_t seq2) { + struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box); uint32_t uid; if (!array_is_created(&ibox->recent_flags)) return; for (; seq1 <= seq2; seq1++) { - mail_index_lookup_uid(ibox->box.view, seq1, &uid); + mail_index_lookup_uid(box->view, seq1, &uid); if (seq_range_array_remove(&ibox->recent_flags, uid)) ibox->recent_flags_count--; } @@ -112,7 +122,7 @@ while (mail_index_view_sync_next(ctx->sync_ctx, &sync_rec)) { switch (sync_rec.type) { case MAIL_INDEX_VIEW_SYNC_TYPE_FLAGS: - if (!mail_index_lookup_seq_range(ctx->ibox->box.view, + if (!mail_index_lookup_seq_range(ctx->ctx.box->view, sync_rec.uid1, sync_rec.uid2, &seq1, &seq2)) @@ -145,13 +155,11 @@ index_mailbox_sync_init(struct mailbox *box, enum mailbox_sync_flags flags, bool failed) { - struct index_mailbox *ibox = (struct index_mailbox *)box; struct index_mailbox_sync_context *ctx; enum mail_index_view_sync_flags sync_flags = 0; ctx = i_new(struct index_mailbox_sync_context, 1); ctx->ctx.box = box; - ctx->ibox = ibox; if (failed) { ctx->failed = TRUE; @@ -195,7 +203,7 @@ range = array_idx(ctx->expunges, ctx->expunge_pos); i_assert(range->seq2 <= ctx->messages_count); - index_mailbox_expunge_recent(ctx->ibox, range->seq1, range->seq2); + index_mailbox_expunge_recent(ctx->ctx.box, range->seq1, range->seq2); ctx->messages_count -= range->seq2 - range->seq1 + 1; sync_rec_r->seq1 = range->seq1; @@ -241,8 +249,9 @@ static void index_mailbox_expunge_unseen_recent(struct index_mailbox_sync_context *ctx) { - struct index_mailbox *ibox = ctx->ibox; - struct mail_index_view *view = ibox->box.view; + struct index_mailbox_context *ibox = + INDEX_STORAGE_CONTEXT(ctx->ctx.box); + struct mail_index_view *view = ctx->ctx.box->view; const struct mail_index_header *hdr; uint32_t seq, start_uid, uid; @@ -303,7 +312,7 @@ { struct index_mailbox_sync_context *ctx = (struct index_mailbox_sync_context *)_ctx; - struct index_mailbox *ibox = ctx->ibox; + struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(_ctx->box); struct mailbox_sync_rec sync_rec; const struct mail_index_header *hdr; uint32_t seq1, seq2; @@ -336,7 +345,7 @@ hdr->next_uid, &seq1, &seq2); if (seq1 != 0) { - index_mailbox_set_recent_seq(ibox, + index_mailbox_set_recent_seq(_ctx->box, _ctx->box->view, seq1, seq2); }
--- a/src/lib-storage/index/index-thread-private.h Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/index-thread-private.h Sun Feb 07 17:30:24 2010 +0200 @@ -1,8 +1,6 @@ #ifndef INDEX_THREAD_PRIVATE_H #define INDEX_THREAD_PRIVATE_H -struct index_mailbox; - #include "crc32.h" #include "mail-thread.h" #include "mail-index-strmap.h" @@ -79,6 +77,6 @@ enum mail_thread_type thread_type, bool return_seqs); -void index_thread_mailbox_opened(struct index_mailbox *ibox); +void index_thread_mailbox_opened(struct mailbox *box); #endif
--- a/src/lib-storage/index/index-thread.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/index-thread.c Sun Feb 07 17:30:24 2010 +0200 @@ -632,9 +632,8 @@ i_free(tbox); } -void index_thread_mailbox_opened(struct index_mailbox *ibox) +void index_thread_mailbox_opened(struct mailbox *box) { - struct mailbox *box = &ibox->box; struct mail_thread_mailbox *tbox; tbox = i_new(struct mail_thread_mailbox, 1);
--- a/src/lib-storage/index/index-transaction.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/index-transaction.c Sun Feb 07 17:30:24 2010 +0200 @@ -20,7 +20,7 @@ struct index_transaction_context *it = MAIL_STORAGE_CONTEXT(index_trans); struct mailbox_transaction_context *t = &it->mailbox_ctx; - struct index_mailbox *ibox = (struct index_mailbox *)t->box; + struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(t->box); int ret = 0; if (t->save_ctx != NULL) { @@ -50,8 +50,8 @@ static void index_transaction_index_rollback(struct mail_index_transaction *t) { struct index_transaction_context *it = MAIL_STORAGE_CONTEXT(t); - struct index_mailbox *ibox = - (struct index_mailbox *)it->mailbox_ctx.box; + struct index_mailbox_context *ibox = + INDEX_STORAGE_CONTEXT(it->mailbox_ctx.box); if (it->mailbox_ctx.save_ctx != NULL) ibox->save_rollback(it->mailbox_ctx.save_ctx);
--- a/src/lib-storage/index/maildir/maildir-copy.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/maildir/maildir-copy.c Sun Feb 07 17:30:24 2010 +0200 @@ -170,8 +170,8 @@ return 0; } - if (mail_index_is_deleted(dest_mbox->ibox.box.index)) { - mailbox_set_deleted(&dest_mbox->ibox.box); + if (mail_index_is_deleted(dest_mbox->box.index)) { + mailbox_set_deleted(&dest_mbox->box); return -1; } @@ -195,7 +195,7 @@ /* hard link to tmp/ with basename and later when we have uidlist locked, move it to new/cur. */ str_printfa(do_ctx.dest_path, "%s/tmp/%s", - dest_mbox->ibox.box.path, do_ctx.dest_fname); + dest_mbox->box.path, do_ctx.dest_fname); do_ctx.base_end_pos = str_len(do_ctx.dest_path); if (src_mbox != NULL) { /* maildir */ @@ -237,7 +237,7 @@ i_assert((_t->flags & MAILBOX_TRANSACTION_FLAG_EXTERNAL) != 0); if (mbox->storage->set->maildir_copy_with_hardlinks && - maildir_compatible_file_modes(&mbox->ibox.box, mail->box)) { + maildir_compatible_file_modes(&mbox->box, mail->box)) { T_BEGIN { ret = maildir_copy_hardlink(ctx, mail); } T_END;
--- a/src/lib-storage/index/maildir/maildir-keywords.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/maildir/maildir-keywords.c Sun Feb 07 17:30:24 2010 +0200 @@ -55,7 +55,7 @@ { struct maildir_keywords *mk; - mk = maildir_keywords_init_readonly(&mbox->ibox.box); + mk = maildir_keywords_init_readonly(&mbox->box); mk->mbox = mbox; return mk; } @@ -286,7 +286,7 @@ const char *path, int fd) { struct maildir_mailbox *mbox = mk->mbox; - struct mailbox *box = &mbox->ibox.box; + struct mailbox *box = &mbox->box; const char *const *keywords; unsigned int i, count; string_t *str; @@ -367,7 +367,7 @@ /* we could just create the temp file directly, but doing it this ways avoids potential problems with overwriting contents in malicious symlinks */ - old_mask = umask(0777 & ~mk->mbox->ibox.box.file_create_mode); + old_mask = umask(0777 & ~mk->mbox->box.file_create_mode); fd = file_dotlock_open(&mk->dotlock_settings, mk->path, DOTLOCK_CREATE_FLAG_NONBLOCK, &dotlock); umask(old_mask); @@ -381,7 +381,7 @@ } /* the control dir doesn't exist. create it unless the whole mailbox was just deleted. */ - if (!maildir_set_deleted(&mk->mbox->ibox.box)) + if (!maildir_set_deleted(&mk->mbox->box)) return -1; }
--- a/src/lib-storage/index/maildir/maildir-mail.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/maildir/maildir-mail.c Sun Feb 07 17:30:24 2010 +0200 @@ -177,8 +177,8 @@ /* one reason this could happen is if we delayed opening dovecot-uidlist and we're trying to open a mail that got recently expunged. Let's test this theory first: */ - (void)mail_index_refresh(mbox->ibox.box.index); - view = mail_index_view_open(mbox->ibox.box.index); + (void)mail_index_refresh(mbox->box.index); + view = mail_index_view_open(mbox->box.index); exists = mail_index_lookup_seq(view, mail->uid, &seq); mail_index_view_close(&view); @@ -193,6 +193,8 @@ static int maildir_get_pop3_state(struct index_mail *mail) { + struct mailbox *box = mail->mail.mail.box; + struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box); const struct mail_cache_field *fields; unsigned int i, count, psize_idx, vsize_idx; enum mail_cache_decision_type dec, vsize_dec; @@ -213,16 +215,16 @@ not_pop3_only = TRUE; /* get vsize decisions */ - psize_idx = mail->ibox->cache_fields[MAIL_CACHE_PHYSICAL_FULL_SIZE].idx; - vsize_idx = mail->ibox->cache_fields[MAIL_CACHE_VIRTUAL_FULL_SIZE].idx; + psize_idx = ibox->cache_fields[MAIL_CACHE_PHYSICAL_FULL_SIZE].idx; + vsize_idx = ibox->cache_fields[MAIL_CACHE_VIRTUAL_FULL_SIZE].idx; if (not_pop3_only) { - vsize_dec = mail_cache_field_get_decision(mail->ibox->box.cache, + vsize_dec = mail_cache_field_get_decision(box->cache, vsize_idx); vsize_dec &= ~MAIL_CACHE_DECISION_FORCED; } else { /* also check if there are any non-[pv]size cached fields */ vsize_dec = MAIL_CACHE_DECISION_NO; - fields = mail_cache_register_get_list(mail->ibox->box.cache, + fields = mail_cache_register_get_list(box->cache, pool_datastack_create(), &count); for (i = 0; i < count; i++) { @@ -239,7 +241,7 @@ /* either nothing is cached, or only vsize is cached. */ mail->pop3_state = 1; } else if (vsize_dec != MAIL_CACHE_DECISION_YES && - (mail->ibox->box.flags & MAILBOX_FLAG_POP3_SESSION) == 0) { + (box->flags & MAILBOX_FLAG_POP3_SESSION) == 0) { /* if virtual size isn't cached permanently, POP3 isn't being used */ mail->pop3_state = -1; @@ -255,7 +257,7 @@ uoff_t *size_r) { struct mail *_mail = &mail->mail.mail; - struct maildir_mailbox *mbox = (struct maildir_mailbox *)mail->ibox; + struct maildir_mailbox *mbox = (struct maildir_mailbox *)_mail->box; enum maildir_uidlist_rec_ext_key key; const char *path, *fname, *value; uoff_t size; @@ -299,7 +301,8 @@ maildir_handle_size_caching(struct index_mail *mail, bool quick_check, bool vsize) { - struct maildir_mailbox *mbox = (struct maildir_mailbox *)mail->ibox; + struct mailbox *box = mail->mail.mail.box; + struct maildir_mailbox *mbox = (struct maildir_mailbox *)box; enum mail_fetch_field field; uoff_t size; int pop3_state; @@ -313,14 +316,14 @@ including to the uidlist if it's already in filename. do some extra checks here to catch potential cache bugs. */ if (vsize && mail->data.virtual_size != size) { - mail_cache_set_corrupted(mail->ibox->box.cache, + mail_cache_set_corrupted(box->cache, "Corrupted virtual size for uid=%u: " "%"PRIuUOFF_T" != %"PRIuUOFF_T, mail->mail.mail.uid, mail->data.virtual_size, size); mail->data.virtual_size = size; } else if (!vsize && mail->data.physical_size != size) { - mail_cache_set_corrupted(mail->ibox->box.cache, + mail_cache_set_corrupted(box->cache, "Corrupted physical size for uid=%u: " "%"PRIuUOFF_T" != %"PRIuUOFF_T, mail->mail.mail.uid, @@ -382,7 +385,7 @@ static int maildir_mail_get_physical_size(struct mail *_mail, uoff_t *size_r) { struct index_mail *mail = (struct index_mail *)_mail; - struct maildir_mailbox *mbox = (struct maildir_mailbox *)mail->ibox; + struct maildir_mailbox *mbox = (struct maildir_mailbox *)_mail->box; struct index_mail_data *data = &mail->data; struct stat st; const char *path; @@ -431,7 +434,7 @@ const char **value_r) { struct index_mail *mail = (struct index_mail *)_mail; - struct maildir_mailbox *mbox = (struct maildir_mailbox *)mail->ibox; + struct maildir_mailbox *mbox = (struct maildir_mailbox *)_mail->box; const char *path, *fname, *end, *uidl; switch (field) { @@ -481,7 +484,7 @@ struct istream **stream_r) { struct index_mail *mail = (struct index_mail *)_mail; - struct maildir_mailbox *mbox = (struct maildir_mailbox *)mail->ibox; + struct maildir_mailbox *mbox = (struct maildir_mailbox *)_mail->box; struct index_mail_data *data = &mail->data; bool deleted; @@ -523,8 +526,7 @@ static void maildir_mail_set_cache_corrupted(struct mail *_mail, enum mail_fetch_field field) { - struct index_mail *mail = (struct index_mail *)_mail; - struct maildir_mailbox *mbox = (struct maildir_mailbox *)mail->ibox; + struct maildir_mailbox *mbox = (struct maildir_mailbox *)_mail->box; enum maildir_uidlist_rec_flag flags; const char *fname; uoff_t size; @@ -544,7 +546,7 @@ "new" : "cur"; mail_storage_set_critical(_mail->box->storage, "Maildir filename has wrong W value: %s/%s/%s", - mbox->ibox.box.path, subdir, fname); + mbox->box.path, subdir, fname); } else if (maildir_uidlist_lookup_ext(mbox->uidlist, _mail->uid, MAILDIR_UIDLIST_REC_EXT_VSIZE) != NULL) { maildir_uidlist_set_ext(mbox->uidlist, _mail->uid,
--- a/src/lib-storage/index/maildir/maildir-save.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/maildir/maildir-save.c Sun Feb 07 17:30:24 2010 +0200 @@ -127,9 +127,9 @@ ctx->files_tail = &ctx->files; ctx->fd = -1; - ctx->tmpdir = p_strconcat(pool, mbox->ibox.box.path, "/tmp", NULL); - ctx->newdir = p_strconcat(pool, mbox->ibox.box.path, "/new", NULL); - ctx->curdir = p_strconcat(pool, mbox->ibox.box.path, "/cur", NULL); + ctx->tmpdir = p_strconcat(pool, mbox->box.path, "/tmp", NULL); + ctx->newdir = p_strconcat(pool, mbox->box.path, "/new", NULL); + ctx->curdir = p_strconcat(pool, mbox->box.path, "/cur", NULL); buffer_create_const_data(&ctx->keywords_buffer, NULL, 0); array_create_from_buffer(&ctx->keywords_array, &ctx->keywords_buffer, @@ -298,14 +298,14 @@ static int maildir_create_tmp(struct maildir_mailbox *mbox, const char *dir, const char **fname) { - struct mailbox *box = &mbox->ibox.box; + struct mailbox *box = &mbox->box; struct stat st; unsigned int prefix_len; const char *tmp_fname = *fname; string_t *path; int fd; - if (mail_index_is_deleted(mbox->ibox.box.index)) { + if (mail_index_is_deleted(mbox->box.index)) { mailbox_set_deleted(box); return -1; } @@ -637,14 +637,14 @@ if (maildir_uidlist_lookup(ctx->mbox->uidlist, conflict->old_uid, &flags, &filename) <= 0) { i_error("maildir %s: uid %u update failed: lost filename", - ctx->mbox->ibox.box.path, conflict->old_uid); + ctx->mbox->box.path, conflict->old_uid); return; } maildir_uidlist_sync_remove(ctx->uidlist_sync_ctx, filename); if (maildir_uidlist_sync_next_uid(ctx->uidlist_sync_ctx, filename, conflict->new_uid, 0) < 0) { i_error("maildir %s: uid %u update failed: sync failed", - ctx->mbox->ibox.box.path, conflict->old_uid); + ctx->mbox->box.path, conflict->old_uid); } } @@ -728,7 +728,7 @@ uids = array_get(&saved_sorted_uids, &count); for (i = 0; i < count; i++) { for (uid = uids[i].seq1; uid <= uids[i].seq2; uid++) - index_mailbox_set_recent_uid(&mbox->ibox, uid); + index_mailbox_set_recent_uid(&mbox->box, uid); } return uids[count-1].seq2 + 1; } @@ -780,7 +780,7 @@ next_uid = maildir_save_set_recent_flags(ctx); } T_END; - if ((mbox->ibox.box.flags & MAILBOX_FLAG_KEEP_RECENT) == 0) + if ((mbox->box.flags & MAILBOX_FLAG_KEEP_RECENT) == 0) first_recent_uid = next_uid; else if (ctx->last_nonrecent_uid != 0) first_recent_uid = ctx->last_nonrecent_uid + 1; @@ -957,7 +957,7 @@ if (ret < 0) { ctx->keywords_sync_ctx = !ctx->have_keywords ? NULL : maildir_keywords_sync_init(ctx->mbox->keywords, - ctx->mbox->ibox.box.index); + ctx->mbox->box.index); /* unlink the files we just moved in an attempt to rollback the transaction. uidlist is still locked, so at least other
--- a/src/lib-storage/index/maildir/maildir-storage.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/maildir/maildir-storage.c Sun Feb 07 17:30:24 2010 +0200 @@ -329,30 +329,32 @@ enum mailbox_flags flags) { struct maildir_mailbox *mbox; + struct index_mailbox_context *ibox; pool_t pool; pool = pool_alloconly_create("maildir mailbox", 1024+512); mbox = p_new(pool, struct maildir_mailbox, 1); - mbox->ibox.box = maildir_mailbox; - mbox->ibox.box.pool = pool; - mbox->ibox.box.storage = storage; - mbox->ibox.box.list = list; - mbox->ibox.box.mail_vfuncs = &maildir_mail_vfuncs; + mbox->box = maildir_mailbox; + mbox->box.pool = pool; + mbox->box.storage = storage; + mbox->box.list = list; + mbox->box.mail_vfuncs = &maildir_mail_vfuncs; - mbox->ibox.save_commit_pre = maildir_transaction_save_commit_pre; - mbox->ibox.save_commit_post = maildir_transaction_save_commit_post; - mbox->ibox.save_rollback = maildir_transaction_save_rollback; + index_storage_mailbox_alloc(&mbox->box, name, input, flags, + MAILDIR_INDEX_PREFIX); - index_storage_mailbox_alloc(&mbox->ibox, name, input, flags, - MAILDIR_INDEX_PREFIX); + ibox = INDEX_STORAGE_CONTEXT(&mbox->box); + ibox->save_commit_pre = maildir_transaction_save_commit_pre; + ibox->save_commit_post = maildir_transaction_save_commit_post; + ibox->save_rollback = maildir_transaction_save_rollback; mbox->storage = (struct maildir_storage *)storage; mbox->maildir_ext_id = - mail_index_ext_register(mbox->ibox.box.index, "maildir", + mail_index_ext_register(mbox->box.index, "maildir", sizeof(mbox->maildir_hdr), 0, 0); mbox->uidlist = maildir_uidlist_init(mbox); mbox->keywords = maildir_keywords_init(mbox); - return &mbox->ibox.box; + return &mbox->box; } static int maildir_mailbox_open_existing(struct mailbox *box) @@ -375,8 +377,8 @@ if (access(t_strconcat(box->path, "/cur", NULL), W_OK) < 0 && errno == EACCES) - mbox->ibox.backend_readonly = TRUE; - return index_storage_mailbox_open(box); + mbox->box.backend_readonly = TRUE; + return index_storage_mailbox_open(box, FALSE); } static int maildir_mailbox_open(struct mailbox *box) @@ -808,12 +810,12 @@ struct maildir_mailbox *mbox = (struct maildir_mailbox *)box; if (box->notify_callback == NULL) - index_mailbox_check_remove_all(&mbox->ibox); + index_mailbox_check_remove_all(&mbox->box); else { - index_mailbox_check_add(&mbox->ibox, - t_strconcat(mbox->ibox.box.path, "/new", NULL)); - index_mailbox_check_add(&mbox->ibox, - t_strconcat(mbox->ibox.box.path, "/cur", NULL)); + index_mailbox_check_add(&mbox->box, + t_strconcat(mbox->box.path, "/new", NULL)); + index_mailbox_check_add(&mbox->box, + t_strconcat(mbox->box.path, "/cur", NULL)); } }
--- a/src/lib-storage/index/maildir/maildir-storage.h Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/maildir/maildir-storage.h Sun Feb 07 17:30:24 2010 +0200 @@ -74,7 +74,7 @@ }; struct maildir_mailbox { - struct index_mailbox ibox; + struct mailbox box; struct maildir_storage *storage; struct mail_index_view *flags_view;
--- a/src/lib-storage/index/maildir/maildir-sync-index.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/maildir/maildir-sync-index.c Sun Feb 07 17:30:24 2010 +0200 @@ -79,7 +79,7 @@ mail_storage_set_critical(&ctx->mbox->storage->storage, "Mailbox %s: Expunged GUID mismatch for UID %u: %s vs %s", - ctx->mbox->ibox.box.vname, ctx->uid, + ctx->mbox->box.vname, ctx->uid, binary_to_hex(guid_128, sizeof(guid_128)), binary_to_hex(expunged_guid_128, MAIL_GUID_128_SIZE)); return FALSE; @@ -88,7 +88,7 @@ static int maildir_expunge(struct maildir_mailbox *mbox, const char *path, struct maildir_index_sync_context *ctx) { - struct mailbox *box = &mbox->ibox.box; + struct mailbox *box = &mbox->box; if (unlink(path) == 0) { if (box->v.sync_notify != NULL) { @@ -108,7 +108,7 @@ static int maildir_sync_flags(struct maildir_mailbox *mbox, const char *path, struct maildir_index_sync_context *ctx) { - struct mailbox *box = &mbox->ibox.box; + struct mailbox *box = &mbox->box; struct stat st; const char *dir, *fname, *newfname, *newpath; enum mail_index_sync_type sync_type; @@ -203,7 +203,7 @@ maildir_uidlist_sync_finish(ctx->uidlist_sync_ctx); i_warning("Maildir %s: Expunged message reappeared, giving a new UID " - "(old uid=%u, file=%s)", ctx->mbox->ibox.box.path, + "(old uid=%u, file=%s)", ctx->mbox->box.path, uid, filename); return 0; } @@ -212,7 +212,7 @@ struct maildir_sync_context *maildir_sync_ctx, struct maildir_index_sync_context **ctx_r) { - struct mailbox *_box = &mbox->ibox.box; + struct mailbox *_box = &mbox->box; struct maildir_index_sync_context *ctx; struct mail_index_sync_ctx *sync_ctx; struct mail_index_view *view; @@ -240,9 +240,8 @@ ctx->keywords_sync_ctx = maildir_keywords_sync_init(mbox->keywords, _box->index); ctx->sync_changes = - index_sync_changes_init(&mbox->ibox, ctx->sync_ctx, - ctx->view, ctx->trans, - mbox->ibox.backend_readonly); + index_sync_changes_init(ctx->sync_ctx, ctx->view, ctx->trans, + mbox->box.backend_readonly); *ctx_r = ctx; return 0; @@ -280,14 +279,14 @@ struct stat st; if (ctx->update_maildir_hdr_cur && - stat(t_strconcat(mbox->ibox.box.path, "/cur", NULL), &st) == 0) { + stat(t_strconcat(mbox->box.path, "/cur", NULL), &st) == 0) { if ((time_t)mbox->maildir_hdr.cur_check_time < st.st_mtime) mbox->maildir_hdr.cur_check_time = st.st_mtime; mbox->maildir_hdr.cur_mtime = st.st_mtime; mbox->maildir_hdr.cur_mtime_nsecs = ST_MTIME_NSEC(st); } - mail_index_get_header_ext(mbox->ibox.box.view, mbox->maildir_ext_id, + mail_index_get_header_ext(mbox->box.view, mbox->maildir_ext_id, &data, &data_size); if (data_size != sizeof(mbox->maildir_hdr) || maildir_index_header_has_changed(data, &mbox->maildir_hdr)) { @@ -314,7 +313,7 @@ start a second index sync and crash. */ mbox->syncing_commit = TRUE; if (mail_index_sync_commit(&ctx->sync_ctx) < 0) { - mail_storage_set_index_error(&mbox->ibox.box); + mail_storage_set_index_error(&mbox->box); ret = -1; } mbox->syncing_commit = FALSE; @@ -357,7 +356,7 @@ static void maildir_sync_mail_keywords(struct maildir_index_sync_context *ctx, uint32_t seq) { - struct mailbox *box = &ctx->mbox->ibox.box; + struct mailbox *box = &ctx->mbox->box; struct mail_keywords *kw; unsigned int i, j, old_count, new_count; const unsigned int *old_indexes, *new_indexes; @@ -465,9 +464,9 @@ first time, reset the index so we can add all messages as new */ i_warning("Maildir %s: UIDVALIDITY changed (%u -> %u)", - mbox->ibox.box.path, hdr->uid_validity, uid_validity); + mbox->box.path, hdr->uid_validity, uid_validity); mail_index_reset(trans); - index_mailbox_reset_uidvalidity(&mbox->ibox); + index_mailbox_reset_uidvalidity(&mbox->box); first_uid = hdr->messages_count + 1; memset(&empty_hdr, 0, sizeof(empty_hdr)); @@ -491,7 +490,7 @@ /* the private flags are kept only in indexes. don't use them at all even for newly seen mails */ - ctx->flags &= ~mbox->ibox.box.private_flags_mask; + ctx->flags &= ~mbox->box.private_flags_mask; again: seq++; @@ -524,7 +523,7 @@ struct mail_keywords *kw; kw = mail_index_keywords_create_from_indexes( - mbox->ibox.box.index, &ctx->keywords); + mbox->box.index, &ctx->keywords); mail_index_update_keywords(trans, seq, MODIFY_REPLACE, kw); mail_index_keywords_unref(&kw); @@ -564,7 +563,7 @@ } /* the private flags are stored only in indexes, keep them */ - ctx->flags |= rec->flags & mbox->ibox.box.private_flags_mask; + ctx->flags |= rec->flags & mbox->box.private_flags_mask; if (index_sync_changes_have(ctx->sync_changes)) { /* apply flag changes to maildir */ @@ -619,7 +618,7 @@ /* UIDVALIDITY changed, skip over the old messages */ seq = first_uid; } - index_mailbox_set_recent_seq(&mbox->ibox, view2, seq, seq2); + index_mailbox_set_recent_seq(&mbox->box, view2, seq, seq2); } mail_index_view_close(&view2); @@ -629,8 +628,8 @@ ret = -1; } - if (mbox->ibox.box.v.sync_notify != NULL) - mbox->ibox.box.v.sync_notify(&mbox->ibox.box, 0, 0); + if (mbox->box.v.sync_notify != NULL) + mbox->box.v.sync_notify(&mbox->box, 0, 0); /* check cur/ mtime later. if we came here from saving messages they could still be moved to cur/ directory. */ @@ -639,7 +638,7 @@ if (uid_validity == 0) { uid_validity = hdr->uid_validity != 0 ? hdr->uid_validity : - maildir_get_uidvalidity_next(mbox->ibox.box.list); + maildir_get_uidvalidity_next(mbox->box.list); maildir_uidlist_set_uid_validity(mbox->uidlist, uid_validity); } maildir_uidlist_set_next_uid(mbox->uidlist, hdr_next_uid, FALSE);
--- a/src/lib-storage/index/maildir/maildir-sync.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/maildir/maildir-sync.c Sun Feb 07 17:30:24 2010 +0200 @@ -236,7 +236,7 @@ ctx->last_touch = now; } if (now - ctx->last_notify > MAIL_STORAGE_STAYALIVE_SECS) { - struct mailbox *box = &ctx->mbox->ibox.box; + struct mailbox *box = &ctx->mbox->box; if (box->storage->callbacks.notify_ok != NULL) { box->storage->callbacks. @@ -255,8 +255,8 @@ ctx = t_new(struct maildir_sync_context, 1); ctx->mbox = mbox; - ctx->new_dir = t_strconcat(mbox->ibox.box.path, "/new", NULL); - ctx->cur_dir = t_strconcat(mbox->ibox.box.path, "/cur", NULL); + ctx->new_dir = t_strconcat(mbox->box.path, "/new", NULL); + ctx->cur_dir = t_strconcat(mbox->box.path, "/cur", NULL); ctx->last_touch = ioloop_time; ctx->last_notify = ioloop_time; ctx->flags = flags; @@ -319,8 +319,7 @@ } new_fname = maildir_filename_generate(); - new_path = t_strconcat(ctx->mbox->ibox.box.path, "/new/", - new_fname, NULL); + new_path = t_strconcat(ctx->mbox->box.path, "/new/", new_fname, NULL); if (rename(path2, new_path) == 0) i_warning("Fixed a duplicate: %s -> %s", path2, new_fname); @@ -336,7 +335,7 @@ static int maildir_stat(struct maildir_mailbox *mbox, const char *path, struct stat *st_r) { - struct mailbox *box = &mbox->ibox.box; + struct mailbox *box = &mbox->box; int i; for (i = 0;; i++) { @@ -386,7 +385,7 @@ return -1; } - if (!maildir_set_deleted(&ctx->mbox->ibox.box)) + if (!maildir_set_deleted(&ctx->mbox->box)) return -1; /* try again */ } @@ -419,8 +418,8 @@ src = t_str_new(1024); dest = t_str_new(1024); - move_new = new_dir && !mailbox_is_readonly(&ctx->mbox->ibox.box) && - (ctx->mbox->ibox.box.flags & MAILBOX_FLAG_KEEP_RECENT) == 0 && + move_new = new_dir && !mailbox_is_readonly(&ctx->mbox->box) && + (ctx->mbox->box.flags & MAILBOX_FLAG_KEEP_RECENT) == 0 && ctx->locked; errno = 0; @@ -537,12 +536,12 @@ const void *data; size_t data_size; - if (mail_index_refresh(mbox->ibox.box.index) < 0) { - mail_storage_set_index_error(&mbox->ibox.box); + if (mail_index_refresh(mbox->box.index) < 0) { + mail_storage_set_index_error(&mbox->box); return -1; } - mail_index_get_header_ext(mbox->ibox.box.view, mbox->maildir_ext_id, + mail_index_get_header_ext(mbox->box.view, mbox->maildir_ext_id, &data, &data_size); if (data_size == 0) { /* doesn't exist */ @@ -636,7 +635,7 @@ const struct mail_index_header *hdr; uint32_t uid_validity, next_uid; - hdr = mail_index_get_header(mbox->ibox.box.view); + hdr = mail_index_get_header(mbox->box.view); if (hdr->uid_validity == 0) return; @@ -662,7 +661,7 @@ /* if there are files in new/, we'll need to move them. we'll check this by checking if we have any recent messages */ - hdr = mail_index_get_header(ctx->mbox->ibox.box.view); + hdr = mail_index_get_header(ctx->mbox->box.view); return hdr->first_recent_uid < maildir_uidlist_get_next_uid(ctx->mbox->uidlist); } @@ -679,7 +678,7 @@ return -1; if (have_recent_messages(ctx)) { - if ((mbox->ibox.box.flags & MAILBOX_FLAG_KEEP_RECENT) == 0) { + if ((mbox->box.flags & MAILBOX_FLAG_KEEP_RECENT) == 0) { *new_changed_r = TRUE; } else if (*new_changed_r) { /* we have some recent messages and new/ has changed. @@ -693,10 +692,10 @@ if (*new_changed_r || *cur_changed_r) return 1; - if ((mbox->ibox.box.flags & MAILBOX_FLAG_KEEP_RECENT) == 0) + if ((mbox->box.flags & MAILBOX_FLAG_KEEP_RECENT) == 0) flags |= MAIL_INDEX_SYNC_FLAG_DROP_RECENT; - return mail_index_sync_have_any(mbox->ibox.box.index, flags) ? 1 : 0; + return mail_index_sync_have_any(mbox->box.index, flags) ? 1 : 0; } static int maildir_sync_context(struct maildir_sync_context *ctx, bool forced, @@ -778,7 +777,7 @@ &ctx->uidlist_sync_ctx); lock_failure = ret <= 0; if (ret <= 0) { - struct mail_storage *storage = ctx->mbox->ibox.box.storage; + struct mail_storage *storage = ctx->mbox->box.storage; if (ret == 0) { /* timeout */ @@ -801,7 +800,7 @@ } if (storage->callbacks.notify_no != NULL) { - storage->callbacks.notify_no(&ctx->mbox->ibox.box, + storage->callbacks.notify_no(&ctx->mbox->box, "Internal mailbox synchronization failure, " "showing only old mails.", storage->callback_context); @@ -924,7 +923,7 @@ } force_resync = (flags & MAILBOX_SYNC_FLAG_FORCE_RESYNC) != 0; - if (index_mailbox_want_full_sync(&mbox->ibox, flags)) { + if (index_mailbox_want_full_sync(&mbox->box, flags)) { T_BEGIN { ctx = maildir_sync_context_new(mbox, flags); ret = maildir_sync_context(ctx, force_resync, NULL, @@ -947,12 +946,12 @@ if (mbox->flags_view == NULL) { mbox->flags_view = - mail_index_view_open(mbox->ibox.box.index); + mail_index_view_open(mbox->box.index); } sync_ctx = mail_index_view_sync_begin(mbox->flags_view, MAIL_INDEX_VIEW_SYNC_FLAG_FIX_INCONSISTENT); if (mail_index_view_sync_commit(&sync_ctx, &b) < 0) { - mail_storage_set_index_error(&mbox->ibox.box); + mail_storage_set_index_error(&mbox->box); ret = -1; } /* make sure the map stays in private memory */ @@ -978,8 +977,8 @@ T_BEGIN { const char *new_dir, *cur_dir; - new_dir = t_strconcat(mbox->ibox.box.path, "/new", NULL); - cur_dir = t_strconcat(mbox->ibox.box.path, "/cur", NULL); + new_dir = t_strconcat(mbox->box.path, "/new", NULL); + cur_dir = t_strconcat(mbox->box.path, "/cur", NULL); ret = maildir_sync_quick_check(mbox, FALSE, new_dir, cur_dir, &new_changed, &cur_changed);
--- a/src/lib-storage/index/maildir/maildir-uidlist.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/maildir/maildir-uidlist.c Sun Feb 07 17:30:24 2010 +0200 @@ -66,7 +66,6 @@ struct maildir_uidlist { struct maildir_mailbox *mbox; - struct index_mailbox *ibox; char *path; int fd; @@ -137,7 +136,7 @@ bool nonblock, bool refresh, bool refresh_when_locked) { - struct mailbox *box = &uidlist->ibox->box; + struct mailbox *box = &uidlist->mbox->box; const char *control_dir, *path; mode_t old_mask; const enum dotlock_create_flags dotlock_flags = @@ -153,7 +152,7 @@ return 1; } - index_storage_lock_notify_reset(uidlist->ibox); + index_storage_lock_notify_reset(&uidlist->mbox->box); control_dir = mailbox_list_get_path(box->list, box->name, MAILBOX_LIST_PATH_TYPE_CONTROL); @@ -187,7 +186,7 @@ } /* the control dir doesn't exist. create it unless the whole mailbox was just deleted. */ - if (!maildir_set_deleted(&uidlist->mbox->ibox.box)) + if (!maildir_set_deleted(&uidlist->mbox->box)) return -1; } @@ -240,28 +239,26 @@ static bool dotlock_callback(unsigned int secs_left, bool stale, void *context) { - struct index_mailbox *ibox = context; + struct mailbox *box = context; - index_storage_lock_notify(ibox, stale ? + index_storage_lock_notify(box, stale ? MAILBOX_LOCK_NOTIFY_MAILBOX_OVERRIDE : MAILBOX_LOCK_NOTIFY_MAILBOX_ABORT, secs_left); return TRUE; } -struct maildir_uidlist * -maildir_uidlist_init_readonly(struct index_mailbox *ibox) +struct maildir_uidlist *maildir_uidlist_init(struct maildir_mailbox *mbox) { - struct mailbox *box = &ibox->box; struct maildir_uidlist *uidlist; const char *control_dir; - control_dir = mailbox_list_get_path(box->list, box->name, + control_dir = mailbox_list_get_path(mbox->box.list, mbox->box.name, MAILBOX_LIST_PATH_TYPE_CONTROL); uidlist = i_new(struct maildir_uidlist, 1); + uidlist->mbox = mbox; uidlist->fd = -1; - uidlist->ibox = ibox; uidlist->path = i_strconcat(control_dir, "/"MAILDIR_UIDLIST_NAME, NULL); i_array_init(&uidlist->records, 128); uidlist->files = hash_table_create(default_pool, default_pool, 4096, @@ -272,32 +269,22 @@ uidlist->dotlock_settings.use_io_notify = TRUE; uidlist->dotlock_settings.use_excl_lock = - box->storage->set->dotlock_use_excl; + mbox->box.storage->set->dotlock_use_excl; uidlist->dotlock_settings.nfs_flush = - box->storage->set->mail_nfs_storage; + mbox->box.storage->set->mail_nfs_storage; uidlist->dotlock_settings.timeout = MAILDIR_UIDLIST_LOCK_STALE_TIMEOUT + 2; uidlist->dotlock_settings.stale_timeout = MAILDIR_UIDLIST_LOCK_STALE_TIMEOUT; uidlist->dotlock_settings.callback = dotlock_callback; - uidlist->dotlock_settings.context = ibox; - - return uidlist; -} - -struct maildir_uidlist *maildir_uidlist_init(struct maildir_mailbox *mbox) -{ - struct maildir_uidlist *uidlist; - - uidlist = maildir_uidlist_init_readonly(&mbox->ibox); - uidlist->mbox = mbox; + uidlist->dotlock_settings.context = &mbox->box; uidlist->dotlock_settings.temp_prefix = mbox->storage->temp_prefix; return uidlist; } static void maildir_uidlist_close(struct maildir_uidlist *uidlist) { - struct mail_storage *storage = uidlist->ibox->box.storage; + struct mail_storage *storage = uidlist->mbox->box.storage; if (uidlist->fd != -1) { if (close(uidlist->fd) < 0) { @@ -352,7 +339,7 @@ maildir_uidlist_set_corrupted(struct maildir_uidlist *uidlist, const char *fmt, ...) { - struct mail_storage *storage = uidlist->ibox->box.storage; + struct mail_storage *storage = uidlist->mbox->box.storage; va_list args; va_start(args, fmt); @@ -697,7 +684,7 @@ maildir_uidlist_update_read(struct maildir_uidlist *uidlist, bool *retry_r, bool try_retry) { - struct mail_storage *storage = uidlist->ibox->box.storage; + struct mail_storage *storage = uidlist->mbox->box.storage; const char *line; uint32_t orig_next_uid, orig_uid_validity; struct istream *input; @@ -841,7 +828,7 @@ static int maildir_uidlist_stat(struct maildir_uidlist *uidlist, struct stat *st_r) { - struct mail_storage *storage = uidlist->ibox->box.storage; + struct mail_storage *storage = uidlist->mbox->box.storage; if (storage->set->mail_nfs_storage) { nfs_flush_file_handle_cache(uidlist->path); @@ -861,7 +848,7 @@ static int maildir_uidlist_has_changed(struct maildir_uidlist *uidlist, bool *recreated_r) { - struct mail_storage *storage = uidlist->ibox->box.storage; + struct mail_storage *storage = uidlist->mbox->box.storage; struct stat st; int ret; @@ -921,7 +908,7 @@ uidlist->fd = nfs_safe_open(uidlist->path, O_RDWR); if (uidlist->fd == -1 && errno != ENOENT) { - mail_storage_set_critical(uidlist->ibox->box.storage, + mail_storage_set_critical(uidlist->mbox->box.storage, "open(%s) failed: %m", uidlist->path); return -1; } @@ -961,7 +948,7 @@ int maildir_uidlist_refresh_fast_init(struct maildir_uidlist *uidlist) { const struct maildir_index_header *mhdr = &uidlist->mbox->maildir_hdr; - struct mail_index *index = uidlist->mbox->ibox.box.index; + struct mail_index *index = uidlist->mbox->box.index; struct mail_index_view *view; const struct mail_index_header *hdr; struct stat st; @@ -1223,22 +1210,22 @@ { const struct mail_index_header *hdr; - if (uidlist->ibox->box.opened) { - hdr = mail_index_get_header(uidlist->ibox->box.view); + if (uidlist->mbox->box.opened) { + hdr = mail_index_get_header(uidlist->mbox->box.view); if (hdr->uid_validity != 0) { uidlist->uid_validity = hdr->uid_validity; return; } } uidlist->uid_validity = - maildir_get_uidvalidity_next(uidlist->ibox->box.list); + maildir_get_uidvalidity_next(uidlist->mbox->box.list); } static int maildir_uidlist_write_fd(struct maildir_uidlist *uidlist, int fd, const char *path, unsigned int first_idx, uoff_t *file_size_r) { - struct mail_storage *storage = uidlist->ibox->box.storage; + struct mail_storage *storage = uidlist->mbox->box.storage; struct maildir_uidlist_iter_ctx *iter; struct ostream *output; struct maildir_uidlist_rec *rec; @@ -1331,11 +1318,11 @@ /* we could get here when opening and locking mailbox, before index files have been opened. */ - if (!uidlist->mbox->ibox.box.opened) + if (!uidlist->mbox->box.opened) return; - mail_index_refresh(uidlist->mbox->ibox.box.index); - view = mail_index_view_open(uidlist->mbox->ibox.box.index); + mail_index_refresh(uidlist->mbox->box.index); + view = mail_index_view_open(uidlist->mbox->box.index); count = array_count(&uidlist->records); hdr = mail_index_get_header(view); if (count * UIDLIST_COMPRESS_PERCENTAGE / 100 <= hdr->messages_count) { @@ -1380,7 +1367,7 @@ static int maildir_uidlist_recreate(struct maildir_uidlist *uidlist) { - struct mailbox *box = &uidlist->ibox->box; + struct mailbox *box = &uidlist->mbox->box; const char *control_dir, *temp_path; struct stat st; mode_t old_mask; @@ -1411,7 +1398,7 @@ } /* the control dir doesn't exist. create it unless the whole mailbox was just deleted. */ - if (!maildir_set_deleted(&uidlist->mbox->ibox.box)) + if (!maildir_set_deleted(&uidlist->mbox->box)) return -1; } @@ -1486,7 +1473,7 @@ static bool maildir_uidlist_want_compress(struct maildir_uidlist_sync_ctx *ctx) { - struct mail_index_view *view = ctx->uidlist->mbox->ibox.box.view; + struct mail_index_view *view = ctx->uidlist->mbox->box.view; unsigned int min_rewrite_count, messages_count; if (!ctx->uidlist->locked_refresh) @@ -1520,7 +1507,7 @@ static int maildir_uidlist_sync_update(struct maildir_uidlist_sync_ctx *ctx) { struct maildir_uidlist *uidlist = ctx->uidlist; - struct mail_storage *storage = uidlist->ibox->box.storage; + struct mail_storage *storage = uidlist->mbox->box.storage; struct stat st; uoff_t file_size; @@ -1742,7 +1729,7 @@ return -1; for (p = filename; *p != '\0'; p++) { if (*p == 13 || *p == 10) { - struct mailbox *box = &uidlist->ibox->box; + struct mailbox *box = &uidlist->mbox->box; dir = mailbox_list_get_path(box->list, box->name, MAILBOX_LIST_PATH_TYPE_MAILBOX);
--- a/src/lib-storage/index/maildir/maildir-uidlist.h Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/maildir/maildir-uidlist.h Sun Feb 07 17:30:24 2010 +0200 @@ -7,7 +7,6 @@ /* how many seconds to wait before overriding uidlist.lock */ #define MAILDIR_UIDLIST_LOCK_STALE_TIMEOUT (60*2) -struct index_mailbox; struct maildir_mailbox; struct maildir_uidlist; struct maildir_uidlist_sync_ctx; @@ -55,8 +54,6 @@ bool maildir_uidlist_is_locked(struct maildir_uidlist *uidlist); struct maildir_uidlist *maildir_uidlist_init(struct maildir_mailbox *mbox); -struct maildir_uidlist * -maildir_uidlist_init_readonly(struct index_mailbox *ibox); void maildir_uidlist_deinit(struct maildir_uidlist **uidlist); /* Returns -1 if error, 0 if file is broken or lost, 1 if ok. If nfs_flush=TRUE
--- a/src/lib-storage/index/maildir/maildir-util.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/maildir/maildir-util.c Sun Feb 07 17:30:24 2010 +0200 @@ -43,7 +43,7 @@ } else { *have_flags_r = TRUE; kw_ctx = maildir_keywords_sync_init_readonly(mbox->keywords, - mbox->ibox.box.index); + mbox->box.index); fname = maildir_filename_set_flags(kw_ctx, fname, flags, &keywords); maildir_keywords_sync_deinit(&kw_ctx); @@ -74,13 +74,13 @@ if ((flags & MAILDIR_UIDLIST_REC_FLAG_NEW_DIR) != 0) { /* probably in new/ dir */ - path = t_strconcat(mbox->ibox.box.path, "/new/", fname, NULL); + path = t_strconcat(mbox->box.path, "/new/", fname, NULL); ret = callback(mbox, path, context); if (ret != 0) return ret; } - path = t_strconcat(mbox->ibox.box.path, "/cur/", fname, NULL); + path = t_strconcat(mbox->box.path, "/cur/", fname, NULL); ret = callback(mbox, path, context); return ret; }
--- a/src/lib-storage/index/mbox/mbox-file.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/mbox/mbox-file.c Sun Feb 07 17:30:24 2010 +0200 @@ -21,15 +21,15 @@ if (mbox->mbox_file_stream != NULL) { /* read-only mbox stream */ - i_assert(mbox->ibox.backend_readonly); + i_assert(mbox->box.backend_readonly); return 0; } - fd = open(mbox->ibox.box.path, - mbox->ibox.backend_readonly ? O_RDONLY : O_RDWR); - if (fd == -1 && errno == EACCES && !mbox->ibox.backend_readonly) { - mbox->ibox.backend_readonly = TRUE; - fd = open(mbox->ibox.box.path, O_RDONLY); + fd = open(mbox->box.path, + mbox->box.backend_readonly ? O_RDONLY : O_RDWR); + if (fd == -1 && errno == EACCES && !mbox->box.backend_readonly) { + mbox->box.backend_readonly = TRUE; + fd = open(mbox->box.path, O_RDONLY); } if (fd == -1) { @@ -68,7 +68,7 @@ if (mbox->mbox_file_stream != NULL) { /* read-only mbox stream */ - i_assert(mbox->mbox_fd == -1 && mbox->ibox.backend_readonly); + i_assert(mbox->mbox_fd == -1 && mbox->box.backend_readonly); } else { if (mbox->mbox_fd == -1) { if (mbox_file_open(mbox) < 0) @@ -89,7 +89,7 @@ } mbox->mbox_stream = i_stream_create_raw_mbox(mbox->mbox_file_stream, - mbox->ibox.box.path); + mbox->box.path); if (mbox->mbox_lock_type != F_UNLCK) istream_raw_mbox_set_locked(mbox->mbox_stream); return 0; @@ -97,12 +97,13 @@ static void mbox_file_fix_atime(struct mbox_mailbox *mbox) { + struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(&mbox->box); struct utimbuf buf; struct stat st; - if (mbox->ibox.recent_flags_count > 0 && - (mbox->ibox.box.flags & MAILBOX_FLAG_KEEP_RECENT) != 0 && - mbox->mbox_fd != -1 && !mbox->ibox.backend_readonly) { + if (ibox->recent_flags_count > 0 && + (mbox->box.flags & MAILBOX_FLAG_KEEP_RECENT) != 0 && + mbox->mbox_fd != -1 && !mbox->box.backend_readonly) { /* we've seen recent messages which we want to keep recent. keep file's atime lower than mtime so \Marked status gets shown while listing */ @@ -113,7 +114,7 @@ if (st.st_atime >= st.st_mtime) { buf.modtime = st.st_mtime; buf.actime = buf.modtime - 1; - if (utime(mbox->ibox.box.path, &buf) < 0) { + if (utime(mbox->box.path, &buf) < 0) { mbox_set_syscall_error(mbox, "utimes()"); return; } @@ -131,7 +132,7 @@ if (mbox->mbox_file_stream != NULL) { if (mbox->mbox_fd == -1) { /* read-only mbox stream */ - i_assert(mbox->ibox.backend_readonly); + i_assert(mbox->box.backend_readonly); i_stream_seek(mbox->mbox_file_stream, 0); } else { i_stream_destroy(&mbox->mbox_file_stream); @@ -153,7 +154,7 @@ if (data == NULL) { mail_storage_set_critical(&mbox->storage->storage, "Cached message offset lost for seq %u in mbox file %s", - seq, mbox->ibox.box.path); + seq, mbox->box.path); mbox->mbox_hdr.dirty_flag = TRUE; mbox->mbox_broken_offsets = TRUE; return 0; @@ -190,7 +191,7 @@ mail_storage_set_critical(&mbox->storage->storage, "Cached message offset %s is invalid for mbox file %s", - dec2str(offset), mbox->ibox.box.path); + dec2str(offset), mbox->box.path); mbox->mbox_hdr.dirty_flag = TRUE; mbox->mbox_broken_offsets = TRUE; return 0;
--- a/src/lib-storage/index/mbox/mbox-lock.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/mbox/mbox-lock.c Sun Feb 07 17:30:24 2010 +0200 @@ -174,9 +174,9 @@ be sure that the file is latest, but mbox files get rarely deleted and the flushing might cause errors (e.g. EBUSY for trying to flush a /var/mail mountpoint) */ - if (nfs_safe_stat(mbox->ibox.box.path, &st) < 0) { + if (nfs_safe_stat(mbox->box.path, &st) < 0) { if (errno == ENOENT) - mailbox_set_deleted(&mbox->ibox.box); + mailbox_set_deleted(&mbox->box); else mbox_set_syscall_error(mbox, "stat()"); return -1; @@ -233,7 +233,7 @@ } ctx->dotlock_last_stale = stale; - index_storage_lock_notify(&ctx->mbox->ibox, stale ? + index_storage_lock_notify(&ctx->mbox->box, stale ? MAILBOX_LOCK_NOTIFY_MAILBOX_OVERRIDE : MAILBOX_LOCK_NOTIFY_MAILBOX_ABORT, secs_left); @@ -268,12 +268,12 @@ privileged group - DoS other users by dotlocking their mailboxes infinitely */ - fname = strrchr(mbox->ibox.box.path, '/'); + fname = strrchr(mbox->box.path, '/'); if (fname == NULL) { /* already relative */ - fname = mbox->ibox.box.path; + fname = mbox->box.path; } else { - dir = t_strdup_until(mbox->ibox.box.path, fname); + dir = t_strdup_until(mbox->box.path, fname); if (chdir(dir) < 0) { mail_storage_set_critical(&mbox->storage->storage, "chdir(%s) failed: %m", dir); @@ -285,7 +285,7 @@ if (op == MBOX_DOTLOCK_OP_LOCK) { if (access(fname, R_OK) < 0) { mail_storage_set_critical(&mbox->storage->storage, - "access(%s) failed: %m", mbox->ibox.box.path); + "access(%s) failed: %m", mbox->box.path); return -1; } } @@ -348,11 +348,11 @@ errmsg = eacces_error_get_creating("file_dotlock_create", path); dir = strrchr(path, '/'); dir = dir == NULL ? "." : t_strdup_until(path, dir); - if (strcmp(mbox->ibox.box.name, "INBOX") != 0) { + if (strcmp(mbox->box.name, "INBOX") != 0) { mail_storage_set_critical(&mbox->storage->storage, "%s (not INBOX -> no privileged locking)", errmsg); } else if (!mbox->mbox_privileged_locking) { - dir = mailbox_list_get_path(mbox->ibox.box.list, NULL, + dir = mailbox_list_get_path(mbox->box.list, NULL, MAILBOX_LIST_PATH_TYPE_DIR); mail_storage_set_critical(&mbox->storage->storage, "%s (under root dir %s -> no privileged locking)", @@ -410,7 +410,7 @@ set.callback = dotlock_callback; set.context = ctx; - ret = file_dotlock_create(&set, mbox->ibox.box.path, 0, + ret = file_dotlock_create(&set, mbox->box.path, 0, &mbox->mbox_dotlock); if (ret >= 0) { /* success / timeout */ @@ -420,7 +420,7 @@ ret = mbox_dotlock_privileged_op(mbox, &set, MBOX_DOTLOCK_OP_LOCK); } else if (errno == EACCES) - mbox_dotlock_log_eacces_error(mbox, mbox->ibox.box.path); + mbox_dotlock_log_eacces_error(mbox, mbox->box.path); else mbox_set_syscall_error(mbox, "file_dotlock_create()"); @@ -510,7 +510,7 @@ next_alarm = 5; alarm(next_alarm); - index_storage_lock_notify(&ctx->mbox->ibox, + index_storage_lock_notify(&ctx->mbox->box, MAILBOX_LOCK_NOTIFY_MAILBOX_ABORT, max_wait_time - now); } @@ -574,7 +574,7 @@ next_alarm = 5; alarm(next_alarm); - index_storage_lock_notify(&ctx->mbox->ibox, + index_storage_lock_notify(&ctx->mbox->box, MAILBOX_LOCK_NOTIFY_MAILBOX_ABORT, max_wait_time - now); } @@ -632,7 +632,7 @@ mail_storage_set_critical(&ctx->mbox->storage->storage, "fcntl() failed with mbox file %s: " "File is locked by another process (EACCES)", - ctx->mbox->ibox.box.path); + ctx->mbox->box.path); return -1; } @@ -649,7 +649,7 @@ next_alarm = 5; alarm(next_alarm); - index_storage_lock_notify(&ctx->mbox->ibox, + index_storage_lock_notify(&ctx->mbox->box, MAILBOX_LOCK_NOTIFY_MAILBOX_ABORT, max_wait_time - now); } @@ -697,14 +697,14 @@ *fcntl_locked_r = FALSE; - index_storage_lock_notify_reset(&mbox->ibox); + index_storage_lock_notify_reset(&mbox->box); if (!mbox->storage->lock_settings_initialized) mbox_init_lock_settings(mbox->storage); if (mbox->mbox_fd == -1 && mbox->mbox_file_stream != NULL) { /* read-only mbox stream. no need to lock. */ - i_assert(mbox->ibox.backend_readonly); + i_assert(mbox->box.backend_readonly); mbox->mbox_lock_type = lock_type; return 1; } @@ -767,7 +767,7 @@ int mbox_lock(struct mbox_mailbox *mbox, int lock_type, unsigned int *lock_id_r) { - const char *path = mbox->ibox.box.path; + const char *path = mbox->box.path; int mbox_fd = mbox->mbox_fd; bool fcntl_locked; int ret; @@ -777,7 +777,7 @@ i_assert(lock_type == F_RDLCK || mbox->mbox_lock_type != F_RDLCK); /* mbox must be locked before index */ - i_assert(mbox->ibox.box.index->lock_type != F_WRLCK); + i_assert(mbox->box.index->lock_type != F_WRLCK); if (mbox->mbox_lock_type == F_UNLCK) { ret = mbox_update_locking(mbox, lock_type, &fcntl_locked);
--- a/src/lib-storage/index/mbox/mbox-mail.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/mbox/mbox-mail.c Sun Feb 07 17:30:24 2010 +0200 @@ -16,11 +16,11 @@ #include <unistd.h> #include <sys/stat.h> -static void mbox_prepare_resync(struct index_mail *mail) +static void mbox_prepare_resync(struct mail *mail) { struct mbox_transaction_context *t = - (struct mbox_transaction_context *)mail->trans; - struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->ibox; + (struct mbox_transaction_context *)mail->transaction; + struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->box; if (mbox->mbox_lock_type == F_RDLCK) { if (mbox->mbox_lock_id == t->mbox_lock_id) @@ -34,16 +34,17 @@ { struct mbox_transaction_context *t = (struct mbox_transaction_context *)mail->trans; - struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->ibox; + struct mail *_mail = &mail->mail.mail; + struct mbox_mailbox *mbox = (struct mbox_mailbox *)_mail->box; enum mbox_sync_flags sync_flags = 0; int ret, try; bool deleted; - if (mail->mail.mail.expunged || mbox->syncing) + if (_mail->expunged || mbox->syncing) return -1; - if (mail->mail.mail.lookup_abort != MAIL_LOOKUP_ABORT_NEVER) - return mail_set_aborted(&mail->mail.mail); + if (_mail->lookup_abort != MAIL_LOOKUP_ABORT_NEVER) + return mail_set_aborted(_mail); if (mbox->mbox_stream != NULL && istream_raw_mbox_is_corrupted(mbox->mbox_stream)) { @@ -54,7 +55,7 @@ for (try = 0; try < 2; try++) { if ((sync_flags & MBOX_SYNC_FORCE_SYNC) != 0) { /* dirty offsets are broken. make sure we can sync. */ - mbox_prepare_resync(mail); + mbox_prepare_resync(_mail); } if (mbox->mbox_lock_type == F_UNLCK) { sync_flags |= MBOX_SYNC_LOCK_READING; @@ -65,8 +66,8 @@ /* refresh index file after mbox has been locked to make sure we get only up-to-date mbox offsets. */ - if (mail_index_refresh(mbox->ibox.box.index) < 0) { - mail_storage_set_index_error(&mbox->ibox.box); + if (mail_index_refresh(mbox->box.index) < 0) { + mail_storage_set_index_error(&mbox->box); return -1; } @@ -84,14 +85,14 @@ return -1; ret = mbox_file_seek(mbox, mail->trans->trans_view, - mail->mail.mail.seq, &deleted); + _mail->seq, &deleted); if (ret > 0) { /* success */ break; } if (ret < 0) { if (deleted) - mail_set_expunged(&mail->mail.mail); + mail_set_expunged(_mail); return -1; } @@ -101,7 +102,7 @@ if (ret == 0) { mail_storage_set_critical(&mbox->storage->storage, "Losing sync for mail uid=%u in mbox file %s", - mail->mail.mail.uid, mbox->ibox.box.path); + _mail->uid, mbox->box.path); } return 0; } @@ -110,7 +111,7 @@ { struct index_mail *mail = (struct index_mail *)_mail; struct index_mail_data *data = &mail->data; - struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->ibox; + struct mbox_mailbox *mbox = (struct mbox_mailbox *)_mail->box; if (index_mail_get_received_date(_mail, date_r) == 0) return 0; @@ -150,7 +151,7 @@ { static uint8_t empty_md5[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->ibox; + struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->mail.mail.box; const void *ext_data; if (mail->data.guid != NULL) @@ -173,7 +174,7 @@ const char **value_r) { struct index_mail *mail = (struct index_mail *)_mail; - struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->ibox; + struct mbox_mailbox *mbox = (struct mbox_mailbox *)_mail->box; switch (field) { case MAIL_FETCH_FROM_ENVELOPE: @@ -191,7 +192,7 @@ but it's almost guaranteed that it means the MD5 sum is missing. recalculate it. */ mbox->mbox_save_md5 = TRUE; - mbox_prepare_resync(mail); + mbox_prepare_resync(_mail); if (mbox_sync(mbox, MBOX_SYNC_FORCE_SYNC) < 0) return -1; @@ -211,7 +212,7 @@ static bool mbox_mail_get_next_offset(struct index_mail *mail, uoff_t *next_offset_r) { - struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->ibox; + struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->mail.mail.box; struct mail_index_view *view; const struct mail_index_header *hdr; uint32_t seq; @@ -232,7 +233,7 @@ if (mbox_sync_header_refresh(mbox) < 0) return -1; - view = mail_index_view_open(mail->ibox->box.index); + view = mail_index_view_open(mail->mail.mail.box->index); hdr = mail_index_get_header(view); if (!mail_index_lookup_seq(view, mail->mail.mail.uid, &seq)) i_panic("Message unexpectedly expunged from index"); @@ -255,7 +256,7 @@ { struct index_mail *mail = (struct index_mail *)_mail; struct index_mail_data *data = &mail->data; - struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->ibox; + struct mbox_mailbox *mbox = (struct mbox_mailbox *)_mail->box; struct istream *input; struct message_size hdr_size; uoff_t old_offset, body_offset, body_size, next_offset; @@ -296,7 +297,7 @@ static int mbox_mail_init_stream(struct index_mail *mail) { - struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->ibox; + struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->mail.mail.box; struct istream *raw_stream; uoff_t hdr_offset, next_offset; int ret; @@ -312,7 +313,7 @@ if (ret < 0) { i_warning("mbox %s: Can't find next message offset " "for uid=%u", - mbox->ibox.box.path, mail->mail.mail.uid); + mbox->box.path, mail->mail.mail.uid); } } if (ret <= 0)
--- a/src/lib-storage/index/mbox/mbox-save.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/mbox/mbox-save.c Sun Feb 07 17:30:24 2010 +0200 @@ -179,8 +179,8 @@ /* open a new view to get the header. this is required if we just synced the mailbox so we can get updated next_uid. */ - (void)mail_index_refresh(mbox->ibox.box.index); - view = mail_index_view_open(mbox->ibox.box.index); + (void)mail_index_refresh(mbox->box.index); + view = mail_index_view_open(mbox->box.index); hdr = mail_index_get_header(view); ctx->next_uid = hdr->next_uid; @@ -227,7 +227,7 @@ const char *const *keyword_names; unsigned int i, count, keyword_names_count; - keyword_names_list = mail_index_get_keywords(ctx->mbox->ibox.box.index); + keyword_names_list = mail_index_get_keywords(ctx->mbox->box.index); keyword_names = array_get(keyword_names_list, &keyword_names_count); str_append(ctx->headers, "X-Keywords:"); @@ -255,14 +255,14 @@ bool empty = FALSE; int ret; - if (ctx->mbox->ibox.backend_readonly) { + if (ctx->mbox->box.backend_readonly) { mail_storage_set_error(storage, MAIL_ERROR_PERM, "Read-only mbox"); return -1; } - if (mail_index_is_deleted(mbox->ibox.box.index)) { - mailbox_set_deleted(&mbox->ibox.box); + if (mail_index_is_deleted(mbox->box.index)) { + mailbox_set_deleted(&mbox->box); return -1; } @@ -778,7 +778,7 @@ buf.modtime = st.st_mtime; buf.actime = ctx->orig_atime; - if (utime(mbox->ibox.box.path, &buf) < 0) + if (utime(mbox->box.path, &buf) < 0) mbox_set_syscall_error(mbox, "utime()"); }
--- a/src/lib-storage/index/mbox/mbox-storage.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/mbox/mbox-storage.c Sun Feb 07 17:30:24 2010 +0200 @@ -83,7 +83,7 @@ } else { mail_storage_set_critical(&mbox->storage->storage, "%s failed with mbox file %s: %m", - function, mbox->ibox.box.path); + function, mbox->box.path); } return -1; } @@ -338,37 +338,39 @@ enum mailbox_flags flags) { struct mbox_mailbox *mbox; + struct index_mailbox_context *ibox; pool_t pool; pool = pool_alloconly_create("mbox mailbox", 1024+512); mbox = p_new(pool, struct mbox_mailbox, 1); - mbox->ibox.box = mbox_mailbox; - mbox->ibox.box.pool = pool; - mbox->ibox.box.storage = storage; - mbox->ibox.box.list = list; - mbox->ibox.box.mail_vfuncs = &mbox_mail_vfuncs; + mbox->box = mbox_mailbox; + mbox->box.pool = pool; + mbox->box.storage = storage; + mbox->box.list = list; + mbox->box.mail_vfuncs = &mbox_mail_vfuncs; - mbox->ibox.save_commit_pre = mbox_transaction_save_commit_pre; - mbox->ibox.save_commit_post = mbox_transaction_save_commit_post; - mbox->ibox.save_rollback = mbox_transaction_save_rollback; + index_storage_mailbox_alloc(&mbox->box, name, input, flags, + MBOX_INDEX_PREFIX); - index_storage_mailbox_alloc(&mbox->ibox, name, input, flags, - MBOX_INDEX_PREFIX); + ibox = INDEX_STORAGE_CONTEXT(&mbox->box); + ibox->save_commit_pre = mbox_transaction_save_commit_pre; + ibox->save_commit_post = mbox_transaction_save_commit_post; + ibox->save_rollback = mbox_transaction_save_rollback; mbox->storage = (struct mbox_storage *)storage; mbox->mbox_fd = -1; mbox->mbox_lock_type = F_UNLCK; mbox->mbox_ext_idx = - mail_index_ext_register(mbox->ibox.box.index, "mbox", + mail_index_ext_register(mbox->box.index, "mbox", sizeof(mbox->mbox_hdr), sizeof(uint64_t), sizeof(uint64_t)); mbox->md5hdr_ext_idx = - mail_index_ext_register(mbox->ibox.box.index, "header-md5", + mail_index_ext_register(mbox->box.index, "header-md5", 0, 16, 1); if ((storage->flags & MAIL_STORAGE_FLAG_KEEP_HEADER_MD5) != 0) mbox->mbox_save_md5 = TRUE; - return &mbox->ibox.box; + return &mbox->box; } static int verify_inbox(struct mailbox_list *list) @@ -418,18 +420,18 @@ static int mbox_mailbox_open_existing(struct mbox_mailbox *mbox) { - struct mailbox *box = &mbox->ibox.box; + struct mailbox *box = &mbox->box; const char *rootdir; + bool move_to_memory; if (access(box->path, R_OK|W_OK) < 0) { if (errno != EACCES) { mbox_set_syscall_error(mbox, "access()"); return -1; } - mbox->ibox.backend_readonly = TRUE; + mbox->box.backend_readonly = TRUE; } - mbox->ibox.move_to_memory = - want_memory_indexes(mbox->storage, box->path); + move_to_memory = want_memory_indexes(mbox->storage, box->path); if (strcmp(box->name, "INBOX") == 0) { /* if INBOX isn't under the root directory, it's probably in @@ -449,7 +451,7 @@ mbox_lock_touch_timeout, mbox); } } - return index_storage_mailbox_open(box); + return index_storage_mailbox_open(box, move_to_memory); } static int mbox_mailbox_open(struct mailbox *box) @@ -460,7 +462,7 @@ if (box->input != NULL) { mbox->mbox_file_stream = box->input; - mbox->ibox.backend_readonly = TRUE; + mbox->box.backend_readonly = TRUE; mbox->no_mbox_file = TRUE; return 0; } @@ -549,7 +551,7 @@ if (box->view != NULL) { hdr = mail_index_get_header(box->view); if ((hdr->flags & MAIL_INDEX_HDR_FLAG_HAVE_DIRTY) != 0 && - !mbox->ibox.backend_readonly) { + !mbox->box.backend_readonly) { /* we've done changes to mbox which haven't been written yet. do it now. */ sync_flags |= MBOX_SYNC_REWRITE; @@ -588,9 +590,9 @@ struct mbox_mailbox *mbox = (struct mbox_mailbox *)box; if (box->notify_callback == NULL) - index_mailbox_check_remove_all(&mbox->ibox); + index_mailbox_check_remove_all(&mbox->box); else if (!mbox->no_mbox_file) - index_mailbox_check_add(&mbox->ibox, mbox->ibox.box.path); + index_mailbox_check_add(&mbox->box, mbox->box.path); } static bool @@ -814,7 +816,7 @@ if (lock_id != 0) (void)mbox_unlock(mbox, lock_id); if (mbox->mbox_global_lock_id == 0) { - i_assert(mbox->ibox.box.transaction_count > 0 || + i_assert(mbox->box.transaction_count > 0 || mbox->mbox_lock_type == F_UNLCK); } else { /* mailbox opened with MAILBOX_FLAG_KEEP_LOCKED */
--- a/src/lib-storage/index/mbox/mbox-storage.h Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/mbox/mbox-storage.h Sun Feb 07 17:30:24 2010 +0200 @@ -32,7 +32,7 @@ }; struct mbox_mailbox { - struct index_mailbox ibox; + struct mailbox box; struct mbox_storage *storage; int mbox_fd;
--- a/src/lib-storage/index/mbox/mbox-sync-parse.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/mbox/mbox-sync-parse.c Sun Feb 07 17:30:24 2010 +0200 @@ -113,7 +113,8 @@ parse_imap_keywords_list(struct mbox_sync_mail_context *ctx, struct message_header_line *hdr, size_t pos) { - struct mailbox *box = &ctx->sync_ctx->mbox->ibox.box; + struct mailbox *box = &ctx->sync_ctx->mbox->box; + struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box); const char *keyword, *error; size_t keyword_start; unsigned int idx, count; @@ -135,7 +136,7 @@ /* add it to index's keyword list if it's not there already */ keyword = t_strndup(hdr->full_value + keyword_start, pos - keyword_start); - if (mailbox_keyword_is_valid(&ctx->sync_ctx->mbox->ibox.box, + if (mailbox_keyword_is_valid(&ctx->sync_ctx->mbox->box, keyword, &error)) { mail_index_keyword_lookup_or_create(box->index, keyword, &idx); @@ -143,7 +144,7 @@ count++; } - if (count != array_count(ctx->sync_ctx->mbox->ibox.keyword_names)) { + if (count != array_count(ibox->keyword_names)) { /* need to update this list */ ctx->imapbase_rewrite = TRUE; ctx->need_rewrite = TRUE; @@ -247,7 +248,7 @@ static bool parse_x_keywords_real(struct mbox_sync_mail_context *ctx, struct message_header_line *hdr) { - struct mailbox *box = &ctx->sync_ctx->mbox->ibox.box; + struct mailbox *box = &ctx->sync_ctx->mbox->box; ARRAY_TYPE(keyword_indexes) keyword_list; const unsigned int *list; string_t *keyword;
--- a/src/lib-storage/index/mbox/mbox-sync-update.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/mbox/mbox-sync-update.c Sun Feb 07 17:30:24 2010 +0200 @@ -124,12 +124,14 @@ keywords_append(struct mbox_sync_context *sync_ctx, string_t *dest, const ARRAY_TYPE(keyword_indexes) *keyword_indexes_arr) { + struct index_mailbox_context *ibox = + INDEX_STORAGE_CONTEXT(&sync_ctx->mbox->box); const char *const *keyword_names; const unsigned int *keyword_indexes; unsigned int i, idx_count, keywords_count; size_t last_break; - keyword_names = array_get(sync_ctx->mbox->ibox.keyword_names, + keyword_names = array_get(ibox->keyword_names, &keywords_count); keyword_indexes = array_get(keyword_indexes_arr, &idx_count); @@ -152,6 +154,8 @@ keywords_append_all(struct mbox_sync_mail_context *ctx, string_t *dest, size_t startpos) { + struct index_mailbox_context *ibox = + INDEX_STORAGE_CONTEXT(&ctx->sync_ctx->mbox->box); const char *const *names; const unsigned char *p; unsigned int i, count; @@ -168,7 +172,7 @@ } } - names = array_get(ctx->sync_ctx->mbox->ibox.keyword_names, &count); + names = array_get(ibox->keyword_names, &count); for (i = 0; i < count; i++) { /* wrap the line whenever it gets too long */ if (str_len(dest) - last_break < KEYWORD_WRAP_LINE_LENGTH)
--- a/src/lib-storage/index/mbox/mbox-sync.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/mbox/mbox-sync.c Sun Feb 07 17:30:24 2010 +0200 @@ -73,13 +73,13 @@ mail_storage_set_critical(&sync_ctx->mbox->storage->storage, "mbox file %s was modified while we were syncing, " "check your locking settings", - sync_ctx->mbox->ibox.box.path); + sync_ctx->mbox->box.path); } va_start(va, fmt); mail_storage_set_critical(&sync_ctx->mbox->storage->storage, "Sync failed for mbox file %s: %s", - sync_ctx->mbox->ibox.box.path, + sync_ctx->mbox->box.path, t_strdup_vprintf(fmt, va)); va_end(va); } @@ -181,7 +181,7 @@ index_sync_changes_read(sync_ctx->sync_changes, uid, sync_expunge_r, expunged_guid_128); - if (sync_ctx->mbox->ibox.backend_readonly) { + if (sync_ctx->mbox->box.backend_readonly) { /* we can't expunge anything from read-only mboxes */ *sync_expunge_r = FALSE; } @@ -296,7 +296,7 @@ mbox_sync_update_index_keywords(struct mbox_sync_mail_context *mail_ctx) { struct mbox_sync_context *sync_ctx = mail_ctx->sync_ctx; - struct mail_index *index = sync_ctx->mbox->ibox.box.index; + struct mail_index *index = sync_ctx->mbox->box.index; struct mail_keywords *keywords; keywords = !array_is_created(&mail_ctx->mail.keywords) ? @@ -366,7 +366,7 @@ const struct mail_index_record *rec) { struct mbox_sync_context *sync_ctx = mail_ctx->sync_ctx; - struct mailbox *box = &sync_ctx->mbox->ibox.box; + struct mailbox *box = &sync_ctx->mbox->box; struct mbox_sync_mail *mail = &mail_ctx->mail; enum mail_index_sync_type sync_type; ARRAY_TYPE(keyword_indexes) orig_keywords = ARRAY_INIT; @@ -594,7 +594,7 @@ static void mbox_sync_handle_expunge(struct mbox_sync_mail_context *mail_ctx) { struct mbox_sync_context *sync_ctx = mail_ctx->sync_ctx; - struct mailbox *box = &sync_ctx->mbox->ibox.box; + struct mailbox *box = &sync_ctx->mbox->box; if (box->v.sync_notify != NULL) { box->v.sync_notify(box, mail_ctx->mail.uid, @@ -991,7 +991,7 @@ i_warning("UIDVALIDITY changed (%u -> %u) in mbox file %s", sync_ctx->hdr->uid_validity, sync_ctx->base_uid_validity, - sync_ctx->mbox->ibox.box.path); + sync_ctx->mbox->box.path); sync_ctx->index_reset = TRUE; return TRUE; } @@ -1114,7 +1114,7 @@ &sync_ctx->mbox->storage->storage, "Out of UIDs, renumbering them in mbox " "file %s", - sync_ctx->mbox->ibox.box.path); + sync_ctx->mbox->box.path); sync_ctx->renumber_uids = TRUE; return 0; } @@ -1390,7 +1390,7 @@ mail_generate_guid_128(mbox->mbox_hdr.mailbox_guid); } - mail_index_get_header_ext(mbox->ibox.box.view, mbox->mbox_ext_idx, + mail_index_get_header_ext(mbox->box.view, mbox->mbox_ext_idx, &data, &data_size); if (data_size != sizeof(mbox->mbox_hdr) || memcmp(data, &mbox->mbox_hdr, data_size) != 0) { @@ -1429,7 +1429,7 @@ quite minimal (an extra logged error message). */ while (sync_ctx->orig_mtime == st->st_mtime) { usleep(500000); - if (utime(sync_ctx->mbox->ibox.box.path, NULL) < 0) { + if (utime(sync_ctx->mbox->box.path, NULL) < 0) { mbox_set_syscall_error(sync_ctx->mbox, "utime()"); return -1; @@ -1483,7 +1483,7 @@ view = mail_index_transaction_open_updated_view(sync_ctx->t); if (mail_index_lookup_seq_range(view, sync_ctx->last_nonrecent_uid + 1, (uint32_t)-1, &seq, &seq2)) { - index_mailbox_set_recent_seq(&sync_ctx->mbox->ibox, + index_mailbox_set_recent_seq(&sync_ctx->mbox->box, view, seq, seq2); } mail_index_view_close(&view); @@ -1515,7 +1515,7 @@ mail_index_reset(sync_ctx->t); sync_ctx->reset_hdr.next_uid = 1; sync_ctx->hdr = &sync_ctx->reset_hdr; - index_mailbox_reset_uidvalidity(&sync_ctx->mbox->ibox); + index_mailbox_reset_uidvalidity(&sync_ctx->mbox->box); } sync_ctx->prev_msg_uid = 0; @@ -1590,7 +1590,7 @@ b) we ran out of UIDs c) syncing had errors */ if (sync_ctx->delay_writes && - !sync_ctx->mbox->ibox.backend_readonly && + !sync_ctx->mbox->box.backend_readonly && (sync_ctx->errors || sync_ctx->renumber_uids)) { /* fixing a broken mbox state, be sure to write the changes. */ @@ -1631,16 +1631,16 @@ const void *data; size_t data_size; - if (mail_index_refresh(mbox->ibox.box.index) < 0) { - mail_storage_set_index_error(&mbox->ibox.box); + if (mail_index_refresh(mbox->box.index) < 0) { + mail_storage_set_index_error(&mbox->box); return -1; } - mail_index_get_header_ext(mbox->ibox.box.view, mbox->mbox_ext_idx, + mail_index_get_header_ext(mbox->box.view, mbox->mbox_ext_idx, &data, &data_size); if (data_size == 0) { /* doesn't exist. FIXME: backwards compatibility copying */ - hdr = mail_index_get_header(mbox->ibox.box.view); + hdr = mail_index_get_header(mbox->box.view); mbox->mbox_hdr.sync_mtime = hdr->sync_stamp; mbox->mbox_hdr.sync_size = hdr->sync_size; return 0; @@ -1670,16 +1670,16 @@ st = i_stream_stat(mbox->mbox_file_stream, FALSE); if (st == NULL) { if (errno == ENOENT) { - mailbox_set_deleted(&mbox->ibox.box); + mailbox_set_deleted(&mbox->box); return 0; } mbox_set_syscall_error(mbox, "i_stream_stat()"); return -1; } } else { - if (stat(mbox->ibox.box.path, &statbuf) < 0) { + if (stat(mbox->box.path, &statbuf) < 0) { if (errno == ENOENT) { - mailbox_set_deleted(&mbox->ibox.box); + mailbox_set_deleted(&mbox->box); return 0; } mbox_set_syscall_error(mbox, "stat()"); @@ -1732,7 +1732,7 @@ int ret, changed; bool delay_writes; - delay_writes = mbox->ibox.backend_readonly || + delay_writes = mbox->box.backend_readonly || ((flags & MBOX_SYNC_REWRITE) == 0 && mbox->storage->set->mbox_lazy_writes); @@ -1779,7 +1779,7 @@ lock it for writing immediately. the mbox must be locked before index syncing is started to avoid deadlocks, so we don't have much choice either (well, easy ones anyway). */ - int lock_type = mbox->ibox.backend_readonly ? F_RDLCK : F_WRLCK; + int lock_type = mbox->box.backend_readonly ? F_RDLCK : F_WRLCK; if ((ret = mbox_lock(mbox, lock_type, lock_id)) <= 0) { if (ret == 0 || lock_type == F_RDLCK) @@ -1788,25 +1788,25 @@ /* try as read-only */ if (mbox_lock(mbox, F_RDLCK, lock_id) <= 0) return -1; - mbox->ibox.backend_readonly = TRUE; + mbox->box.backend_readonly = TRUE; } } sync_flags = 0; - if ((mbox->ibox.box.flags & MAILBOX_FLAG_KEEP_RECENT) == 0) + if ((mbox->box.flags & MAILBOX_FLAG_KEEP_RECENT) == 0) sync_flags |= MAIL_INDEX_SYNC_FLAG_DROP_RECENT; if ((flags & MBOX_SYNC_REWRITE) != 0) sync_flags |= MAIL_INDEX_SYNC_FLAG_FLUSH_DIRTY; - ret = mail_index_sync_begin(mbox->ibox.box.index, &index_sync_ctx, + ret = mail_index_sync_begin(mbox->box.index, &index_sync_ctx, &sync_view, &trans, sync_flags); if (ret <= 0) { if (ret < 0) - mail_storage_set_index_error(&mbox->ibox.box); + mail_storage_set_index_error(&mbox->box); return ret; } - if ((mbox->ibox.box.flags & MAILBOX_FLAG_KEEP_RECENT) == 0) { + if ((mbox->box.flags & MAILBOX_FLAG_KEEP_RECENT) == 0) { /* see if we need to drop recent flags */ sync_ctx.hdr = mail_index_get_header(sync_view); if (sync_ctx.hdr->first_recent_uid < sync_ctx.hdr->next_uid) @@ -1819,7 +1819,7 @@ /* index may need to do internal syncing though, so commit instead of rollbacking. */ if (mail_index_sync_commit(&index_sync_ctx) < 0) { - mail_storage_set_index_error(&mbox->ibox.box); + mail_storage_set_index_error(&mbox->box); return -1; } return 0; @@ -1828,7 +1828,7 @@ memset(&sync_ctx, 0, sizeof(sync_ctx)); sync_ctx.mbox = mbox; sync_ctx.keep_recent = - (mbox->ibox.box.flags & MAILBOX_FLAG_KEEP_RECENT) != 0; + (mbox->box.flags & MAILBOX_FLAG_KEEP_RECENT) != 0; sync_ctx.hdr = mail_index_get_header(sync_view); sync_ctx.from_line = str_new(default_pool, 256); @@ -1843,17 +1843,16 @@ pool_alloconly_create("mbox saved keywords", 4096); /* make sure we've read the latest keywords in index */ - (void)mail_index_get_keywords(mbox->ibox.box.index); + (void)mail_index_get_keywords(mbox->box.index); i_array_init(&sync_ctx.mails, 64); sync_ctx.flags = flags; sync_ctx.delay_writes = delay_writes || - sync_ctx.mbox->ibox.backend_readonly; + sync_ctx.mbox->box.backend_readonly; sync_ctx.sync_changes = - index_sync_changes_init(&mbox->ibox, index_sync_ctx, - sync_view, trans, + index_sync_changes_init(index_sync_ctx, sync_view, trans, sync_ctx.delay_writes); if (!changed && delay_writes) { @@ -1895,14 +1894,14 @@ if (ret < 0) mail_index_sync_rollback(&index_sync_ctx); else if (mail_index_sync_commit(&index_sync_ctx) < 0) { - mail_storage_set_index_error(&mbox->ibox.box); + mail_storage_set_index_error(&mbox->box); ret = -1; } sync_ctx.t = NULL; sync_ctx.index_sync_ctx = NULL; if (ret == 0 && mbox->mbox_fd != -1 && sync_ctx.keep_recent && - !sync_ctx.mbox->ibox.backend_readonly) { + !sync_ctx.mbox->box.backend_readonly) { /* try to set atime back to its original value */ struct utimbuf buf; struct stat st; @@ -1912,7 +1911,7 @@ else { buf.modtime = st.st_mtime; buf.actime = sync_ctx.orig_atime; - if (utime(mbox->ibox.box.path, &buf) < 0) + if (utime(mbox->box.path, &buf) < 0) mbox_set_syscall_error(mbox, "utime()"); } } @@ -1960,8 +1959,8 @@ } } - if (mbox->ibox.box.v.sync_notify != NULL) - mbox->ibox.box.v.sync_notify(&mbox->ibox.box, 0, 0); + if (mbox->box.v.sync_notify != NULL) + mbox->box.v.sync_notify(&mbox->box, 0, 0); return ret; } @@ -1977,7 +1976,7 @@ ret = -1; } - if (index_mailbox_want_full_sync(&mbox->ibox, flags) && ret == 0) { + if (index_mailbox_want_full_sync(&mbox->box, flags) && ret == 0) { if ((flags & MAILBOX_SYNC_FLAG_FULL_READ) != 0 && !mbox->storage->set->mbox_very_dirty_syncs) mbox_sync_flags |= MBOX_SYNC_UNDIRTY;
--- a/src/lib-storage/index/raw/raw-storage.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/raw/raw-storage.c Sun Feb 07 17:30:24 2010 +0200 @@ -46,13 +46,13 @@ pool = pool_alloconly_create("raw mailbox", 1024+512); mbox = p_new(pool, struct raw_mailbox, 1); - mbox->ibox.box = raw_mailbox; - mbox->ibox.box.pool = pool; - mbox->ibox.box.storage = storage; - mbox->ibox.box.list = list; - mbox->ibox.box.mail_vfuncs = &raw_mail_vfuncs; + mbox->box = raw_mailbox; + mbox->box.pool = pool; + mbox->box.storage = storage; + mbox->box.list = list; + mbox->box.mail_vfuncs = &raw_mail_vfuncs; - index_storage_mailbox_alloc(&mbox->ibox, name, input, flags, NULL); + index_storage_mailbox_alloc(&mbox->box, name, input, flags, NULL); mbox->storage = (struct raw_storage *)storage; @@ -63,7 +63,7 @@ mbox->have_filename = TRUE; } mbox->size = (uoff_t)-1; - return &mbox->ibox.box; + return &mbox->box; } static int raw_mailbox_open(struct mailbox *box) @@ -71,7 +71,7 @@ int fd; if (box->input != NULL) - return index_storage_mailbox_open(box); + return index_storage_mailbox_open(box, FALSE); fd = open(box->path, O_RDONLY); if (fd == -1) { @@ -87,7 +87,7 @@ } box->input = i_stream_create_fd(fd, MAIL_READ_FULL_BLOCK_SIZE, TRUE); i_stream_set_init_buffer_size(box->input, MAIL_READ_FULL_BLOCK_SIZE); - return index_storage_mailbox_open(box); + return index_storage_mailbox_open(box, FALSE); } static int
--- a/src/lib-storage/index/raw/raw-storage.h Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/raw/raw-storage.h Sun Feb 07 17:30:24 2010 +0200 @@ -13,7 +13,7 @@ }; struct raw_mailbox { - struct index_mailbox ibox; + struct mailbox box; struct raw_storage *storage; time_t mtime, ctime;
--- a/src/lib-storage/index/raw/raw-sync.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/raw/raw-sync.c Sun Feb 07 17:30:24 2010 +0200 @@ -18,14 +18,14 @@ sync_flags = MAIL_INDEX_SYNC_FLAG_FLUSH_DIRTY | MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES; - if ((mbox->ibox.box.flags & MAILBOX_FLAG_KEEP_RECENT) == 0) + if ((mbox->box.flags & MAILBOX_FLAG_KEEP_RECENT) == 0) sync_flags |= MAIL_INDEX_SYNC_FLAG_DROP_RECENT; - ret = mail_index_sync_begin(mbox->ibox.box.index, &index_sync_ctx, + ret = mail_index_sync_begin(mbox->box.index, &index_sync_ctx, &sync_view, &trans, sync_flags); if (ret <= 0) { if (ret < 0) - mail_storage_set_index_error(&mbox->ibox.box); + mail_storage_set_index_error(&mbox->box); return ret; } @@ -36,10 +36,10 @@ /* add our one and only message */ mail_index_append(trans, 1, &seq); - index_mailbox_set_recent_uid(&mbox->ibox, 1); + index_mailbox_set_recent_uid(&mbox->box, 1); if (mail_index_sync_commit(&index_sync_ctx) < 0) { - mail_storage_set_index_error(&mbox->ibox.box); + mail_storage_set_index_error(&mbox->box); return -1; } mbox->synced = TRUE;
--- a/src/lib-storage/index/test-index-fetch.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/index/test-index-fetch.c Sun Feb 07 17:30:24 2010 +0200 @@ -87,19 +87,19 @@ static void test_index_storage_get_expunges(void) { - struct index_mailbox *ibox; + struct mailbox *box; ARRAY_TYPE(seq_range) uids_filter; ARRAY_TYPE(mailbox_expunge_rec) expunges; const struct mailbox_expunge_rec *exp; unsigned int i, count; uint64_t modseq; - ibox = t_new(struct index_mailbox, 1); - ibox->box.index = t_new(struct mail_index, 1); - ibox->box.view = t_new(struct mail_index_view, 1); + box = t_new(struct mailbox, 1); + box->index = t_new(struct mail_index, 1); + box->view = t_new(struct mail_index_view, 1); - ibox->box.view->log_file_head_seq = 101; - ibox->box.view->log_file_head_offset = 1024; + box->view->log_file_head_seq = 101; + box->view->log_file_head_offset = 1024; test_begin("index storage get expunges"); @@ -114,7 +114,7 @@ t_array_init(&expunges, 32); modseq = 98ULL << 32; for (i = 0; i < 2; i++) { - test_assert(index_storage_get_expunges(&ibox->box, modseq, &uids_filter, + test_assert(index_storage_get_expunges(box, modseq, &uids_filter, &expunges) == i); exp = array_get(&expunges, &count);
--- a/src/lib-storage/mail-storage-private.h Sun Feb 07 16:27:18 2010 +0200 +++ b/src/lib-storage/mail-storage-private.h Sun Feb 07 17:30:24 2010 +0200 @@ -253,6 +253,8 @@ unsigned int opened:1; /* Mailbox was deleted while we had it open. */ unsigned int mailbox_deleted:1; + /* we've discovered there aren't enough permissions to modify mailbox */ + unsigned int backend_readonly:1; }; struct mail_vfuncs {
--- a/src/plugins/virtual/virtual-config.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/plugins/virtual/virtual-config.c Sun Feb 07 17:30:24 2010 +0200 @@ -323,16 +323,16 @@ i_array_init(&mbox->backend_boxes, 8); mbox->search_args_crc32 = (uint32_t)-1; - path = t_strconcat(mbox->ibox.box.path, "/"VIRTUAL_CONFIG_FNAME, NULL); + path = t_strconcat(mbox->box.path, "/"VIRTUAL_CONFIG_FNAME, NULL); fd = open(path, O_RDONLY); if (fd == -1) { if (errno == ENOENT) { - mailbox_list_set_error(mbox->ibox.box.list, + mailbox_list_set_error(mbox->box.list, MAIL_ERROR_NOTPOSSIBLE, "Virtual mailbox missing configuration file"); return -1; } - mailbox_list_set_critical(mbox->ibox.box.list, + mailbox_list_set_critical(mbox->box.list, "open(%s) failed: %m", path); return -1; } @@ -340,7 +340,7 @@ memset(&ctx, 0, sizeof(ctx)); ctx.sep = mail_namespaces_get_root_sep(user->namespaces); ctx.mbox = mbox; - ctx.pool = mbox->ibox.box.pool; + ctx.pool = mbox->box.pool; ctx.rule = t_str_new(256); ctx.input = i_stream_create_fd(fd, (size_t)-1, FALSE); i_stream_set_return_partial_line(ctx.input, TRUE); @@ -353,7 +353,7 @@ else ret = virtual_config_parse_line(&ctx, line, &error); if (ret < 0) { - mailbox_list_set_critical(mbox->ibox.box.list, + mailbox_list_set_critical(mbox->box.list, "%s: Error at line %u: %s", path, linenum, error); break; @@ -362,7 +362,7 @@ if (ret == 0) { ret = virtual_config_add_rule(&ctx, &error); if (ret < 0) { - mailbox_list_set_critical(mbox->ibox.box.list, + mailbox_list_set_critical(mbox->box.list, "%s: Error at line %u: %s", path, linenum, error); } @@ -373,7 +373,7 @@ ret = virtual_config_expand_wildcards(&ctx); if (ret == 0 && array_count(&mbox->backend_boxes) == 0) { - mailbox_list_set_critical(mbox->ibox.box.list, + mailbox_list_set_critical(mbox->box.list, "%s: No mailboxes defined", path); ret = -1; }
--- a/src/plugins/virtual/virtual-mail.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/plugins/virtual/virtual-mail.c Sun Feb 07 17:30:24 2010 +0200 @@ -41,7 +41,7 @@ vmail->imail.data_pool = pool_alloconly_create("virtual index_mail", 512); - vmail->imail.ibox = &mbox->ibox; + vmail->imail.ibox = INDEX_STORAGE_CONTEXT(t->box); vmail->imail.trans = (struct index_transaction_context *)t; vmail->wanted_fields = wanted_fields;
--- a/src/plugins/virtual/virtual-search.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/plugins/virtual/virtual-search.c Sun Feb 07 17:30:24 2010 +0200 @@ -82,7 +82,7 @@ seq_range_array_add(&vctx->result, 0, ctx->seq); } else { /* possible match, save and check later */ - mail_index_lookup_ext(mbox->ibox.box.view, ctx->seq, + mail_index_lookup_ext(mbox->box.view, ctx->seq, mbox->virtual_ext_id, &data, &expunged); vrec = data;
--- a/src/plugins/virtual/virtual-storage.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/plugins/virtual/virtual-storage.c Sun Feb 07 17:30:24 2010 +0200 @@ -144,7 +144,7 @@ return 0; } /* copy the error */ - mail_storage_set_error(mbox->ibox.box.storage, error, + mail_storage_set_error(mbox->box.storage, error, t_strdup_printf("%s (%s)", str, mailbox)); return -1; } @@ -197,23 +197,23 @@ pool = pool_alloconly_create("virtual mailbox", 1024+512); mbox = p_new(pool, struct virtual_mailbox, 1); - mbox->ibox.box = virtual_mailbox; - mbox->ibox.box.pool = pool; - mbox->ibox.box.storage = _storage; - mbox->ibox.box.list = list; - mbox->ibox.box.mail_vfuncs = &virtual_mail_vfuncs; + mbox->box = virtual_mailbox; + mbox->box.pool = pool; + mbox->box.storage = _storage; + mbox->box.list = list; + mbox->box.mail_vfuncs = &virtual_mail_vfuncs; - index_storage_mailbox_alloc(&mbox->ibox, name, input, flags, + index_storage_mailbox_alloc(&mbox->box, name, input, flags, VIRTUAL_INDEX_PREFIX); mbox->storage = storage; mbox->vseq_lookup_prev_mailbox = i_strdup(""); mbox->virtual_ext_id = - mail_index_ext_register(mbox->ibox.box.index, "virtual", 0, + mail_index_ext_register(mbox->box.index, "virtual", 0, sizeof(struct virtual_mail_index_record), sizeof(uint32_t)); - return &mbox->ibox.box; + return &mbox->box; } static int virtual_mailbox_open(struct mailbox *box) @@ -255,7 +255,7 @@ virtual_mailboxes_open(mbox, box->flags) < 0; array_delete(&mbox->storage->open_stack, array_count(&mbox->storage->open_stack)-1, 1); - return failed ? -1 : index_storage_mailbox_open(box); + return failed ? -1 : index_storage_mailbox_open(box, FALSE); } static void virtual_mailbox_close(struct mailbox *box)
--- a/src/plugins/virtual/virtual-storage.h Sun Feb 07 16:27:18 2010 +0200 +++ b/src/plugins/virtual/virtual-storage.h Sun Feb 07 17:30:24 2010 +0200 @@ -99,7 +99,7 @@ ARRAY_DEFINE_TYPE(virtual_backend_box, struct virtual_backend_box *); struct virtual_mailbox { - struct index_mailbox ibox; + struct mailbox box; struct virtual_storage *storage; uint32_t virtual_ext_id;
--- a/src/plugins/virtual/virtual-sync.c Sun Feb 07 16:27:18 2010 +0200 +++ b/src/plugins/virtual/virtual-sync.c Sun Feb 07 17:30:24 2010 +0200 @@ -140,7 +140,7 @@ /* another process just added a new mailbox. we can't handle this currently. */ ctx->mbox->inconsistent = TRUE; - mail_storage_set_error(ctx->mbox->ibox.box.storage, MAIL_ERROR_TEMP, + mail_storage_set_error(ctx->mbox->box.storage, MAIL_ERROR_TEMP, "Backend mailbox added by another session. " "Reopen the virtual mailbox."); return -1; @@ -184,7 +184,7 @@ if (ext_name_offset >= ext_size || ext_hdr->mailbox_count > INT_MAX/sizeof(*mailboxes)) { i_error("virtual index %s: Broken mailbox_count header", - ctx->mbox->ibox.box.path); + ctx->mbox->box.path); ctx->index_broken = TRUE; ext_mailbox_count = 0; ret = 0; @@ -199,18 +199,18 @@ if (mailboxes[i].id > ext_hdr->highest_mailbox_id || mailboxes[i].id <= prev_mailbox_id) { i_error("virtual index %s: Broken mailbox id", - ctx->mbox->ibox.box.path); + ctx->mbox->box.path); break; } if (mailboxes[i].name_len == 0 || mailboxes[i].name_len > ext_size) { i_error("virtual index %s: Broken mailbox name_len", - ctx->mbox->ibox.box.path); + ctx->mbox->box.path); break; } if (ext_name_offset + mailboxes[i].name_len > ext_size) { i_error("virtual index %s: Broken mailbox list", - ctx->mbox->ibox.box.path); + ctx->mbox->box.path); break; } T_BEGIN { @@ -433,7 +433,7 @@ static void virtual_sync_index_finish(struct virtual_sync_context *ctx) { - struct mailbox *box = &ctx->mbox->ibox.box; + struct mailbox *box = &ctx->mbox->box; const struct mail_index_header *hdr; uint32_t seq1, seq2; @@ -446,7 +446,7 @@ /* mark the newly seen messages as recent */ if (mail_index_lookup_seq_range(ctx->sync_view, hdr->first_recent_uid, hdr->next_uid, &seq1, &seq2)) { - index_mailbox_set_recent_seq(&ctx->mbox->ibox, ctx->sync_view, + index_mailbox_set_recent_seq(&ctx->mbox->box, ctx->sync_view, seq1, seq2); } if (ctx->ext_header_rewrite) { @@ -1319,7 +1319,7 @@ vrec->mailbox_id); if (bbox == NULL) { mail_storage_set_critical( - ctx->mbox->ibox.box.storage, + ctx->mbox->box.storage, "Mailbox ID %u unexpectedly lost", vrec->mailbox_id); return -1; @@ -1352,7 +1352,7 @@ seq_range_array_iter_init(&iter, isync_ctx->expunges); while (seq_range_array_iter_nth(&iter, n++, &seq)) { - mail_index_lookup_ext(mbox->ibox.box.view, seq, + mail_index_lookup_ext(mbox->box.view, seq, mbox->virtual_ext_id, &data, &expunged); vrec = data; @@ -1380,7 +1380,7 @@ for (i = 0; i < count; i++) { if (virtual_sync_backend_box(ctx, bboxes[i]) < 0) { /* backend failed, copy the error */ - virtual_box_copy_error(&ctx->mbox->ibox.box, + virtual_box_copy_error(&ctx->mbox->box, bboxes[i]->box); return -1; } @@ -1414,7 +1414,7 @@ virtual_sync_backend_boxes_finish(ctx); if (success) { if (mail_index_sync_commit(&ctx->index_sync_ctx) < 0) { - mail_storage_set_index_error(&ctx->mbox->ibox.box); + mail_storage_set_index_error(&ctx->mbox->box); ret = -1; } } else { @@ -1424,7 +1424,7 @@ if (mail_index_unlink(ctx->index) < 0) { i_error("virtual index %s: Failed to unlink() " "broken indexes: %m", - ctx->mbox->ibox.box.path); + ctx->mbox->box.path); } } mail_index_sync_rollback(&ctx->index_sync_ctx); @@ -1443,7 +1443,7 @@ ctx = i_new(struct virtual_sync_context, 1); ctx->mbox = mbox; ctx->flags = flags; - ctx->index = mbox->ibox.box.index; + ctx->index = mbox->box.index; /* Removed messages are expunged when a) EXPUNGE is used b) Mailbox is being opened (FIX_INCONSISTENT is set) */ @@ -1453,7 +1453,7 @@ index_sync_flags = MAIL_INDEX_SYNC_FLAG_FLUSH_DIRTY | MAIL_INDEX_SYNC_FLAG_AVOID_FLAG_UPDATES; - if ((mbox->ibox.box.flags & MAILBOX_FLAG_KEEP_RECENT) == 0) + if ((mbox->box.flags & MAILBOX_FLAG_KEEP_RECENT) == 0) index_sync_flags |= MAIL_INDEX_SYNC_FLAG_DROP_RECENT; ret = mail_index_sync_begin(ctx->index, &ctx->index_sync_ctx, @@ -1461,7 +1461,7 @@ index_sync_flags); if (ret <= 0) { if (ret < 0) - mail_storage_set_index_error(&mbox->ibox.box); + mail_storage_set_index_error(&mbox->box); i_free(ctx); return ret; } @@ -1493,7 +1493,7 @@ ret = -1; } - if (index_mailbox_want_full_sync(&mbox->ibox, flags) && ret == 0) + if (index_mailbox_want_full_sync(&mbox->box, flags) && ret == 0) ret = virtual_sync(mbox, flags); sync_ctx = index_mailbox_sync_init(box, flags, ret < 0);