Lines Matching refs:box

64 static void index_cache_register_defaults(struct mailbox *box)
66 struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box);
67 const struct mail_storage_settings *set = box->storage->set;
68 struct mail_cache *cache = box->cache;
78 box->mail_cache_disabled = TRUE;
95 void index_storage_lock_notify(struct mailbox *box,
99 struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box);
100 struct mail_storage *storage = box->storage;
130 notify_no(box, str, storage->callback_context);
139 notify_ok(box, str, storage->callback_context);
144 void index_storage_lock_notify_reset(struct mailbox *box)
146 struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box);
153 index_mailbox_alloc_index(struct mailbox *box, struct mail_index **index_r)
157 if (mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_MAILBOX,
160 if ((box->flags & MAILBOX_FLAG_NO_INDEX_FILES) != 0 ||
161 mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX,
164 *index_r = mail_index_alloc_cache_get(box->storage->user->event,
166 box->index_prefix);
170 int index_storage_mailbox_exists(struct mailbox *box,
174 return index_storage_mailbox_exists_full(box, NULL, existence_r);
177 int index_storage_mailbox_exists_full(struct mailbox *box, const char *subdir,
186 ret = mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_MAILBOX, &path);
188 mailbox_list_get_last_error(box->list, &error);
200 ret = (subdir != NULL || !box->list->set.iter_from_index_dir) ? 0 :
201 mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX, &index_path);
207 index_path = t_strconcat(index_path, "/", box->index_prefix,
222 mailbox_set_critical(box, "stat(%s) failed: %m", path);
227 if (mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_DIR, &path2) <= 0 ||
236 int index_storage_mailbox_alloc_index(struct mailbox *box)
240 if (box->index != NULL)
243 if (mailbox_create_missing_dir(box, MAILBOX_LIST_PATH_TYPE_INDEX) < 0)
245 if (index_mailbox_alloc_index(box, &box->index) < 0)
248 if (mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX_CACHE,
250 if (mailbox_create_missing_dir(box, MAILBOX_LIST_PATH_TYPE_INDEX_CACHE) < 0)
252 mail_index_set_cache_dir(box->index, cache_dir);
254 mail_index_set_lock_method(box->index,
255 box->storage->set->parsed_lock_method,
256 mail_storage_get_lock_timeout(box->storage, UINT_MAX));
258 const struct mail_storage_settings *set = box->storage->set;
279 mail_index_set_optimization_settings(box->index, &optimization_set);
283 int index_storage_mailbox_open(struct mailbox *box, bool move_to_memory)
285 struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box);
289 i_assert(!box->opened);
295 if (index_storage_mailbox_alloc_index(box) < 0)
299 (void)mailbox_get_permissions(box);
301 ret = mail_index_open(box->index, index_flags);
305 mailbox_set_index_error(box);
309 if (mail_index_move_to_memory(box->index) < 0) {
312 if (mail_index_open_or_create(box->index,
318 if (mail_index_is_in_memory(box->index)) {
319 mailbox_set_critical(box,
321 mail_index_close(box->index);
326 if ((box->flags & MAILBOX_FLAG_OPEN_DELETED) == 0) {
327 if (mail_index_is_deleted(box->index)) {
328 mailbox_set_deleted(box);
329 mail_index_close(box->index);
334 box->cache = mail_index_get_cache(box->index);
335 index_cache_register_defaults(box);
336 box->view = mail_index_view_open(box->index);
337 ibox->keyword_names = mail_index_get_keywords(box->index);
338 box->vsize_hdr_ext_id =
339 mail_index_ext_register(box->index, "hdr-vsize",
342 box->pop3_uidl_hdr_ext_id =
343 mail_index_ext_register(box->index, "hdr-pop3-uidl",
345 box->box_name_hdr_ext_id =
346 mail_index_ext_register(box->index, "box-name", 0, 0, 0);
348 box->box_last_rename_stamp_ext_id =
349 mail_index_ext_register(box->index, "last-rename-stamp",
351 box->mail_vsize_ext_id = mail_index_ext_register(box->index, "vsize", 0,
355 box->opened = TRUE;
357 if ((box->enabled_features & MAILBOX_FEATURE_CONDSTORE) != 0)
358 mail_index_modseq_enable(box->index);
360 index_thread_mailbox_opened(box);
361 hook_mailbox_opened(box);
365 void index_storage_mailbox_alloc(struct mailbox *box, const char *vname,
374 box->generation_sequence = ++mailbox_generation_sequence;
375 box->vname = p_strdup(box->pool, vname);
376 box->name = p_strdup(box->pool,
377 mailbox_list_get_storage_name(box->list, vname));
378 box->flags = flags;
379 box->index_prefix = p_strdup(box->pool, index_prefix);
380 box->event = event_create(box->storage->user->event);
381 event_add_category(box->event, &event_category_mailbox);
382 event_add_str(box->event, "name", box->vname);
383 event_set_append_log_prefix(box->event,
384 t_strdup_printf("Mailbox %s: ", box->vname));
386 p_array_init(&box->search_results, box->pool, 16);
387 array_create(&box->module_contexts,
388 box->pool, sizeof(void *), 5);
390 ibox = p_new(box->pool, struct index_mailbox_context, 1);
393 mail_storage_settings_to_index_flags(box->storage->set);
394 if ((box->flags & MAILBOX_FLAG_SAVEONLY) != 0)
396 if (box->storage->user->mail_debug)
399 MODULE_CONTEXT_SET(box, index_storage_module, ibox);
401 box->inbox_user = strcmp(box->name, "INBOX") == 0 &&
402 (box->list->ns->flags & NAMESPACE_FLAG_INBOX_USER) != 0;
403 box->inbox_any = strcmp(box->name, "INBOX") == 0 &&
404 (box->list->ns->flags & NAMESPACE_FLAG_INBOX_ANY) != 0;
407 int index_storage_mailbox_enable(struct mailbox *box,
411 box->enabled_features |= MAILBOX_FEATURE_CONDSTORE;
412 if (box->opened)
413 mail_index_modseq_enable(box->index);
418 void index_storage_mailbox_close(struct mailbox *box)
420 struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box);
422 mailbox_watch_remove_all(box);
423 i_stream_unref(&box->input);
425 if (box->view_pvt != NULL)
426 mail_index_view_close(&box->view_pvt);
427 if (box->index_pvt != NULL)
428 mail_index_close(box->index_pvt);
429 if (box->view != NULL) {
430 mail_index_view_close(&box->view);
431 mail_index_close(box->index);
433 box->cache = NULL;
441 static void index_storage_mailbox_unref_indexes(struct mailbox *box)
443 if (box->index_pvt != NULL)
444 mail_index_alloc_cache_unref(&box->index_pvt);
445 if (box->index != NULL)
446 mail_index_alloc_cache_unref(&box->index);
449 void index_storage_mailbox_free(struct mailbox *box)
451 index_storage_mailbox_unref_indexes(box);
452 event_unref(&box->event);
456 index_storage_mailbox_update_cache(struct mailbox *box,
465 old_fields = mail_cache_register_get_list(box->cache,
495 mail_cache_register_fields(box->cache,
502 index_storage_mailbox_update_pvt(struct mailbox *box,
509 if ((ret = mailbox_open_index_pvt(box)) <= 0)
512 mail_index_refresh(box->index_pvt);
513 view = mail_index_view_open(box->index_pvt);
518 mail_index_modseq_enable(box->index_pvt);
524 mailbox_set_index_error(box);
529 int index_storage_mailbox_update_common(struct mailbox *box,
535 index_storage_mailbox_update_cache(box, update);
538 if (index_storage_mailbox_update_pvt(box, update) < 0)
544 int index_storage_mailbox_update(struct mailbox *box,
552 if (mailbox_open(box) < 0)
556 mail_index_refresh(box->index);
557 view = mail_index_view_open(box->index);
592 mail_index_modseq_enable(box->index);
598 mailbox_set_index_error(box);
601 index_storage_mailbox_update_common(box, update);
604 int index_storage_mailbox_create(struct mailbox *box, bool directory)
612 if ((box->list->props & MAILBOX_LIST_PROP_NO_NOSELECT) != 0) {
620 if ((ret = mailbox_get_path_to(box, type, &path)) < 0)
624 mail_storage_set_error(box->storage, MAIL_ERROR_NOTPOSSIBLE,
629 (box->list->flags & MAILBOX_LIST_FLAG_MAILBOX_FILES) != 0;
638 if ((ret = mailbox_mkdir(box, path, type)) < 0)
640 if (box->list->set.iter_from_index_dir) {
645 if (mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX, &path) <= 0)
647 if ((ret2 = mailbox_mkdir(box, path, type)) < 0)
655 mailbox_refresh_permissions(box);
660 if (!directory && *box->list->set.mailbox_dir_name == '\0') {
664 if (mailbox_exists(box, FALSE, &existence) < 0)
669 mail_storage_set_error(box->storage, MAIL_ERROR_EXISTS,
682 int index_storage_mailbox_delete_dir(struct mailbox *box, bool mailbox_deleted)
687 if (mailbox_list_delete_dir(box->list, box->name) == 0)
690 mailbox_list_get_last_error(box->list, &error);
692 mail_storage_copy_list_error(box->storage, box->list);
698 mailbox_name_get_sha128(box->vname, dir_sha128);
699 mailbox_list_add_change(box->list, MAILBOX_LOG_RECORD_DELETE_DIR,
711 bool inbox = t->box->inbox_any;
713 iter = mailbox_attribute_iter_init(t->box, type, "");
721 if (mailbox_get_last_mail_error(t->box) != MAIL_ERROR_NOTPOSSIBLE) {
732 static int mailbox_expunge_all_data(struct mailbox *box)
739 (void)mailbox_sync(box, MAILBOX_SYNC_FLAG_FULL_READ);
741 t = mailbox_transaction_begin(box, 0, __func__);
764 return mailbox_sync(box, 0);
767 int index_storage_mailbox_delete_pre(struct mailbox *box)
771 if (!box->opened) {
773 if (index_storage_mailbox_delete_dir(box, FALSE) == 0)
775 if (mailbox_is_autocreated(box)) {
784 if ((box->list->flags & MAILBOX_LIST_FLAG_MAILBOX_FILES) == 0) {
788 if (mailbox_list_delete_symlink(box->list, box->name) == 0)
800 if (!box->deleting_must_be_empty) {
801 if (mailbox_expunge_all_data(box) < 0)
804 if (mailbox_mark_index_deleted(box, TRUE) < 0)
807 if (!box->delete_skip_empty_check || box->deleting_must_be_empty) {
808 if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FULL_READ) < 0)
810 mailbox_get_open_status(box, STATUS_MESSAGES, &status);
813 else if (box->deleting_must_be_empty) {
814 mail_storage_set_error(box->storage, MAIL_ERROR_EXISTS,
818 mail_storage_set_error(box->storage, MAIL_ERROR_EXISTS,
826 int index_storage_mailbox_delete_post(struct mailbox *box)
831 ret_guid = mailbox_get_metadata(box, MAILBOX_METADATA_GUID, &metadata);
837 mailbox_close(box);
838 index_storage_mailbox_unref_indexes(box);
841 if (box->list->v.delete_mailbox(box->list, box->name) < 0) {
842 mail_storage_copy_list_error(box->storage, box->list);
847 mailbox_list_add_change(box->list,
851 if (index_storage_mailbox_delete_dir(box, TRUE) < 0) {
852 if (mailbox_get_last_mail_error(box) != MAIL_ERROR_EXISTS)
860 int index_storage_mailbox_delete(struct mailbox *box)
864 if ((ret = index_storage_mailbox_delete_pre(box)) <= 0)
870 return index_storage_mailbox_delete_post(box);
903 int index_mailbox_update_last_temp_file_scan(struct mailbox *box)
907 mail_index_transaction_begin(box->view,
913 mailbox_set_index_error(box);
919 bool index_storage_is_readonly(struct mailbox *box)
921 return (box->flags & MAILBOX_FLAG_READONLY) != 0;
924 bool index_storage_is_inconsistent(struct mailbox *box)
926 return box->view != NULL &&
927 mail_index_view_is_inconsistent(box->view);
952 src_field_idx = mail_cache_register_lookup(src_mail->box->cache, name);
955 dest_field_idx = mail_cache_register_lookup(dest_trans->box->cache, name);
960 dest_field = mail_cache_register_get_field(dest_trans->box->cache,
1018 ctx->transaction->box->mail_vsize_ext_id,
1023 ctx->transaction->box->mail_vsize_ext_id,
1036 if (mailbox_get_metadata(src_mail->box,
1043 if (mailbox_get_metadata(ctx->transaction->box,
1057 int index_storage_set_subscribed(struct mailbox *box, bool set)
1060 struct mailbox_list *list = box->list;
1065 subs_name = box->name;
1070 box->vname);
1072 mail_storage_set_error(box->storage, MAIL_ERROR_NOTPOSSIBLE,
1078 subs_name = t_strconcat(list->ns->prefix, box->name, NULL);
1086 mail_storage_copy_list_error(box->storage, list);
1094 mailbox_name_get_sha128(box->vname, guid);
1108 static void index_storage_expunging_init(struct mailbox *box)
1110 struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box);
1115 ibox->vsize_update = index_mailbox_vsize_update_init(box);
1121 void index_storage_expunging_deinit(struct mailbox *box)
1123 struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box);
1129 static bool index_storage_expunging_want_updates(struct mailbox *box)
1131 struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box);
1136 ibox->vsize_update = index_mailbox_vsize_update_init(box);
1142 int index_storage_expunged_sync_begin(struct mailbox *box,
1148 struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box);
1153 if (mail_index_sync_have_any_expunges(box->index))
1154 index_storage_expunging_init(box);
1156 ret = mail_index_sync_begin(box->index, ctx_r, view_r,
1160 mailbox_set_index_error(box);
1161 index_storage_expunging_deinit(box);
1166 index_storage_expunging_want_updates(box)) {
1170 index_storage_expunging_deinit(box);
1171 return index_storage_expunged_sync_begin(box, ctx_r, view_r,
1181 struct mail_storage *storage = ctx->transaction->box->storage;
1234 int index_mailbox_fix_inconsistent_existence(struct mailbox *box,
1246 if (mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX,
1254 return mailbox_mkdir(box, path, MAILBOX_LIST_PATH_TYPE_MAILBOX);
1258 mailbox_set_critical(box, "stat(%s) failed: %m", index_path);
1261 mailbox_set_deleted(box);