]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
authorTimo Sirainen <tss@iki.fi>
Fri, 12 Feb 2010 21:27:16 +0000 (23:27 +0200)
committerTimo Sirainen <tss@iki.fi>
Fri, 12 Feb 2010 21:27:16 +0000 (23:27 +0200)
--HG--
branch : HEAD

40 files changed:
src/doveadm/doveadm-mail.c
src/dsync/dsync-worker-local.c
src/imap/cmd-append.c
src/imap/cmd-copy.c
src/imap/cmd-create.c
src/imap/cmd-delete.c
src/imap/cmd-select.c
src/imap/imap-status.c
src/lda/main.c
src/lib-lda/mail-deliver.c
src/lib-storage/index/cydir/cydir-storage.c
src/lib-storage/index/dbox-common/dbox-storage.c
src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c
src/lib-storage/index/dbox-multi/mdbox-storage.c
src/lib-storage/index/dbox-multi/mdbox-storage.h
src/lib-storage/index/dbox-single/sdbox-storage.c
src/lib-storage/index/dbox-single/sdbox-storage.h
src/lib-storage/index/index-storage.c
src/lib-storage/index/index-storage.h
src/lib-storage/index/maildir/maildir-storage.c
src/lib-storage/index/mbox/mbox-storage.c
src/lib-storage/index/raw/raw-storage.c
src/lib-storage/mail-storage-private.h
src/lib-storage/mail-storage.c
src/lib-storage/mail-storage.h
src/lib-storage/test-mail-storage.h
src/lib-storage/test-mailbox.c
src/lmtp/commands.c
src/plugins/autocreate/autocreate-plugin.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/listescape/listescape-plugin.c
src/plugins/mbox-snarf/mbox-snarf-plugin.c
src/plugins/quota/quota-count.c
src/plugins/trash/trash-plugin.c
src/plugins/virtual/virtual-storage.c
src/plugins/zlib/zlib-plugin.c
src/pop3/pop3-client.c

index 703aec2df582ea68cc6d9ae7fa7bf4cc5015fa14..1fc5b6e22d198a2febce2a73ff389ab3d2ed1f70 100644 (file)
@@ -46,7 +46,7 @@ mailbox_find_and_open(struct mail_user *user, const char *mailbox)
        if (ns == NULL)
                i_fatal("Can't find namespace for mailbox %s", mailbox);
 
