const char *virtual_plugin_version = DOVECOT_ABI_VERSION;
+static struct mail_storage_hooks acl_mail_storage_hooks = {
+ .mailbox_opened = virtual_mailbox_opened_hook
+};
+
void virtual_plugin_init(struct module *module ATTR_UNUSED)
{
mail_storage_class_register(&virtual_storage);
+ mail_storage_hooks_add(module, &acl_mail_storage_hooks);
}
void virtual_plugin_deinit(void)
{
mail_storage_class_unregister(&virtual_storage);
+ mail_storage_hooks_remove(&acl_mail_storage_hooks);
}
mailbox = bbox->name;
ns = mail_namespace_find(user->namespaces, mailbox);
bbox->box = mailbox_alloc(ns->list, mailbox, flags);
+ MODULE_CONTEXT_SET(bbox->box, virtual_storage_module, bbox);
if (mailbox_exists(bbox->box, TRUE, &existence) < 0)
return virtual_backend_box_open_failed(mbox, bbox);
return FALSE;
}
-void virtual_backend_box_opened(struct virtual_mailbox *mbox,
- struct virtual_backend_box *bbox)
+void virtual_mailbox_opened_hook(struct mailbox *box)
{
+ struct virtual_backend_box *bbox = VIRTUAL_CONTEXT(box);
+ struct virtual_mailbox *mbox;
+
+ if (bbox == NULL) {
+ /* not a backend for a virtual mailbox */
+ return;
+ }
i_assert(!bbox->open_tracked);
+ mbox = bbox->virtual_mbox;
/* the backend mailbox was already opened. if we didn't get here
from virtual_backend_box_open() we may need to close a mailbox */
virtual_backend_box_close_any_except(mbox, bbox))
;
- if (mailbox_open(bbox->box) < 0)
- return -1;
- virtual_backend_box_opened(mbox, bbox);
- return 0;
+ return mailbox_open(bbox->box);
}
void virtual_backend_box_close(struct virtual_mailbox *mbox,
struct virtual_backend_box *bbox)
{
i_assert(bbox->box->opened);
+ i_assert(bbox->open_tracked);
if (bbox->search_result != NULL)
mailbox_search_result_free(&bbox->search_result);
mail_search_args_deinit(bbox->search_args);
bbox->search_args_initialized = FALSE;
}
- if (bbox->open_tracked) {
- i_assert(mbox->backends_open_count > 0);
- mbox->backends_open_count--;
- bbox->open_tracked = FALSE;
-
- DLLIST2_REMOVE_FULL(&mbox->open_backend_boxes_head,
- &mbox->open_backend_boxes_tail, bbox,
- prev_open, next_open);
- } else {
- /* mailbox can be leaked outside our code via
- virtual_get_virtual_backend_boxes() and it could have
- been opened there. FIXME: maybe we could hook into the
- backend open/close functions to do the tracking and
- auto-closing. */
- }
+ i_assert(mbox->backends_open_count > 0);
+ mbox->backends_open_count--;
+ bbox->open_tracked = FALSE;
+
+ DLLIST2_REMOVE_FULL(&mbox->open_backend_boxes_head,
+ &mbox->open_backend_boxes_tail, bbox,
+ prev_open, next_open);
mailbox_close(bbox->box);
}
};
struct virtual_backend_box {
+ union mailbox_module_context module_ctx;
+ struct virtual_mailbox *virtual_mbox;
+
/* linked list for virtual_mailbox->open_backend_boxes_{head,tail} */
struct virtual_backend_box *prev_open, *next_open;
struct virtual_backend_box *bbox);
void virtual_backend_box_accessed(struct virtual_mailbox *mbox,
struct virtual_backend_box *bbox);
-void virtual_backend_box_opened(struct virtual_mailbox *mbox,
- struct virtual_backend_box *bbox);
void virtual_backend_box_sync_mail_unset(struct virtual_backend_box *bbox);
struct mail_search_context *
void virtual_box_copy_error(struct mailbox *dest, struct mailbox *src);
+void virtual_mailbox_opened_hook(struct mailbox *box);
+
#endif
bbox->open_failed = FALSE;
}
- ret = mailbox_get_status(bbox->box, STATUS_UIDVALIDITY |
- STATUS_UIDNEXT | STATUS_HIGHESTMODSEQ,
- &status);
- if (!bbox_index_opened && bbox->box->opened)
- virtual_backend_box_opened(ctx->mbox, bbox);
- if (ret < 0) {
+ if (mailbox_get_status(bbox->box, STATUS_UIDVALIDITY |
+ STATUS_UIDNEXT | STATUS_HIGHESTMODSEQ,
+ &status) < 0) {
if (mailbox_get_last_mail_error(bbox->box) != MAIL_ERROR_NOTFOUND)
return -1;
/* mailbox was deleted */