# HG changeset patch # User Timo Sirainen # Date 1239141272 14400 # Node ID 7d484e0f0789941af02f1d3f4d87788be967b67b # Parent 41508990561659cc580917aa8bacc69dd7d59599 Shared mailboxes: Find the final storage before calling mail_storage.mailbox_open(), not inside it. This fixes some crashes with plugins. diff -r 415089905616 -r 7d484e0f0789 src/lib-storage/index/shared/shared-list.c --- a/src/lib-storage/index/shared/shared-list.c Tue Apr 07 16:38:47 2009 -0400 +++ b/src/lib-storage/index/shared/shared-list.c Tue Apr 07 17:54:32 2009 -0400 @@ -42,6 +42,18 @@ mailbox_list_set_error(shared_list, error, str); } +static int +shared_get_storage(struct mailbox_list *list, const char *name, + struct mail_storage **storage_r) +{ + struct mail_namespace *ns; + + if (shared_storage_get_namespace(list->ns->storage, &name, &ns) < 0) + return -1; + *storage_r = ns->storage; + return 0; +} + static bool shared_is_valid_pattern(struct mailbox_list *list, const char *pattern) { @@ -292,6 +304,7 @@ { shared_list_alloc, shared_list_deinit, + shared_get_storage, shared_is_valid_pattern, shared_is_valid_existing_name, shared_is_valid_create_name, diff -r 415089905616 -r 7d484e0f0789 src/lib-storage/index/shared/shared-storage.c --- a/src/lib-storage/index/shared/shared-storage.c Tue Apr 07 16:38:47 2009 -0400 +++ b/src/lib-storage/index/shared/shared-storage.c Tue Apr 07 17:54:32 2009 -0400 @@ -274,33 +274,6 @@ mail_storage_set_error(shared_storage, error, str); } -static struct mailbox * -shared_mailbox_open(struct mail_storage *storage, const char *name, - struct istream *input, enum mailbox_open_flags flags) -{ - struct mail_namespace *ns; - struct mailbox *box; - - if (input != NULL) { - mail_storage_set_critical(storage, - "Shared storage doesn't support streamed mailboxes"); - return NULL; - } - - if (shared_storage_get_namespace(storage, &name, &ns) < 0) - return NULL; - - /* if we call the normal mailbox_open() here the plugins will see - mailbox_open() called twice and they could break. */ - box = ns->storage->storage_class->v. - mailbox_open(ns->storage, name, NULL, flags); - if (box == NULL) - shared_mailbox_copy_error(storage, ns); - else - ns->flags |= NAMESPACE_FLAG_USABLE; - return box; -} - static int shared_mailbox_create(struct mail_storage *storage, const char *name, bool directory) { @@ -327,7 +300,7 @@ shared_create, index_storage_destroy, NULL, - shared_mailbox_open, + NULL, shared_mailbox_create } }; diff -r 415089905616 -r 7d484e0f0789 src/lib-storage/list/mailbox-list-fs.c --- a/src/lib-storage/list/mailbox-list-fs.c Tue Apr 07 16:38:47 2009 -0400 +++ b/src/lib-storage/list/mailbox-list-fs.c Tue Apr 07 17:54:32 2009 -0400 @@ -370,6 +370,7 @@ { fs_list_alloc, fs_list_deinit, + NULL, fs_is_valid_pattern, fs_is_valid_existing_name, fs_is_valid_create_name, diff -r 415089905616 -r 7d484e0f0789 src/lib-storage/list/mailbox-list-maildir.c --- a/src/lib-storage/list/mailbox-list-maildir.c Tue Apr 07 16:38:47 2009 -0400 +++ b/src/lib-storage/list/mailbox-list-maildir.c Tue Apr 07 17:54:32 2009 -0400 @@ -444,6 +444,7 @@ { maildir_list_alloc, maildir_list_deinit, + NULL, maildir_is_valid_pattern, maildir_is_valid_existing_name, maildir_is_valid_create_name, @@ -471,6 +472,7 @@ { imapdir_list_alloc, maildir_list_deinit, + NULL, maildir_is_valid_pattern, maildir_is_valid_existing_name, maildir_is_valid_create_name, diff -r 415089905616 -r 7d484e0f0789 src/lib-storage/mail-storage.c --- a/src/lib-storage/mail-storage.c Tue Apr 07 16:38:47 2009 -0400 +++ b/src/lib-storage/mail-storage.c Tue Apr 07 17:54:32 2009 -0400 @@ -458,11 +458,18 @@ enum mailbox_open_flags flags) { struct mail_storage *storage = *_storage; + struct mailbox_list *list = storage->list; struct mailbox *box; + if (list->v.get_storage != NULL) { + if (list->v.get_storage(list, name, &storage) < 0) + return NULL; + *_storage = storage; + } + mail_storage_clear_error(storage); - if (!mailbox_list_is_valid_existing_name(storage->list, name)) { + if (!mailbox_list_is_valid_existing_name(list, name)) { mail_storage_set_error(storage, MAIL_ERROR_PARAMS, "Invalid mailbox name"); return NULL; @@ -473,9 +480,6 @@ if (hook_mailbox_opened != NULL && box != NULL) hook_mailbox_opened(box); } T_END; - - if (box != NULL) - *_storage = box->storage; return box; } diff -r 415089905616 -r 7d484e0f0789 src/lib-storage/mailbox-list-private.h --- a/src/lib-storage/mailbox-list-private.h Tue Apr 07 16:38:47 2009 -0400 +++ b/src/lib-storage/mailbox-list-private.h Tue Apr 07 17:54:32 2009 -0400 @@ -12,6 +12,8 @@ struct mailbox_list *(*alloc)(void); void (*deinit)(struct mailbox_list *list); + int (*get_storage)(struct mailbox_list *list, + const char *name, struct mail_storage **storage_r); bool (*is_valid_pattern)(struct mailbox_list *list, const char *pattern); bool (*is_valid_existing_name)(struct mailbox_list *list,