From e5fd6dfd0a492e4708d4dbb7971d7fc5d7b8fd85 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Fri, 12 Feb 2010 23:27:16 +0200 Subject: [PATCH] lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream() --HG-- branch : HEAD --- src/doveadm/doveadm-mail.c | 2 +- src/dsync/dsync-worker-local.c | 13 ++- src/imap/cmd-append.c | 2 +- src/imap/cmd-copy.c | 2 +- src/imap/cmd-create.c | 2 +- src/imap/cmd-delete.c | 2 +- src/imap/cmd-select.c | 2 +- src/imap/imap-status.c | 2 +- src/lda/main.c | 16 ++-- src/lib-lda/mail-deliver.c | 2 +- src/lib-storage/index/cydir/cydir-storage.c | 11 +-- .../index/dbox-common/dbox-storage.c | 6 -- .../index/dbox-multi/mdbox-storage-rebuild.c | 6 +- .../index/dbox-multi/mdbox-storage.c | 6 +- .../index/dbox-multi/mdbox-storage.h | 3 +- .../index/dbox-single/sdbox-storage.c | 8 +- .../index/dbox-single/sdbox-storage.h | 5 -- src/lib-storage/index/index-storage.c | 21 ++--- src/lib-storage/index/index-storage.h | 1 - .../index/maildir/maildir-storage.c | 11 +-- src/lib-storage/index/mbox/mbox-storage.c | 12 +-- src/lib-storage/index/raw/raw-storage.c | 22 +++-- src/lib-storage/mail-storage-private.h | 5 +- src/lib-storage/mail-storage.c | 33 ++++++-- src/lib-storage/mail-storage.h | 9 +-- src/lib-storage/test-mail-storage.h | 3 +- src/lib-storage/test-mailbox.c | 3 +- src/lmtp/commands.c | 5 +- src/plugins/autocreate/autocreate-plugin.c | 2 +- src/plugins/expire/expire-tool.c | 2 +- src/plugins/imap-acl/imap-acl-plugin.c | 4 +- src/plugins/imap-quota/imap-quota-plugin.c | 2 +- .../lazy-expunge/lazy-expunge-plugin.c | 6 +- src/plugins/listescape/listescape-plugin.c | 5 +- src/plugins/mbox-snarf/mbox-snarf-plugin.c | 7 +- src/plugins/quota/quota-count.c | 2 +- src/plugins/trash/trash-plugin.c | 2 +- src/plugins/virtual/virtual-storage.c | 13 +-- src/plugins/zlib/zlib-plugin.c | 80 ++++++++----------- src/pop3/pop3-client.c | 2 +- 40 files changed, 150 insertions(+), 192 deletions(-) diff --git a/src/doveadm/doveadm-mail.c b/src/doveadm/doveadm-mail.c index 703aec2df5..1fc5b6e22d 100644 --- a/src/doveadm/doveadm-mail.c +++ b/src/doveadm/doveadm-mail.c @@ -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, diff --git a/src/dsync/dsync-worker-local.c b/src/dsync/dsync-worker-local.c index 97f3327811..a2d010d5d6 100644 --- a/src/dsync/dsync-worker-local.c +++ b/src/dsync/dsync-worker-local.c @@ -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); diff --git a/src/imap/cmd-append.c b/src/imap/cmd-append.c index 199a6db4d9..075b675b4b 100644 --- a/src/imap/cmd-append.c +++ b/src/imap/cmd-append.c @@ -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)); diff --git a/src/imap/cmd-copy.c b/src/imap/cmd-copy.c index e56beadcd0..34182878bb 100644 --- a/src/imap/cmd-copy.c +++ b/src/imap/cmd-copy.c @@ -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) { diff --git a/src/imap/cmd-create.c b/src/imap/cmd-create.c index d047c0bc54..27602ad16a 100644 --- a/src/imap/cmd-create.c +++ b/src/imap/cmd-create.c @@ -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 diff --git a/src/imap/cmd-delete.c b/src/imap/cmd-delete.c index 666c9c60b6..661538445c 100644 --- a/src/imap/cmd-delete.c +++ b/src/imap/cmd-delete.c @@ -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 */ diff --git a/src/imap/cmd-select.c b/src/imap/cmd-select.c index b53fda776e..583c4f1ac7 100644 --- a/src/imap/cmd-select.c +++ b/src/imap/cmd-select.c @@ -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)); diff --git a/src/imap/imap-status.c b/src/imap/imap-status.c index 414b107500..496ce037f6 100644 --- a/src/imap/imap-status.c +++ b/src/imap/imap-status.c @@ -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) diff --git a/src/lda/main.c b/src/lda/main.c index 07dc0b7efe..5b01ebd52f 100644 --- a/src/lda/main.c +++ b/src/lda/main.c @@ -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", diff --git a/src/lib-lda/mail-deliver.c b/src/lib-lda/mail-deliver.c index 59f312a60c..3197a4621c 100644 --- a/src/lib-lda/mail-deliver.c +++ b/src/lib-lda/mail-deliver.c @@ -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; diff --git a/src/lib-storage/index/cydir/cydir-storage.c b/src/lib-storage/index/cydir/cydir-storage.c index 02a3b7770c..8f44c35ba9 100644 --- a/src/lib-storage/index/cydir/cydir-storage.c +++ b/src/lib-storage/index/cydir/cydir-storage.c @@ -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) { diff --git a/src/lib-storage/index/dbox-common/dbox-storage.c b/src/lib-storage/index/dbox-common/dbox-storage.c index 6c394d12e9..7567240b46 100644 --- a/src/lib-storage/index/dbox-common/dbox-storage.c +++ b/src/lib-storage/index/dbox-common/dbox-storage.c @@ -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) { diff --git a/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c b/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c index 18d7da57cd..15ecc2d70e 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c +++ b/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c @@ -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) diff --git a/src/lib-storage/index/dbox-multi/mdbox-storage.c b/src/lib-storage/index/dbox-multi/mdbox-storage.c index 34071c49c3..6856be4bee 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-storage.c +++ b/src/lib-storage/index/dbox-multi/mdbox-storage.c @@ -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); diff --git a/src/lib-storage/index/dbox-multi/mdbox-storage.h b/src/lib-storage/index/dbox-multi/mdbox-storage.h index cf07112217..ce21077bbe 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-storage.h +++ b/src/lib-storage/index/dbox-multi/mdbox-storage.h @@ -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); diff --git a/src/lib-storage/index/dbox-single/sdbox-storage.c b/src/lib-storage/index/dbox-single/sdbox-storage.c index 45760f1755..3e022744a1 100644 --- a/src/lib-storage/index/dbox-single/sdbox-storage.c +++ b/src/lib-storage/index/dbox-single/sdbox-storage.c @@ -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); diff --git a/src/lib-storage/index/dbox-single/sdbox-storage.h b/src/lib-storage/index/dbox-single/sdbox-storage.h index 08467e8328..ae671e4bf1 100644 --- a/src/lib-storage/index/dbox-single/sdbox-storage.h +++ b/src/lib-storage/index/dbox-single/sdbox-storage.h @@ -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); diff --git a/src/lib-storage/index/index-storage.c b/src/lib-storage/index/index-storage.c index f6c82df566..d800dd95fe 100644 --- a/src/lib-storage/index/index-storage.c +++ b/src/lib-storage/index/index-storage.c @@ -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); diff --git a/src/lib-storage/index/index-storage.h b/src/lib-storage/index/index-storage.h index ccc9969453..a22bc9a31d 100644 --- a/src/lib-storage/index/index-storage.h +++ b/src/lib-storage/index/index-storage.h @@ -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); diff --git a/src/lib-storage/index/maildir/maildir-storage.c b/src/lib-storage/index/maildir/maildir-storage.c index 8ceb83f52d..49669c56f9 100644 --- a/src/lib-storage/index/maildir/maildir-storage.c +++ b/src/lib-storage/index/maildir/maildir-storage.c @@ -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; diff --git a/src/lib-storage/index/mbox/mbox-storage.c b/src/lib-storage/index/mbox/mbox-storage.c index 91726317cd..56e8a148e5 100644 --- a/src/lib-storage/index/mbox/mbox-storage.c +++ b/src/lib-storage/index/mbox/mbox-storage.c @@ -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, diff --git a/src/lib-storage/index/raw/raw-storage.c b/src/lib-storage/index/raw/raw-storage.c index eaed115d0a..ad8d25ab68 100644 --- a/src/lib-storage/index/raw/raw-storage.c +++ b/src/lib-storage/index/raw/raw-storage.c @@ -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, diff --git a/src/lib-storage/mail-storage-private.h b/src/lib-storage/mail-storage-private.h index 0f1514d224..3528ba99fb 100644 --- a/src/lib-storage/mail-storage-private.h +++ b/src/lib-storage/mail-storage-private.h @@ -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 { diff --git a/src/lib-storage/mail-storage.c b/src/lib-storage/mail-storage.c index 3efc10507b..c99e3b28ab 100644 --- a/src/lib-storage/mail-storage.c +++ b/src/lib-storage/mail-storage.c @@ -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); diff --git a/src/lib-storage/mail-storage.h b/src/lib-storage/mail-storage.h index 07e8f10870..f67c11da33 100644 --- a/src/lib-storage/mail-storage.h +++ b/src/lib-storage/mail-storage.h @@ -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. */ diff --git a/src/lib-storage/test-mail-storage.h b/src/lib-storage/test-mail-storage.h index 77d9d4dc1d..22057c2379 100644 --- a/src/lib-storage/test-mail-storage.h +++ b/src/lib-storage/test-mail-storage.h @@ -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, diff --git a/src/lib-storage/test-mailbox.c b/src/lib-storage/test-mailbox.c index e130901940..6cd18663bb 100644 --- a/src/lib-storage/test-mailbox.c +++ b/src/lib-storage/test-mailbox.c @@ -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; diff --git a/src/lmtp/commands.c b/src/lmtp/commands.c index 636bbaf506..ac89d4ae5b 100644 --- a/src/lmtp/commands.c +++ b/src/lmtp/commands.c @@ -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); diff --git a/src/plugins/autocreate/autocreate-plugin.c b/src/plugins/autocreate/autocreate-plugin.c index bc2f5d5733..17de7a0ce4 100644 --- a/src/plugins/autocreate/autocreate-plugin.c +++ b/src/plugins/autocreate/autocreate-plugin.c @@ -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); diff --git a/src/plugins/expire/expire-tool.c b/src/plugins/expire/expire-tool.c index a65507f322..59241f6a13 100644 --- a/src/plugins/expire/expire-tool.c +++ b/src/plugins/expire/expire-tool.c @@ -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); diff --git a/src/plugins/imap-acl/imap-acl-plugin.c b/src/plugins/imap-acl/imap-acl-plugin.c index 73bf91f1d3..1002d4057d 100644 --- a/src/plugins/imap-acl/imap-acl-plugin.c +++ b/src/plugins/imap-acl/imap-acl-plugin.c @@ -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) { diff --git a/src/plugins/imap-quota/imap-quota-plugin.c b/src/plugins/imap-quota/imap-quota-plugin.c index c745f130cb..b2375b457a 100644 --- a/src/plugins/imap-quota/imap-quota-plugin.c +++ b/src/plugins/imap-quota/imap-quota-plugin.c @@ -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 */ diff --git a/src/plugins/lazy-expunge/lazy-expunge-plugin.c b/src/plugins/lazy-expunge/lazy-expunge-plugin.c index 7a231a7b1a..8de527d9cd 100644 --- a/src/plugins/lazy-expunge/lazy-expunge-plugin.c +++ b/src/plugins/lazy-expunge/lazy-expunge-plugin.c @@ -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); diff --git a/src/plugins/listescape/listescape-plugin.c b/src/plugins/listescape/listescape-plugin.c index 299e15482d..a5e6f7c740 100644 --- a/src/plugins/listescape/listescape-plugin.c +++ b/src/plugins/listescape/listescape-plugin.c @@ -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 diff --git a/src/plugins/mbox-snarf/mbox-snarf-plugin.c b/src/plugins/mbox-snarf/mbox-snarf-plugin.c index 3fa41c04ea..6b20a8c731 100644 --- a/src/plugins/mbox-snarf/mbox-snarf-plugin.c +++ b/src/plugins/mbox-snarf/mbox-snarf-plugin.c @@ -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; diff --git a/src/plugins/quota/quota-count.c b/src/plugins/quota/quota-count.c index e1d623a0fe..09214069a6 100644 --- a/src/plugins/quota/quota-count.c +++ b/src/plugins/quota/quota-count.c @@ -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); diff --git a/src/plugins/trash/trash-plugin.c b/src/plugins/trash/trash-plugin.c index 3db53cebec..20aaa34639 100644 --- a/src/plugins/trash/trash-plugin.c +++ b/src/plugins/trash/trash-plugin.c @@ -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); diff --git a/src/plugins/virtual/virtual-storage.c b/src/plugins/virtual/virtual-storage.c index 4e41626c30..a2e260bfbf 100644 --- a/src/plugins/virtual/virtual-storage.c +++ b/src/plugins/virtual/virtual-storage.c @@ -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) { diff --git a/src/plugins/zlib/zlib-plugin.c b/src/plugins/zlib/zlib-plugin.c index a93934712e..e45197f66e 100644 --- a/src/plugins/zlib/zlib-plugin.c +++ b/src/plugins/zlib/zlib-plugin.c @@ -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) diff --git a/src/pop3/pop3-client.c b/src/pop3/pop3-client.c index c1222f556a..a1a0f79e42 100644 --- a/src/pop3/pop3-client.c +++ b/src/pop3/pop3-client.c @@ -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", -- 2.47.3