]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mailbox_open() now takes struct mail_storage ** so it can be changed.
authorTimo Sirainen <tss@iki.fi>
Fri, 21 Nov 2008 17:24:04 +0000 (19:24 +0200)
committerTimo Sirainen <tss@iki.fi>
Fri, 21 Nov 2008 17:24:04 +0000 (19:24 +0200)
--HG--
branch : HEAD

18 files changed:
src/deliver/deliver.c
src/imap/cmd-append.c
src/imap/cmd-copy.c
src/imap/cmd-select.c
src/imap/imap-status.c
src/lib-storage/mail-storage.c
src/lib-storage/mail-storage.h
src/plugins/convert/convert-storage.c
src/plugins/expire/expire-tool.c
src/plugins/imap-acl/imap-acl-plugin.c
src/plugins/imap-quota/imap-quota-plugin.c
src/plugins/lazy-expunge/lazy-expunge-plugin.c
src/plugins/mbox-snarf/mbox-snarf-plugin.c
src/plugins/quota/quota-count.c
src/plugins/quota/quota-storage.c
src/plugins/trash/trash-plugin.c
src/plugins/virtual/virtual-storage.c
src/pop3/client.c

index b097426cfde8b5ac2059624914a9a2705c6904a9..35924af00a2d4d90ed916b68c9b6f51ff6f4477e 100644 (file)
@@ -172,16 +172,16 @@ mailbox_open_or_create_synced(struct mail_namespace *namespaces,
                return NULL;
        }
 
-       box = mailbox_open(ns->storage, name, NULL, open_flags);
+       box = mailbox_open(storage_r, name, NULL, open_flags);
        if (box != NULL || !deliver_set->mailbox_autocreate)
                return box;
 
-       (void)mail_storage_get_last_error(ns->storage, &error);
+       (void)mail_storage_get_last_error(*storage_r, &error);
        if (error != MAIL_ERROR_NOTFOUND)
                return NULL;
 
        /* try creating it. */