-       box = mailbox_alloc(ns->list, mailbox, NULL, MAILBOX_FLAG_KEEP_RECENT |
+       box = mailbox_alloc(ns->list, mailbox, MAILBOX_FLAG_KEEP_RECENT |
                            MAILBOX_FLAG_IGNORE_ACLS);
        if (mailbox_open(box) < 0) {
                i_fatal("Opening mailbox %s failed: %s", orig_mailbox,
index 97f3327811960ec56a8ea2578faf54761ebe209a..a2d010d5d690a8613e3c4793d9920c1f037b55e1 100644 (file)
@@ -505,7 +505,7 @@ local_worker_mailbox_iter_next(struct dsync_worker_mailbox_iter *_iter,
                return 1;
        }
 
-       box = mailbox_alloc(info->ns->list, storage_name, NULL, flags);
+       box = mailbox_alloc(info->ns->list, storage_name, flags);
        if (mailbox_sync(box, 0) < 0 ||
            mailbox_get_guid(box, mailbox_guid) < 0) {
                struct mail_storage *storage = mailbox_get_storage(box);
@@ -700,7 +700,7 @@ static int local_mailbox_open(struct local_dsync_worker *worker,
                return -1;
        }
 
-       box = mailbox_alloc(lbox->ns->list, lbox->storage_name, NULL, flags);
+       box = mailbox_alloc(lbox->ns->list, lbox->storage_name, flags);
        if (mailbox_sync(box, 0) < 0 ||
            mailbox_get_guid(box, mailbox_guid) < 0) {
                struct mail_storage *storage = mailbox_get_storage(box);
@@ -1003,8 +1003,7 @@ local_worker_mailbox_alloc(struct local_dsync_worker *worker,
                                 &dsync_box->mailbox_guid);
        if (lbox != NULL) {
                /* use the existing known mailbox name */
-               return mailbox_alloc(lbox->ns->list, lbox->storage_name,
-                                    NULL, 0);
+               return mailbox_alloc(lbox->ns->list, lbox->storage_name, 0);
        }
 
        name = dsync_box->name;
@@ -1018,7 +1017,7 @@ local_worker_mailbox_alloc(struct local_dsync_worker *worker,
                                                 dsync_box, creating);
        local_dsync_worker_add_mailbox(worker, ns, name,
                                       &dsync_box->mailbox_guid);
-       return mailbox_alloc(ns->list, name, NULL, 0);
+       return mailbox_alloc(ns->list, name, 0);
 }
 
 static int
@@ -1091,7 +1090,7 @@ local_worker_create_mailbox(struct dsync_worker *_worker,
 
        local_dsync_worker_add_mailbox(worker, ns, new_name,
                                       &dsync_box->mailbox_guid);
-       box = mailbox_alloc(ns->list, new_name, NULL, 0);
+       box = mailbox_alloc(ns->list, new_name, 0);
        (void)local_worker_create_allocated_mailbox(worker, box, dsync_box);
        mailbox_free(&box);
 }
@@ -1116,7 +1115,7 @@ local_worker_delete_mailbox(struct dsync_worker *_worker,
 
        mailbox_list_set_changelog_timestamp(lbox->ns->list,
                                             dsync_box->last_change);
-       box = mailbox_alloc(lbox->ns->list, lbox->storage_name, NULL, 0);
+       box = mailbox_alloc(lbox->ns->list, lbox->storage_name, 0);
        if (mailbox_delete(box) < 0) {
                struct mail_storage *storage = mailbox_get_storage(box);
 
index 199a6db4d94a054ed517e9d1a28d545185a6f117..075b675b4b8446c7bfd74d6ee2d6aaf95ecdaee1 100644 (file)
@@ -464,7 +464,7 @@ get_mailbox(struct client_command_context *cmd, const char *name)
            mailbox_equals(cmd->client->mailbox, ns, name))
                return cmd->client->mailbox;
 
-       box = mailbox_alloc(ns->list, name, NULL, MAILBOX_FLAG_SAVEONLY |
+       box = mailbox_alloc(ns->list, name, MAILBOX_FLAG_SAVEONLY |
                            MAILBOX_FLAG_KEEP_RECENT);
        if (mailbox_open(box) < 0) {
                client_send_storage_error(cmd, mailbox_get_storage(box));
index e56beadcd03344db308d4fb716f98d06e0065f55..34182878bbf5a17c636b4709c4b3e9b70e495eda 100644 (file)
@@ -118,7 +118,7 @@ bool cmd_copy(struct client_command_context *cmd)
        if (mailbox_equals(client->mailbox, dest_ns, mailbox))
                destbox = client->mailbox;
        else {
-               destbox = mailbox_alloc(dest_ns->list, mailbox, NULL,
+               destbox = mailbox_alloc(dest_ns->list, mailbox,
                                        MAILBOX_FLAG_SAVEONLY |
                                        MAILBOX_FLAG_KEEP_RECENT);
                if (mailbox_open(destbox) < 0) {
index d047c0bc543a11ec4fe25f77012da77cd1fba939..27602ad16aee5a77bb8e222484b9975bb3ea5d60 100644 (file)
@@ -44,7 +44,7 @@ bool cmd_create(struct client_command_context *cmd)
        if (ns == NULL)
                return TRUE;
 
-       box = mailbox_alloc(ns->list, mailbox, NULL, 0);
+       box = mailbox_alloc(ns->list, mailbox, 0);
        if (mailbox_create(box, NULL, directory) < 0)
                client_send_storage_error(cmd, mailbox_get_storage(box));
        else
index 666c9c60b67044fdb0d90b09f3fcb784839f1b59..661538445c0414a8006201c0521e0d783b1cd356 100644 (file)
@@ -25,7 +25,7 @@ bool cmd_delete(struct client_command_context *cmd)
        if (ns == NULL)
                return TRUE;
 
-       box = mailbox_alloc(ns->list, name, NULL, 0);
+       box = mailbox_alloc(ns->list, name, 0);
        if (client->mailbox != NULL &&
            mailbox_backends_equal(box, client->mailbox)) {
                /* deleting selected mailbox. close it first */
index b53fda776e6d7ee1dd68961ccf09e3df01d36eaa..583c4f1ac7f6b6151382e1a23a35ab93f25fe6f9 100644 (file)
@@ -267,7 +267,7 @@ select_open(struct imap_select_context *ctx, const char *mailbox, bool readonly)
 
        if (readonly)
                flags |= MAILBOX_FLAG_READONLY | MAILBOX_FLAG_KEEP_RECENT;
-       ctx->box = mailbox_alloc(ctx->ns->list, mailbox, NULL, flags);
+       ctx->box = mailbox_alloc(ctx->ns->list, mailbox, flags);
        if (mailbox_open(ctx->box) < 0) {
                client_send_storage_error(ctx->cmd,
                                          mailbox_get_storage(ctx->box));
index 414b1075001d5801d16c3747d060bb43df673ad2..496ce037f6809f3ae53d63a48774d310fd11b85d 100644 (file)
@@ -66,7 +66,7 @@ int imap_status_get(struct client_command_context *cmd,
                box = client->mailbox;
        } else {
                /* open the mailbox */
-               box = mailbox_alloc(ns->list, mailbox, NULL,
+               box = mailbox_alloc(ns->list, mailbox,
                                    MAILBOX_FLAG_READONLY |
                                    MAILBOX_FLAG_KEEP_RECENT);
                if (client->enabled_features != 0)
index 07dc0b7efe24dbce722b301fd9c21c714178d0d5..5b01ebd52fd215dfbe0dd035967e3ecaa3452005 100644 (file)
@@ -405,16 +405,20 @@ int main(int argc, char *argv[])
        if (path == NULL) {
                input = create_raw_stream(&ctx, 0, &mtime);
                box = mailbox_alloc(raw_ns->list, "Dovecot Delivery Mail",
-                                   input, MAILBOX_FLAG_NO_INDEX_FILES);
+                                   MAILBOX_FLAG_NO_INDEX_FILES);
+               if (mailbox_open_stream(box, input) < 0) {
+                       i_fatal("Can't open delivery mail as raw: %s",
+                               mail_storage_get_last_error(box->storage, &error));
+               }
                i_stream_unref(&input);
        } else {
                mtime = (time_t)-1;
-               box = mailbox_alloc(raw_ns->list, path, NULL,
+               box = mailbox_alloc(raw_ns->list, path,
                                    MAILBOX_FLAG_NO_INDEX_FILES);
-       }
-       if (mailbox_open(box) < 0) {
-               i_fatal("Can't open delivery mail as raw: %s",
-                       mail_storage_get_last_error(box->storage, &error));
+               if (mailbox_open(box) < 0) {
+                       i_fatal("Can't open delivery mail as raw: %s",
+                               mail_storage_get_last_error(box->storage, &error));
+               }
        }
        if (mailbox_sync(box, 0) < 0) {
                i_fatal("Can't sync delivery mail: %s",
index 59f312a60c4e46bc90bd4c1ae8a7176f119d45bc..3197a4621c13cc3a9aeb3df7065f6edcda5d6134 100644 (file)
@@ -106,7 +106,7 @@ mailbox_open_or_create_synced(struct mail_deliver_context *ctx,
                return NULL;
        }
 
-       box = mailbox_alloc(ns->list, name, NULL, flags);
+       box = mailbox_alloc(ns->list, name, flags);
        if (mailbox_open(box) == 0)
                return box;
 
index 02a3b7770c77d60c36f8d9d04362b8f576a7db77..8f44c35ba95029502dcb51a0c1cfeddceb227164 100644 (file)
@@ -35,8 +35,7 @@ cydir_storage_get_list_settings(const struct mail_namespace *ns ATTR_UNUSED,
 
 static struct mailbox *
 cydir_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
-                   const char *name, struct istream *input,
-                   enum mailbox_flags flags)
+                   const char *name, enum mailbox_flags flags)
 {
        struct cydir_mailbox *mbox;
        struct index_mailbox_context *ibox;
@@ -53,7 +52,7 @@ cydir_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
        mbox->box.list = list;
        mbox->box.mail_vfuncs = &cydir_mail_vfuncs;
 
-       index_storage_mailbox_alloc(&mbox->box, name, input, flags,
+       index_storage_mailbox_alloc(&mbox->box, name, flags,
                                    CYDIR_INDEX_PREFIX);
        mail_index_set_fsync_types(mbox->box.index,
                                   MAIL_INDEX_SYNC_TYPE_APPEND |
@@ -72,12 +71,6 @@ static int cydir_mailbox_open(struct mailbox *box)
 {
        struct stat st;
 
-       if (box->input != NULL) {
-               mail_storage_set_critical(box->storage,
-                       "cydir doesn't support streamed mailboxes");
-               return -1;
-       }
-
        if (stat(box->path, &st) == 0) {
                /* exists, open it */
        } else if (errno == ENOENT && strcmp(box->name, "INBOX") == 0) {
index 6c394d12e98a7fc7e2e04245d24fe898a83d0807..7567240b46c17af739ebf7d6522b134e0f188147 100644 (file)
@@ -98,12 +98,6 @@ static int dbox_mailbox_create_indexes(struct mailbox *box,
 
 int dbox_mailbox_open(struct mailbox *box)
 {
-       if (box->input != NULL) {
-               mail_storage_set_critical(box->storage,
-                       "dbox doesn't support streamed mailboxes");
-               return -1;
-       }
-
        if (dbox_cleanup_if_exists(box->list, box->path)) {
                return index_storage_mailbox_open(box, FALSE);
        } else if (errno == ENOENT) {
index 18d7da57cd331456c265426ddeddfaa99ec9e086..15ecc2d70e2c5fdd141945d10927c2d5900b34fa 100644 (file)
@@ -406,8 +406,7 @@ rebuild_mailbox(struct mdbox_storage_rebuild_context *ctx,
        int ret;
 
        box = mdbox_mailbox_alloc(&ctx->storage->storage.storage,
-                                 ns->list, name, NULL,
-                                 MAILBOX_FLAG_READONLY |
+                                 ns->list, name, MAILBOX_FLAG_READONLY |
                                  MAILBOX_FLAG_KEEP_RECENT |
                                  MAILBOX_FLAG_IGNORE_ACLS);
        if (dbox_mailbox_open(box) < 0) {
@@ -543,8 +542,7 @@ static int rebuild_restore_msg(struct mdbox_storage_rebuild_context *ctx,
                ctx->prev_msg.box : NULL;
        while (box == NULL) {
                box = mdbox_mailbox_alloc(storage, ctx->default_list,
-                                         mailbox, NULL,
-                                         MAILBOX_FLAG_READONLY |
+                                         mailbox, MAILBOX_FLAG_READONLY |
                                          MAILBOX_FLAG_KEEP_RECENT |
                                          MAILBOX_FLAG_IGNORE_ACLS);
                if (dbox_mailbox_open(box) == 0)
index 34071c49c3a2e728b56b5b2e22a03e6e608cc4b9..6856be4bee2d273478795b316bd7b2f6629e910b 100644 (file)
@@ -88,8 +88,7 @@ static void mdbox_storage_destroy(struct mail_storage *_storage)
 
 struct mailbox *
 mdbox_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
-                   const char *name, struct istream *input,
-                   enum mailbox_flags flags)
+                   const char *name, enum mailbox_flags flags)
 {
        struct mdbox_mailbox *mbox;
        struct index_mailbox_context *ibox;
@@ -106,8 +105,7 @@ mdbox_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
        mbox->box.list = list;
        mbox->box.mail_vfuncs = &mdbox_mail_vfuncs;
 
-       index_storage_mailbox_alloc(&mbox->box, name, input, flags,
-                                   DBOX_INDEX_PREFIX);
+       index_storage_mailbox_alloc(&mbox->box, name, flags, DBOX_INDEX_PREFIX);
        mail_index_set_fsync_types(mbox->box.index,
                                   MAIL_INDEX_SYNC_TYPE_APPEND |
                                   MAIL_INDEX_SYNC_TYPE_EXPUNGE);
index cf071122170ca7ed2d5b7fb027f2ddff60a36186..ce21077bbe4215e45637cb9595f5f708a5eb907e 100644 (file)
@@ -51,8 +51,7 @@ extern struct mail_vfuncs mdbox_mail_vfuncs;
 
 struct mailbox *
 mdbox_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
-                   const char *name, struct istream *input,
-                   enum mailbox_flags flags);
+                   const char *name, enum mailbox_flags flags);
 
 int mdbox_mail_open(struct dbox_mail *mail, uoff_t *offset_r,
                    struct dbox_file **file_r);
index 45760f1755d14001422a8d57e4cd61b765471006..3e022744a1ce969cbefc0f0c6e83faeb7fb7ef4a 100644 (file)
@@ -35,10 +35,9 @@ static struct mail_storage *sdbox_storage_alloc(void)
        return &storage->storage.storage;
 }
 
-struct mailbox *
+static struct mailbox *
 sdbox_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
-                   const char *name, struct istream *input,
-                   enum mailbox_flags flags)
+                   const char *name, enum mailbox_flags flags)
 {
        struct sdbox_mailbox *mbox;
        struct index_mailbox_context *ibox;
@@ -55,8 +54,7 @@ sdbox_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
        mbox->box.list = list;
        mbox->box.mail_vfuncs = &sdbox_mail_vfuncs;
 
-       index_storage_mailbox_alloc(&mbox->box, name, input, flags,
-                                   DBOX_INDEX_PREFIX);
+       index_storage_mailbox_alloc(&mbox->box, name, flags, DBOX_INDEX_PREFIX);
        mail_index_set_fsync_types(mbox->box.index,
                                   MAIL_INDEX_SYNC_TYPE_APPEND |
                                   MAIL_INDEX_SYNC_TYPE_EXPUNGE);
index 08467e8328a68cbed24a81ac1eee59c032f9a711..ae671e4bf1ef5a820472a2cf2d6f08f49ca4b429 100644 (file)
@@ -36,11 +36,6 @@ struct sdbox_mailbox {
 
 extern struct mail_vfuncs sdbox_mail_vfuncs;
 
-struct mailbox *
-sdbox_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
-                   const char *name, struct istream *input,
-                   enum mailbox_flags flags);
-
 int sdbox_mail_open(struct dbox_mail *mail, uoff_t *offset_r,
                    struct dbox_file **file_r);
 
index f6c82df566f59daca87b92f5eaed80dafacf47af..d800dd95feaf7bd30fff586569335e47f9f4a4f7 100644 (file)
@@ -257,7 +257,6 @@ int index_storage_mailbox_open(struct mailbox *box, bool move_to_memory)
 }
 
 void index_storage_mailbox_alloc(struct mailbox *box, const char *name,
-                                struct istream *input,
                                 enum mailbox_flags flags,
                                 const char *index_prefix)
 {
@@ -265,22 +264,12 @@ void index_storage_mailbox_alloc(struct mailbox *box, const char *name,
        const char *path;
        string_t *vname;
 
-       if (name != NULL) {
-               box->name = p_strdup(box->pool, name);
-               vname = t_str_new(128);
-               mail_namespace_get_vname(box->list->ns, vname, name);
-               box->vname = p_strdup(box->pool, str_c(vname));
-       } else {
-               i_assert(input != NULL);
-               box->name = "(read-only input stream)";
-               box->vname = box->name;
-       }
+       i_assert(name != NULL);
 
-       if (input != NULL) {
-               flags |= MAILBOX_FLAG_READONLY;
-               box->input = input;
-               i_stream_ref(input);
-       }
+       box->name = p_strdup(box->pool, name);
+       vname = t_str_new(128);
+       mail_namespace_get_vname(box->list->ns, vname, name);
+       box->vname = p_strdup(box->pool, str_c(vname));
        box->flags = flags;
 
        p_array_init(&box->search_results, box->pool, 16);
index ccc9969453cf87b77695120eb88eeacc220b092c..a22bc9a31d7a991b332bc2ad6a988a5a7db9aec8 100644 (file)
@@ -67,7 +67,6 @@ void index_storage_lock_notify(struct mailbox *box,
 void index_storage_lock_notify_reset(struct mailbox *box);
 
 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, bool move_to_memory);
index 8ceb83f52d3c88c94ae4606619067f421466e698..49669c56f9511dd4f06aad4ea1f942b6109814ed 100644 (file)
@@ -318,8 +318,7 @@ static void maildir_lock_touch_timeout(struct maildir_mailbox *mbox)
 
 static struct mailbox *
 maildir_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
-                     const char *name, struct istream *input,
-                     enum mailbox_flags flags)
+                     const char *name, enum mailbox_flags flags)
 {
        struct maildir_mailbox *mbox;
        struct index_mailbox_context *ibox;
@@ -333,7 +332,7 @@ maildir_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
        mbox->box.list = list;
        mbox->box.mail_vfuncs = &maildir_mail_vfuncs;
 
-       index_storage_mailbox_alloc(&mbox->box, name, input, flags,
+       index_storage_mailbox_alloc(&mbox->box, name, flags,
                                    MAILDIR_INDEX_PREFIX);
 
        ibox = INDEX_STORAGE_CONTEXT(&mbox->box);
@@ -380,12 +379,6 @@ static int maildir_mailbox_open(struct mailbox *box)
        int ret;
        bool inbox;
 
-       if (box->input != NULL) {
-               mail_storage_set_critical(box->storage,
-                       "Maildir doesn't support streamed mailboxes");
-               return -1;
-       }
-
        inbox = strcmp(box->name, "INBOX") == 0 &&
                (box->list->ns->flags & NAMESPACE_FLAG_INBOX) != 0;
 
index 91726317cdbe50f86b6f04506961880f36e50611..56e8a148e56e6008df25515d9e7504e09d371405 100644 (file)
@@ -327,8 +327,7 @@ static bool want_memory_indexes(struct mbox_storage *storage, const char *path)
 
 static struct mailbox *
 mbox_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
-                  const char *name, struct istream *input,
-                  enum mailbox_flags flags)
+                  const char *name, enum mailbox_flags flags)
 {
        struct mbox_mailbox *mbox;
        struct index_mailbox_context *ibox;
@@ -342,8 +341,7 @@ mbox_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
        mbox->box.list = list;
        mbox->box.mail_vfuncs = &mbox_mail_vfuncs;
 
-       index_storage_mailbox_alloc(&mbox->box, name, input, flags,
-                                   MBOX_INDEX_PREFIX);
+       index_storage_mailbox_alloc(&mbox->box, name, flags, MBOX_INDEX_PREFIX);
 
        ibox = INDEX_STORAGE_CONTEXT(&mbox->box);
        ibox->save_commit_pre = mbox_transaction_save_commit_pre;
@@ -454,10 +452,11 @@ static int mbox_mailbox_open(struct mailbox *box)
        int ret;
 
        if (box->input != NULL) {
+               i_stream_ref(box->input);
                mbox->mbox_file_stream = box->input;
                mbox->box.backend_readonly = TRUE;
                mbox->no_mbox_file = TRUE;
-               return 0;
+               return index_storage_mailbox_open(box, FALSE);
        }
 
        if (strcmp(box->name, "INBOX") == 0 &&
@@ -767,7 +766,8 @@ mbox_transaction_rollback(struct mailbox_transaction_context *t)
 
 struct mail_storage mbox_storage = {
        .name = MBOX_STORAGE_NAME,
-       .class_flags = MAIL_STORAGE_CLASS_FLAG_MAILBOX_IS_FILE,
+       .class_flags = MAIL_STORAGE_CLASS_FLAG_MAILBOX_IS_FILE |
+               MAIL_STORAGE_CLASS_FLAG_OPEN_STREAMS,
 
        .v = {
                 mbox_get_setting_parser_info,
index eaed115d0a4247b0d6f5c6897533b36d2fe77d2a..ad8d25ab683c54c005a92cc7d6e1fa8b58826d83 100644 (file)
@@ -35,8 +35,7 @@ raw_storage_get_list_settings(const struct mail_namespace *ns ATTR_UNUSED,
 
 static struct mailbox *
 raw_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
-                 const char *name, struct istream *input,
-                 enum mailbox_flags flags)
+                 const char *name, enum mailbox_flags flags)
 {
        struct raw_mailbox *mbox;
        pool_t pool;
@@ -51,27 +50,25 @@ raw_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
        mbox->box.list = list;
        mbox->box.mail_vfuncs = &raw_mail_vfuncs;
 
-       index_storage_mailbox_alloc(&mbox->box, name, input, flags, NULL);
+       index_storage_mailbox_alloc(&mbox->box, name, flags, NULL);
 
+       mbox->mtime = mbox->ctime = (time_t)-1;
        mbox->storage = (struct raw_storage *)storage;
-
-       if (input != NULL)
-               mbox->mtime = mbox->ctime = ioloop_time;
-       else {
-               mbox->mtime = mbox->ctime = (time_t)-1;
-               mbox->have_filename = TRUE;
-       }
        mbox->size = (uoff_t)-1;
        return &mbox->box;
 }
 
 static int raw_mailbox_open(struct mailbox *box)
 {
+       struct raw_mailbox *mbox = (struct raw_mailbox *)box;
        int fd;
 
-       if (box->input != NULL)
+       if (box->input != NULL) {
+               mbox->mtime = mbox->ctime = ioloop_time;
                return index_storage_mailbox_open(box, FALSE);
+       }
 
+       mbox->have_filename = TRUE;
        fd = open(box->path, O_RDONLY);
        if (fd == -1) {
                if (ENOTFOUND(errno)) {
@@ -162,7 +159,8 @@ static void raw_storage_add_list(struct mail_storage *storage ATTR_UNUSED,
 
 struct mail_storage raw_storage = {
        .name = RAW_STORAGE_NAME,
-       .class_flags = MAIL_STORAGE_CLASS_FLAG_MAILBOX_IS_FILE,
+       .class_flags = MAIL_STORAGE_CLASS_FLAG_MAILBOX_IS_FILE |
+               MAIL_STORAGE_CLASS_FLAG_OPEN_STREAMS,
 
        .v = {
                NULL,
index 0f1514d224a95512fd825e4012c5647476da4865..3528ba99fb6ad2ae2033e96e1c86538c3547a5be 100644 (file)
@@ -39,7 +39,6 @@ struct mail_storage_vfuncs {
        struct mailbox *(*mailbox_alloc)(struct mail_storage *storage,
                                         struct mailbox_list *list,
                                         const char *name,
-                                        struct istream *input,
                                         enum mailbox_flags flags);
        int (*purge)(struct mail_storage *storage);
 };
@@ -53,7 +52,9 @@ enum mail_storage_class_flags {
        /* mailboxes are files, not directories */
        MAIL_STORAGE_CLASS_FLAG_MAILBOX_IS_FILE = 0x01,
        /* root_dir points to a unique directory */
-       MAIL_STORAGE_CLASS_FLAG_UNIQUE_ROOT     = 0x02
+       MAIL_STORAGE_CLASS_FLAG_UNIQUE_ROOT     = 0x02,
+       /* mailbox_open_stream() is supported */
+       MAIL_STORAGE_CLASS_FLAG_OPEN_STREAMS    = 0x04
 };
 
 struct mail_storage {
index 3efc10507be855e2517200c23020e863ed6be616..c99e3b28abf72d2dc8541e7a82c0b829df31d033 100644 (file)
@@ -4,6 +4,7 @@
 #include "ioloop.h"
 #include "array.h"
 #include "llist.h"
+#include "istream.h"
 #include "eacces-error.h"
 #include "mkdir-parents.h"
 #include "var-expand.h"
@@ -475,7 +476,6 @@ bool mail_storage_set_error_from_errno(struct mail_storage *storage)
 }
 
 struct mailbox *mailbox_alloc(struct mailbox_list *list, const char *name,
-                             struct istream *input,
                              enum mailbox_flags flags)
 {
        struct mailbox_list *new_list = list;
@@ -488,14 +488,13 @@ struct mailbox *mailbox_alloc(struct mailbox_list *list, const char *name,
        }
 
        T_BEGIN {
-               box = storage->v.mailbox_alloc(storage, new_list,
-                                              name, input, flags);
+               box = storage->v.mailbox_alloc(storage, new_list, name, flags);
                hook_mailbox_allocated(box);
        } T_END;
        return box;
 }
 
-int mailbox_open(struct mailbox *box)
+static int mailbox_open_full(struct mailbox *box, struct istream *input)
 {
        int ret;
 
@@ -508,17 +507,41 @@ int mailbox_open(struct mailbox *box)
                return -1;
        }
 
+       if (input != NULL) {
+               if ((box->storage->class_flags &
+                    MAIL_STORAGE_CLASS_FLAG_OPEN_STREAMS) == 0) {
+                       mail_storage_set_critical(box->storage,
+                               "Storage doesn't support streamed mailboxes");
+                       return -1;
+               }
+               box->input = input;
+               box->flags |= MAILBOX_FLAG_READONLY;
+               i_stream_ref(box->input);
+       }
+
        T_BEGIN {
                ret = box->v.open(box);
        } T_END;
 
-       if (ret < 0)
+       if (ret < 0) {
+               i_stream_unref(&box->input);
                return -1;
+       }
 
        box->list->ns->flags |= NAMESPACE_FLAG_USABLE;
        return 0;
 }
 
+int mailbox_open(struct mailbox *box)
+{
+       return mailbox_open_full(box, NULL);
+}
+
+int mailbox_open_stream(struct mailbox *box, struct istream *input)
+{
+       return mailbox_open_full(box, input);
+}
+
 int mailbox_enable(struct mailbox *box, enum mailbox_feature features)
 {
        return box->v.enable(box, features);
index 07e8f10870a74e796803814e7841aa76df205f59..f67c11da33d92a96a49c61cb0084d3233aa4a719 100644 (file)
@@ -320,16 +320,15 @@ const char *mail_storage_get_last_error(struct mail_storage *storage,
 bool mail_storage_is_mailbox_file(struct mail_storage *storage) ATTR_PURE;
 
 /* Initialize mailbox without actually opening any files or verifying that
-   it exists. If input stream is given, mailbox is opened read-only
-   using it as a backend.
-
-   Note that append and copy may open the selected mailbox again
+   it exists. Note that append and copy may open the selected mailbox again
    with possibly different readonly-state. */
 struct mailbox *mailbox_alloc(struct mailbox_list *list, const char *name,
-                             struct istream *input, enum mailbox_flags flags);
+                             enum mailbox_flags flags);
 /* Open the mailbox. If this function isn't called explicitly, it's also called
    internally by lib-storage when necessary. */
 int mailbox_open(struct mailbox *box);
+/* Open mailbox as read-only using the given stream as input. */
+int mailbox_open_stream(struct mailbox *box, struct istream *input);
 /* Close mailbox. Same as if mailbox was freed and re-allocated. */
 void mailbox_close(struct mailbox *box);
 /* Close and free the mailbox. */
index 77d9d4dc1dc345aaa792b3ea79f9156dcd6dec2f..22057c23796c9392f8d63f5d98a97af6d09e9a06 100644 (file)
@@ -5,8 +5,7 @@ struct mail_storage *test_mail_storage_create(void);
 
 struct mailbox *
 test_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
-                  const char *name, struct istream *input,
-                  enum mailbox_flags flags);
+                  const char *name, enum mailbox_flags flags);
 
 struct mail *
 test_mailbox_mail_alloc(struct mailbox_transaction_context *t,
index e130901940e39ab9c4732ea197934531ad1ee05a..6cd18663bb39224dfc03c1a45fc8ad25e6c3b251 100644 (file)
@@ -359,8 +359,7 @@ struct mailbox test_mailbox = {
 
 struct mailbox *
 test_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
-                  const char *name, struct istream *input ATTR_UNUSED,
-                  enum mailbox_flags flags)
+                  const char *name, enum mailbox_flags flags)
 {
        struct mailbox *box;
        pool_t pool;
index 636bbaf5061c938b5223cf6ce3ec4b6653ab4188..ac89d4ae5bfac25cc5065ccab89b8cb8613a7058 100644 (file)
@@ -580,9 +580,10 @@ static int client_open_raw_mail(struct client *client, struct istream *input)
 
        client->state.raw_box = box =
                mailbox_alloc(client->raw_mail_user->namespaces->list,
-                             "Dovecot Delivery Mail", input,
+                             "Dovecot Delivery Mail",
                              MAILBOX_FLAG_NO_INDEX_FILES);
-       if (mailbox_sync(box, 0) < 0) {
+       if (mailbox_open_stream(box, input) < 0 ||
+           mailbox_sync(box, 0) < 0) {
                i_error("Can't open delivery mail as raw: %s",
                        mail_storage_get_last_error(box->storage, &error));
                mailbox_free(&box);
index bc2f5d57330d797d0d16b2b78a0fa987687f4bed..17de7a0ce475ad2a408c65eae80dd1276ace69ab 100644 (file)
@@ -25,7 +25,7 @@ autocreate_mailbox(struct mail_namespace *namespaces, const char *name)
                return;
        }
 
-       box = mailbox_alloc(ns->list, name, NULL, 0);
+       box = mailbox_alloc(ns->list, name, 0);
        if (mailbox_create(box, NULL, FALSE) < 0) {
                str = mail_storage_get_last_error(mailbox_get_storage(box),
                                                  &error);
index a65507f322bf66e073dacb9e4bca3f5a3e74585b..59241f6a138995633e0418839b6b3e316565182b 100644 (file)
@@ -105,7 +105,7 @@ mailbox_delete_old_mails(struct expire_context *ctx, const char *user,
                return 0;
        }
 
-       box = mailbox_alloc(ns->list, ns_mailbox, NULL, 0);
+       box = mailbox_alloc(ns->list, ns_mailbox, 0);
        if (mailbox_open(box) < 0) {
                errstr = mail_storage_get_last_error(mailbox_get_storage(box),
                                                     &error);
index 73bf91f1d3fc165e85848d7e20b79cc72b2bdf0c..1002d4057debeebeb285e538cc2c4398d7099acd 100644 (file)
@@ -70,7 +70,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_alloc(ns->list, name, NULL, ACL_MAILBOX_FLAGS |
+       box = mailbox_alloc(ns->list, name, ACL_MAILBOX_FLAGS |
                            MAILBOX_FLAG_IGNORE_ACLS);
        ret = acl_mailbox_right_lookup(box, ACL_STORAGE_RIGHT_ADMIN);
        if (ret > 0)
@@ -299,7 +299,7 @@ static bool cmd_myrights(struct client_command_context *cmd)
        if (ns == NULL)
                return TRUE;
 
-       box = mailbox_alloc(ns->list, real_mailbox, NULL,
+       box = mailbox_alloc(ns->list, real_mailbox, 
                            ACL_MAILBOX_FLAGS | MAILBOX_FLAG_IGNORE_ACLS);
        if (acl_object_get_my_rights(acl_mailbox_get_aclobj(box),
                                     pool_datastack_create(), &rights) < 0) {
index c745f130cbc61018fe41c72b2cd3eb32295b2fdd..b2375b457a652001d6d39015f942594e8b4128a1 100644 (file)
@@ -96,7 +96,7 @@ static bool cmd_getquotaroot(struct client_command_context *cmd)
                return TRUE;
        }
 
-       box = mailbox_alloc(ns->list, mailbox, NULL, MAILBOX_FLAG_READONLY |
+       box = mailbox_alloc(ns->list, mailbox, MAILBOX_FLAG_READONLY |
                            MAILBOX_FLAG_KEEP_RECENT);
 
        /* send QUOTAROOT reply */
index 7a231a7b1a7f4873b29234abd2cb737095634504..8de527d9cd9b79d194e81eccd69a2347fd95ec32 100644 (file)
@@ -76,7 +76,7 @@ mailbox_open_or_create(struct mailbox_list *list, const char *name,
        struct mail_storage *storage;
        enum mail_error error;
 
-       box = mailbox_alloc(list, name, NULL, MAILBOX_FLAG_KEEP_RECENT |
+       box = mailbox_alloc(list, name, MAILBOX_FLAG_KEEP_RECENT |
                            MAILBOX_FLAG_NO_INDEX_FILES);
        if (mailbox_open(box) == 0) {
                *error_r = NULL;
@@ -283,7 +283,7 @@ mailbox_move_all_mails(struct mailbox *src_box, const char *dest_name)
        enum mail_error error;
        int ret;
 
-       dest_box = mailbox_alloc(src_box->list, dest_name, NULL, 0);
+       dest_box = mailbox_alloc(src_box->list, dest_name, 0);
        if (mailbox_open(dest_box) < 0) {
                errstr = mail_storage_get_last_error(dest_box->storage, &error);
                i_error("lazy_expunge: Couldn't open DELETE dest mailbox "
@@ -389,7 +389,7 @@ static int lazy_expunge_mailbox_delete(struct mailbox *box)
        /* other sessions now see the mailbox completely deleted.
           since it's not really deleted in the lazy-expunge namespace,
           we might want to change it again. so mark the index undeleted. */
-       expunge_box = mailbox_alloc(dest_ns->list, destname, NULL,
+       expunge_box = mailbox_alloc(dest_ns->list, destname,
                                    MAILBOX_FLAG_OPEN_DELETED);
        if (mailbox_open(expunge_box) < 0) {
                str = mail_storage_get_last_error(expunge_box->storage, &error);
index 299e15482dc58a8b1d96b916ffd2b73422ae7f86..a5e6f7c7408a75d90b62cdb9365b4114a64a02fb 100644 (file)
@@ -203,8 +203,7 @@ listescape_mailbox_list_iter_deinit(struct mailbox_list_iterate_context *ctx)
 static struct mailbox *
 listescape_mailbox_alloc(struct mail_storage *storage,
                         struct mailbox_list *list,
-                        const char *name, struct istream *input,
-                        enum mailbox_flags flags)
+                        const char *name, enum mailbox_flags flags)
 {
        struct listescape_mail_storage *mstorage = LIST_ESCAPE_CONTEXT(storage);
        struct listescape_mailbox_list *mlist = LIST_ESCAPE_LIST_CONTEXT(list);
@@ -212,7 +211,7 @@ listescape_mailbox_alloc(struct mail_storage *storage,
        if (!mlist->name_escaped && list->hierarchy_sep != list->ns->sep)
                name = list_escape(list->ns, name, FALSE);
        return mstorage->module_ctx.super.
-               mailbox_alloc(storage, list, name, input, flags);
+               mailbox_alloc(storage, list, name, flags);
 }
 
 static int
index 3fa41c04ea0c2df9c16ca4ae4474b7b5468a001c..6b20a8c7317ebef7525de688d777e3c0cc480e05 100644 (file)
@@ -109,7 +109,7 @@ mbox_snarf_sync_init(struct mailbox *box, enum mailbox_sync_flags flags)
 
        /* try to open the spool mbox */
        mstorage->open_spool_inbox = TRUE;
-       spool_mbox = mailbox_alloc(box->list, "INBOX", NULL,
+       spool_mbox = mailbox_alloc(box->list, "INBOX",
                                   MAILBOX_FLAG_KEEP_RECENT |
                                   MAILBOX_FLAG_NO_INDEX_FILES);
        mstorage->open_spool_inbox = FALSE;
@@ -123,8 +123,7 @@ mbox_snarf_sync_init(struct mailbox *box, enum mailbox_sync_flags flags)
 static struct mailbox *
 mbox_snarf_mailbox_alloc(struct mail_storage *storage,
                         struct mailbox_list *list,
-                        const char *name, struct istream *input,
-                        enum mailbox_flags flags)
+                        const char *name, enum mailbox_flags flags)
 {
        struct mbox_snarf_mail_storage *mstorage =
                MBOX_SNARF_CONTEXT(storage);
@@ -151,7 +150,7 @@ mbox_snarf_mailbox_alloc(struct mail_storage *storage,
        }
 
        box = mstorage->module_ctx.super.
-               mailbox_alloc(storage, list, name, input, flags);
+               mailbox_alloc(storage, list, name, flags);
        storage->flags = old_flags;
        list->flags = old_list_flags;
 
index e1d623a0fe21d798b4d485af66777baca4008e4e..09214069a6faf2a718c29ff009bee28401a60476 100644 (file)
@@ -27,7 +27,7 @@ quota_count_mailbox(struct quota_root *root, struct mail_namespace *ns,
                return 0;
        }
 
-       box = mailbox_alloc(ns->list, name, NULL,
+       box = mailbox_alloc(ns->list, name,
                            MAILBOX_FLAG_READONLY | MAILBOX_FLAG_KEEP_RECENT);
        if (mailbox_open(box) < 0) {
                mail_storage_get_last_error(mailbox_get_storage(box), &error);
index 3db53cebecf9974e3c13400814229186622a1a6e..20aaa3463974e66c4e36a42cb6d5fa2f9695da18 100644 (file)
@@ -52,7 +52,7 @@ static int trash_clean_mailbox_open(struct trash_mailbox *trash)
 {
        struct mail_search_args *search_args;
 
-       trash->box = mailbox_alloc(trash->ns->list, trash->name, NULL,
+       trash->box = mailbox_alloc(trash->ns->list, trash->name,
                                   MAILBOX_FLAG_KEEP_RECENT);
        if (mailbox_open(trash->box) < 0) {
                mailbox_free(&trash->box);
index 4e41626c30355db706152db7d47a069f1544e6c5..a2e260bfbf0a0327e9207a0b11182a4c03492f07 100644 (file)
@@ -131,7 +131,7 @@ static int virtual_backend_box_open(struct virtual_mailbox *mbox,
 
        mailbox = bbox->name;
        ns = mail_namespace_find(user->namespaces, &mailbox);
-       bbox->box = mailbox_alloc(ns->list, mailbox, NULL, flags);
+       bbox->box = mailbox_alloc(ns->list, mailbox, flags);
 
        if (mailbox_open(bbox->box) < 0) {
                storage = mailbox_get_storage(bbox->box);
@@ -188,8 +188,7 @@ static int virtual_mailboxes_open(struct virtual_mailbox *mbox,
 
 static struct mailbox *
 virtual_mailbox_alloc(struct mail_storage *_storage, struct mailbox_list *list,
-                     const char *name, struct istream *input,
-                     enum mailbox_flags flags)
+                     const char *name, enum mailbox_flags flags)
 {
        struct virtual_storage *storage = (struct virtual_storage *)_storage;
        struct virtual_mailbox *mbox;
@@ -203,7 +202,7 @@ virtual_mailbox_alloc(struct mail_storage *_storage, struct mailbox_list *list,
        mbox->box.list = list;
        mbox->box.mail_vfuncs = &virtual_mail_vfuncs;
 
-       index_storage_mailbox_alloc(&mbox->box, name, input, flags,
+       index_storage_mailbox_alloc(&mbox->box, name, flags,
                                    VIRTUAL_INDEX_PREFIX);
 
        mbox->storage = storage;
@@ -228,12 +227,6 @@ static int virtual_mailbox_open(struct mailbox *box)
                return -1;
        }
 
-       if (box->input != NULL) {
-               mail_storage_set_critical(box->storage,
-                       "virtual doesn't support streamed mailboxes");
-               return -1;
-       }
-
        if (stat(box->path, &st) == 0) {
                /* exists, open it */
        } else if (errno == ENOENT) {
index a93934712eaeaa954d56229ff17268f2544cd7e9..e45197f66e51d01f756f80d928ae02dedd8a1f10 100644 (file)
@@ -4,8 +4,8 @@
 #include "array.h"
 #include "istream.h"
 #include "ostream.h"
-#include "maildir/maildir-storage.h"
-#include "maildir/maildir-uidlist.h"
+#include "mail-user.h"
+#include "index-storage.h"
 #include "index-mail.h"
 #include "istream-zlib.h"
 #include "ostream-zlib.h"
@@ -310,13 +310,10 @@ zlib_mail_save_compress_begin(struct mail_save_context *ctx,
        return 0;
 }
 
-static void zlib_maildir_open_init(struct mailbox *box)
+static void zlib_maildir_alloc_init(struct mailbox *box)
 {
        struct zlib_user *zuser = ZLIB_USER_CONTEXT(box->storage->user);
-       union mailbox_module_context *zbox;
 
-       zbox = p_new(box->pool, union mailbox_module_context, 1);
-       zbox->super = box->v;
        box->v.mail_alloc = zlib_maildir_mail_alloc;
        box->v.transaction_begin = zlib_mailbox_transaction_begin;
        box->v.transaction_rollback = zlib_mailbox_transaction_rollback;
@@ -327,67 +324,58 @@ static void zlib_maildir_open_init(struct mailbox *box)
        } else {
                box->v.save_begin = zlib_mail_save_compress_begin;
        }
-
-       MODULE_CONTEXT_SET_SELF(box, zlib_storage_module, zbox);
 }
 
-static struct istream *
-zlib_mailbox_open_input(struct mail_storage *storage, struct mailbox_list *list,
-                       const char *name)
+static int zlib_mailbox_open_input(struct mailbox *box)
 {
        struct zlib_handler *handler;
-       const char *path;
        int fd;
 
-       handler = zlib_get_zlib_handler_ext(name);
+       handler = zlib_get_zlib_handler_ext(box->name);
        if (handler == NULL || handler->create_istream == NULL)
-               return NULL;
+               return 0;
 
-       if (mail_storage_is_mailbox_file(storage)) {
+       if (mail_storage_is_mailbox_file(box->storage)) {
                /* looks like a compressed single file mailbox. we should be
                   able to handle this. */
-               path = mailbox_list_get_path(list, name,
-                                            MAILBOX_LIST_PATH_TYPE_MAILBOX);
-               fd = open(path, O_RDONLY);
-               if (fd != -1)
-                       return handler->create_istream(fd);
+               fd = open(box->path, O_RDONLY);
+               if (fd == -1) {
+                       mail_storage_set_critical(box->storage,
+                               "open(%s) failed: %m", box->path);
+                       return -1;
+               }
+               box->input = handler->create_istream(fd);
+               box->flags |= MAILBOX_FLAG_READONLY;
        }
-       return NULL;
+       return 0;
 }
 
-static struct mailbox *
-zlib_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
-                  const char *name, struct istream *input,
-                  enum mailbox_flags flags)
+static int zlib_mailbox_open(struct mailbox *box)
 {
-       union mail_storage_module_context *qstorage = ZLIB_CONTEXT(storage);
-       struct mailbox *box;
-       struct istream *zlib_input = NULL;
+       union mailbox_module_context *zbox = ZLIB_CONTEXT(box);
 
-       if (input == NULL && strcmp(storage->name, "mbox") == 0) {
-               input = zlib_input =
-                       zlib_mailbox_open_input(storage, list, name);
+       if (box->input == NULL &&
+           (box->storage->class_flags &
+            MAIL_STORAGE_CLASS_FLAG_OPEN_STREAMS) != 0) {
+               if (zlib_mailbox_open_input(box) < 0)
+                       return -1;
        }
 
-       box = qstorage->super.mailbox_alloc(storage, list, name, input, flags);
-
-       if (zlib_input != NULL)
-               i_stream_unref(&zlib_input);
-
-       if (strcmp(box->storage->name, "maildir") == 0)
-               zlib_maildir_open_init(box);
-       return box;
+       return zbox->super.open(box);
 }
 
-static void zlib_mail_storage_created(struct mail_storage *storage)
+static void zlib_mailbox_allocated(struct mailbox *box)
 {
-       union mail_storage_module_context *qstorage;
+       union mailbox_module_context *zbox;
 
-       qstorage = p_new(storage->pool, union mail_storage_module_context, 1);
-       qstorage->super = storage->v;
-       storage->v.mailbox_alloc = zlib_mailbox_alloc;
+       zbox = p_new(box->pool, union mailbox_module_context, 1);
+       zbox->super = box->v;
+       box->v.open = zlib_mailbox_open;
 
-       MODULE_CONTEXT_SET_SELF(storage, zlib_storage_module, qstorage);
+       MODULE_CONTEXT_SET_SELF(box, zlib_storage_module, zbox);
+
+       if (strcmp(box->storage->name, "maildir") == 0)
+               zlib_maildir_alloc_init(box);
 }
 
 static void zlib_mail_user_created(struct mail_user *user)
@@ -419,7 +407,7 @@ static void zlib_mail_user_created(struct mail_user *user)
 
 static struct mail_storage_hooks zlib_mail_storage_hooks = {
        .mail_user_created = zlib_mail_user_created,
-       .mail_storage_created = zlib_mail_storage_created
+       .mailbox_allocated = zlib_mailbox_allocated
 };
 
 void zlib_plugin_init(struct module *module)
index c1222f556a6747b47bd7ecc5e24872d842af4cff..a1a0f79e422b93b2efe69a87e5d6c38bc28f9e28 100644 (file)
@@ -237,7 +237,7 @@ struct client *client_create(int fd_in, int fd_out, struct mail_user *user,
                flags |= MAILBOX_FLAG_KEEP_RECENT;
        if (set->pop3_lock_session)
                flags |= MAILBOX_FLAG_KEEP_LOCKED;
-       client->mailbox = mailbox_alloc(ns->list, "INBOX", NULL, flags);
+       client->mailbox = mailbox_alloc(ns->list, "INBOX", flags);
        storage = mailbox_get_storage(client->mailbox);
        if (mailbox_open(client->mailbox) < 0) {
                errmsg = t_strdup_printf("Couldn't open INBOX: %s",