-       if (mail_storage_mailbox_create(ns->storage, name, FALSE) < 0)
+       if (mail_storage_mailbox_create(*storage_r, name, FALSE) < 0)
                return NULL;
        if (deliver_set->mailbox_autosubscribe) {
                /* (try to) subscribe to it */
@@ -189,7 +189,7 @@ mailbox_open_or_create_synced(struct mail_namespace *namespaces,
        }
 
        /* and try opening again */
-       box = mailbox_open(ns->storage, name, NULL, open_flags);
+       box = mailbox_open(storage_r, name, NULL, open_flags);
        if (box == NULL)
                return NULL;
 
@@ -1082,12 +1082,12 @@ int main(int argc, char *argv[])
                i_fatal("Couldn't create internal raw storage: %s", errstr);
        if (path == NULL) {
                input = create_raw_stream(0, &mtime);
-               box = mailbox_open(raw_ns->storage, "Dovecot Delivery Mail",
+               box = mailbox_open(&raw_ns->storage, "Dovecot Delivery Mail",
                                   input, MAILBOX_OPEN_NO_INDEX_FILES);
                i_stream_unref(&input);
        } else {
                mtime = (time_t)-1;
-               box = mailbox_open(raw_ns->storage, path, NULL,
+               box = mailbox_open(&raw_ns->storage, path, NULL,
                                   MAILBOX_OPEN_NO_INDEX_FILES);
        }
        if (box == NULL)
index 84ffbf2adaa3c794b98a60598bca3d8207ebebf9..88ccf1194d62b6535b660fc710968036c3b5b837 100644 (file)
@@ -445,7 +445,7 @@ get_mailbox(struct client_command_context *cmd, const char *name)
            mailbox_equals(cmd->client->mailbox, storage, name))
                return cmd->client->mailbox;
 
-       box = mailbox_open(storage, name, NULL, MAILBOX_OPEN_SAVEONLY |
+       box = mailbox_open(&storage, name, NULL, MAILBOX_OPEN_SAVEONLY |
                           MAILBOX_OPEN_FAST | MAILBOX_OPEN_KEEP_RECENT);
        if (box == NULL) {
                client_send_storage_error(cmd, storage);
index 75ab657683586c50d9258885b9f1ee09aa819154..22c366e56d7b4782cb2ec0ae047013eccdf143bc 100644 (file)
@@ -121,7 +121,7 @@ bool cmd_copy(struct client_command_context *cmd)
        if (mailbox_equals(client->mailbox, storage, mailbox))
                destbox = client->mailbox;
        else {
-               destbox = mailbox_open(storage, mailbox, NULL,
+               destbox = mailbox_open(&storage, mailbox, NULL,
                                       MAILBOX_OPEN_SAVEONLY |
                                       MAILBOX_OPEN_FAST |
                                       MAILBOX_OPEN_KEEP_RECENT);
index 1e912f586c6cbc7746920f5c651cc479a23aae38..d3f2759813e510105f7690b57c58e7bbe43949c9 100644 (file)
@@ -264,7 +264,7 @@ select_open(struct imap_select_context *ctx, const char *mailbox, bool readonly)
 
        if (readonly)
                open_flags |= MAILBOX_OPEN_READONLY | MAILBOX_OPEN_KEEP_RECENT;
-       ctx->box = mailbox_open(ctx->storage, mailbox, NULL, open_flags);
+       ctx->box = mailbox_open(&ctx->storage, mailbox, NULL, open_flags);
        if (ctx->box == NULL)
                return -1;
 
index 04b8e2045fcb2b1d42db8172a06644bc39de12ea..e0636523840cb856b88ea8362acdb1e9d1700672 100644 (file)
@@ -61,7 +61,7 @@ bool imap_status_get(struct client *client, struct mail_storage *storage,
        }
 
        /* open the mailbox */
-       box = mailbox_open(storage, mailbox, NULL, MAILBOX_OPEN_FAST |
+       box = mailbox_open(&storage, mailbox, NULL, MAILBOX_OPEN_FAST |
                           MAILBOX_OPEN_READONLY | MAILBOX_OPEN_KEEP_RECENT);
        if (box == NULL)
                return FALSE;
index 121a92317d9d5bb8f5e9227000b1c9b8a5c68d60..c7b2029646a7603dda181fbf66d9f72f328d7e3d 100644 (file)
@@ -441,10 +441,11 @@ bool mail_storage_set_error_from_errno(struct mail_storage *storage)
        return TRUE;
 }
 
-struct mailbox *mailbox_open(struct mail_storage *storage, const char *name,
+struct mailbox *mailbox_open(struct mail_storage **_storage, const char *name,
                             struct istream *input,
                             enum mailbox_open_flags flags)
 {
+       struct mail_storage *storage = *_storage;
        struct mailbox *box;
 
        mail_storage_clear_error(storage);
@@ -460,6 +461,9 @@ struct mailbox *mailbox_open(struct mail_storage *storage, const char *name,
                if (hook_mailbox_opened != NULL && box != NULL)
                        hook_mailbox_opened(box);
        } T_END;
+
+       if (box != NULL)
+               *_storage = box->storage;
        return box;
 }
 
index af1f0f33a25ee3017f0f94ef353ace0839ecd0c8..13e8c39bf0567d683883901c23d4d573c1c802ee 100644 (file)
@@ -305,8 +305,11 @@ const char *mail_storage_get_mailbox_index_dir(struct mail_storage *storage,
    tried to be used, NULL is returned.
 
    Note that append and copy may open the selected mailbox again
-   with possibly different readonly-state. */
-struct mailbox *mailbox_open(struct mail_storage *storage, const char *name,
+   with possibly different readonly-state.
+
+   Given storage is a pointer-to-pointer because it may change as a result of
+   a new namespace being created for shared mailboxes. */
+struct mailbox *mailbox_open(struct mail_storage **storage, const char *name,
                             struct istream *input,
                             enum mailbox_open_flags flags);
 /* Close the box. Returns -1 if some cleanup errors occurred, but
index cfc3b10eb8969b1223fb1fdda9919cc7f13ee63a..f44587bcecdb3e72953e7f60062dd23320b74338 100644 (file)
@@ -282,7 +282,7 @@ static int mailbox_convert_list_item(struct mail_storage *source_storage,
 
        /* First open the source mailbox. If we can't open it, don't create
           the destination mailbox either. */
-       srcbox = mailbox_open(source_storage, name, NULL,
+       srcbox = mailbox_open(&source_storage, name, NULL,
                              MAILBOX_OPEN_READONLY | MAILBOX_OPEN_KEEP_RECENT);
        if (srcbox == NULL) {
                if (set->skip_broken_mailboxes)
@@ -306,7 +306,7 @@ static int mailbox_convert_list_item(struct mail_storage *source_storage,
                }
        }
 
-       destbox = mailbox_open(dest_storage, dest_name, NULL,
+       destbox = mailbox_open(&dest_storage, dest_name, NULL,
                               MAILBOX_OPEN_KEEP_RECENT);
        if (destbox == NULL) {
                i_error("Mailbox conversion: Couldn't open dest mailbox %s: %s",
index 43d9753fb5af3c46edbec5e71aaa0facbe34839d..98963e0b6f40ec25b18d6ef2022c0ef4462d2818 100644 (file)
@@ -64,6 +64,7 @@ mailbox_delete_old_mails(struct expire_context *ctx, const char *user,
                         time_t *oldest_r)
 {
        struct mail_namespace *ns;
+       struct mail_storage *storage;
        struct mailbox *box;
        struct mail_search_context *search_ctx;
        struct mailbox_transaction_context *t;
@@ -97,9 +98,10 @@ mailbox_delete_old_mails(struct expire_context *ctx, const char *user,
                return 0;
        }
 
-       box = mailbox_open(ns->storage, ns_mailbox, NULL, 0);
+       storage = ns->storage;
+       box = mailbox_open(&storage, ns_mailbox, NULL, 0);
        if (box == NULL) {
-               errstr = mail_storage_get_last_error(ns->storage, &error);
+               errstr = mail_storage_get_last_error(storage, &error);
                if (error != MAIL_ERROR_NOTFOUND) {
                        i_error("%s: Opening mailbox %s failed: %s",
                                user, mailbox, errstr);
index 0912de480d0ef52e7235c2c1e1e8da92424f2d43..901d917bdc9ee43158cfa6fc197b21be8a466303 100644 (file)
@@ -61,7 +61,7 @@ acl_mailbox_open_as_admin(struct client_command_context *cmd, const char *name)
 
        /* Force opening the mailbox so that we can give a nicer error message
           if mailbox isn't selectable but is listable. */
-       box = mailbox_open(storage, name, NULL, ACL_MAILBOX_OPEN_FLAGS |
+       box = mailbox_open(&storage, name, NULL, ACL_MAILBOX_OPEN_FLAGS |
                           MAILBOX_OPEN_IGNORE_ACLS);
        if (box == NULL) {
                client_send_storage_error(cmd, storage);
@@ -232,8 +232,8 @@ static bool cmd_myrights(struct client_command_context *cmd)
        if (storage == NULL)
                return TRUE;
 
-       box = mailbox_open(storage, real_mailbox, NULL, ACL_MAILBOX_OPEN_FLAGS |
-                          MAILBOX_OPEN_IGNORE_ACLS);
+       box = mailbox_open(&storage, real_mailbox, NULL,
+                          ACL_MAILBOX_OPEN_FLAGS | MAILBOX_OPEN_IGNORE_ACLS);
        if (box == NULL) {
                client_send_storage_error(cmd, storage);
                return TRUE;
index edfa43a6ca9e83cfe5dc93ad5cbde4e3e5ecea29..287a15932a101dbaeca0a7f1f430cd4285aa4e8c 100644 (file)
@@ -63,9 +63,9 @@ static bool cmd_getquotaroot(struct client_command_context *cmd)
        if (storage == NULL)
                return TRUE;
 
-       box = mailbox_open(storage, mailbox, NULL, (MAILBOX_OPEN_READONLY |
-                                                   MAILBOX_OPEN_FAST |
-                                                   MAILBOX_OPEN_KEEP_RECENT));
+       box = mailbox_open(&storage, mailbox, NULL, (MAILBOX_OPEN_READONLY |
+                                                    MAILBOX_OPEN_FAST |
+                                                    MAILBOX_OPEN_KEEP_RECENT));
        if (box == NULL) {
                client_send_storage_error(cmd, storage);
                return TRUE;
index f9ba60f449114b614228d026ed3774712cb769db..8096c13bbd7af09642b5a0438dd7d1810cb86711 100644 (file)
@@ -82,7 +82,7 @@ mailbox_open_or_create(struct mail_storage *storage, const char *name)
        struct mailbox *box;
        enum mail_error error;
 
-       box = mailbox_open(storage, name, NULL, MAILBOX_OPEN_FAST |
+       box = mailbox_open(&storage, name, NULL, MAILBOX_OPEN_FAST |
                           MAILBOX_OPEN_KEEP_RECENT |
                           MAILBOX_OPEN_NO_INDEX_FILES);
        if (box != NULL)
@@ -97,7 +97,7 @@ mailbox_open_or_create(struct mail_storage *storage, const char *name)
                return NULL;
 
        /* and try opening again */
-       box = mailbox_open(storage, name, NULL, MAILBOX_OPEN_FAST |
+       box = mailbox_open(&storage, name, NULL, MAILBOX_OPEN_FAST |
                           MAILBOX_OPEN_KEEP_RECENT);
        return box;
 }
index 8ceffa7add5f31bd2afd90d8a60c7c7004563996..a851e0f6b44fa30529a9cf19aac6403f42dd93ff 100644 (file)
@@ -100,13 +100,15 @@ mbox_snarf_sync_init(struct mailbox *box, enum mailbox_sync_flags flags)
 {
        struct mbox_snarf_mail_storage *mstorage =
                MBOX_SNARF_CONTEXT(box->storage);
+       struct mail_storage *storage;
        struct mbox_snarf_mailbox *mbox = MBOX_SNARF_CONTEXT(box);
 
        if (mbox->spool_mbox == NULL) {
                /* try to open the spool mbox */
                mstorage->open_spool_inbox = TRUE;
+               storage = box->storage;
                mbox->spool_mbox =
-                       mailbox_open(box->storage, "INBOX", NULL,
+                       mailbox_open(&storage, "INBOX", NULL,
                                     MAILBOX_OPEN_KEEP_RECENT |
                                     MAILBOX_OPEN_NO_INDEX_FILES);
                mstorage->open_spool_inbox = FALSE;
index bf2cdfc43d88d2ab5d738fc5638b93562ac2e3a5..a1b04747f8a5759d37f967e192ad4569e563d1e3 100644 (file)
@@ -25,7 +25,7 @@ quota_count_mailbox(struct quota_root *root, struct mail_storage *storage,
                return 0;
        }
 
-       box = mailbox_open(storage, name, NULL,
+       box = mailbox_open(&storage, name, NULL,
                           MAILBOX_OPEN_READONLY | MAILBOX_OPEN_KEEP_RECENT);
        if (box == NULL)
                return -1;
index d4723646d876e0f4a8a126ed89c7484b7b961f15..db4ae82d0904aec634a9ec4dff0afbb34f4948cf 100644 (file)
@@ -433,6 +433,7 @@ static int
 quota_mailbox_list_delete(struct mailbox_list *list, const char *name)
 {
        struct quota_mailbox_list *qlist = QUOTA_LIST_CONTEXT(list);
+       struct mail_storage *storage;
        struct mailbox *box;
        enum mail_error error;
        const char *str;
@@ -442,7 +443,8 @@ quota_mailbox_list_delete(struct mailbox_list *list, const char *name)
           and free the quota for all the messages existing in it. Open the
           mailbox locked so that other processes can't mess up the quota
           calculations by adding/removing mails while we're doing this. */
-       box = mailbox_open(qlist->storage, name, NULL, MAILBOX_OPEN_FAST |
+       storage = qlist->storage;
+       box = mailbox_open(&storage, name, NULL, MAILBOX_OPEN_FAST |
                           MAILBOX_OPEN_KEEP_RECENT | MAILBOX_OPEN_KEEP_LOCKED);
        if (box == NULL) {
                str = mail_storage_get_last_error(qlist->storage, &error);
index 12585b129ba3dbe612d9d09dc54754e24d150660..2870f0755f695f96504dbf505b783bf5d3680c1d 100644 (file)
@@ -52,9 +52,10 @@ static int (*trash_next_quota_test_alloc)(struct quota_transaction_context *,
 
 static int trash_clean_mailbox_open(struct trash_mailbox *trash)
 {
+       struct mail_storage *storage = trash->storage;
        struct mail_search_args *search_args;
 
-       trash->box = mailbox_open(trash->storage, trash->name, NULL,
+       trash->box = mailbox_open(&storage, trash->name, NULL,
                                  MAILBOX_OPEN_KEEP_RECENT);
        if (trash->box == NULL)
                return 0;
index 9aa68a5bbd3ac1d27aac3a5a5542ae818d65203b..13444b91c2a581ba7a174206cc5d5da3acb1b1f4 100644 (file)
@@ -200,6 +200,7 @@ static int virtual_mailboxes_open(struct virtual_mailbox *mbox,
        struct mail_user *user = mbox->storage->storage.ns->user;
        struct virtual_backend_box *const *bboxes;
        struct mail_namespace *ns;
+       struct mail_storage *storage;
        unsigned int i, count;
        enum mail_error error;
        const char *str, *mailbox;
@@ -210,13 +211,14 @@ static int virtual_mailboxes_open(struct virtual_mailbox *mbox,
        for (i = 0; i < count; i++) {
                mailbox = bboxes[i]->name;
                ns = mail_namespace_find(user->namespaces, &mailbox);
-               bboxes[i]->box = mailbox_open(ns->storage, mailbox,
+               storage = ns->storage;
+               bboxes[i]->box = mailbox_open(&storage, mailbox,
                                              NULL, open_flags);
 
                if (bboxes[i]->box == NULL) {
-                       if (ns->storage != mbox->ibox.box.storage) {
+                       if (storage != mbox->ibox.box.storage) {
                                /* copy the error */
-                               str = mail_storage_get_last_error(ns->storage,
+                               str = mail_storage_get_last_error(storage,
                                                                  &error);
                                mail_storage_set_error(mbox->ibox.box.storage,
                                                       error, str);
index fd7683e22747a28086a50ef5869293a935c06aca..9eea8628a1ec105d8b36d5757ac410780a0e8527 100644 (file)
@@ -180,7 +180,7 @@ struct client *client_create(int fd_in, int fd_out, struct mail_user *user)
                flags |= MAILBOX_OPEN_KEEP_RECENT;
        if (lock_session)
                flags |= MAILBOX_OPEN_KEEP_LOCKED;
-       client->mailbox = mailbox_open(storage, "INBOX", NULL, flags);
+       client->mailbox = mailbox_open(&storage, "INBOX", NULL, flags);
        if (client->mailbox == NULL) {
                errmsg = t_strdup_printf("Couldn't open INBOX: %s",
                                mail_storage_get_last_error(storage,