Mercurial > dovecot > core-2.2
changeset 10690:b7c8221cea5b HEAD
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
line wrap: on
line diff
--- a/src/doveadm/doveadm-mail.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/doveadm/doveadm-mail.c Fri Feb 12 23:27:16 2010 +0200 @@ -46,7 +46,7 @@ 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,
--- a/src/dsync/dsync-worker-local.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/dsync/dsync-worker-local.c Fri Feb 12 23:27:16 2010 +0200 @@ -505,7 +505,7 @@ 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 @@ 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 @@ &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 @@ 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_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 @@ 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);
--- a/src/imap/cmd-append.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/imap/cmd-append.c Fri Feb 12 23:27:16 2010 +0200 @@ -464,7 +464,7 @@ 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));
--- a/src/imap/cmd-copy.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/imap/cmd-copy.c Fri Feb 12 23:27:16 2010 +0200 @@ -118,7 +118,7 @@ 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) {
--- a/src/imap/cmd-create.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/imap/cmd-create.c Fri Feb 12 23:27:16 2010 +0200 @@ -44,7 +44,7 @@ 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
--- a/src/imap/cmd-delete.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/imap/cmd-delete.c Fri Feb 12 23:27:16 2010 +0200 @@ -25,7 +25,7 @@ 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 */
--- a/src/imap/cmd-select.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/imap/cmd-select.c Fri Feb 12 23:27:16 2010 +0200 @@ -267,7 +267,7 @@ 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));
--- a/src/imap/imap-status.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/imap/imap-status.c Fri Feb 12 23:27:16 2010 +0200 @@ -66,7 +66,7 @@ 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)
--- a/src/lda/main.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/lda/main.c Fri Feb 12 23:27:16 2010 +0200 @@ -405,16 +405,20 @@ 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",
--- a/src/lib-lda/mail-deliver.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/lib-lda/mail-deliver.c Fri Feb 12 23:27:16 2010 +0200 @@ -106,7 +106,7 @@ return NULL; } - box = mailbox_alloc(ns->list, name, NULL, flags); + box = mailbox_alloc(ns->list, name, flags); if (mailbox_open(box) == 0) return box;
--- a/src/lib-storage/index/cydir/cydir-storage.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/lib-storage/index/cydir/cydir-storage.c Fri Feb 12 23:27:16 2010 +0200 @@ -35,8 +35,7 @@ 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 @@ 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 @@ { 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) {
--- a/src/lib-storage/index/dbox-common/dbox-storage.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/lib-storage/index/dbox-common/dbox-storage.c Fri Feb 12 23:27:16 2010 +0200 @@ -98,12 +98,6 @@ 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) {
--- a/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c Fri Feb 12 23:27:16 2010 +0200 @@ -406,8 +406,7 @@ 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 @@ 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)
--- a/src/lib-storage/index/dbox-multi/mdbox-storage.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/lib-storage/index/dbox-multi/mdbox-storage.c Fri Feb 12 23:27:16 2010 +0200 @@ -88,8 +88,7 @@ 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 @@ 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);
--- a/src/lib-storage/index/dbox-multi/mdbox-storage.h Fri Feb 12 21:31:49 2010 +0200 +++ b/src/lib-storage/index/dbox-multi/mdbox-storage.h Fri Feb 12 23:27:16 2010 +0200 @@ -51,8 +51,7 @@ 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);
--- a/src/lib-storage/index/dbox-single/sdbox-storage.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/lib-storage/index/dbox-single/sdbox-storage.c Fri Feb 12 23:27:16 2010 +0200 @@ -35,10 +35,9 @@ 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 @@ 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);
--- a/src/lib-storage/index/dbox-single/sdbox-storage.h Fri Feb 12 21:31:49 2010 +0200 +++ b/src/lib-storage/index/dbox-single/sdbox-storage.h Fri Feb 12 23:27:16 2010 +0200 @@ -36,11 +36,6 @@ 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);
--- a/src/lib-storage/index/index-storage.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/lib-storage/index/index-storage.c Fri Feb 12 23:27:16 2010 +0200 @@ -257,7 +257,6 @@ } 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 @@ 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);
--- a/src/lib-storage/index/index-storage.h Fri Feb 12 21:31:49 2010 +0200 +++ b/src/lib-storage/index/index-storage.h Fri Feb 12 23:27:16 2010 +0200 @@ -67,7 +67,6 @@ 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);
--- a/src/lib-storage/index/maildir/maildir-storage.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/lib-storage/index/maildir/maildir-storage.c Fri Feb 12 23:27:16 2010 +0200 @@ -318,8 +318,7 @@ 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 @@ 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 @@ 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;
--- a/src/lib-storage/index/mbox/mbox-storage.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/lib-storage/index/mbox/mbox-storage.c Fri Feb 12 23:27:16 2010 +0200 @@ -327,8 +327,7 @@ 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->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 @@ 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 @@ 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,
--- a/src/lib-storage/index/raw/raw-storage.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/lib-storage/index/raw/raw-storage.c Fri Feb 12 23:27:16 2010 +0200 @@ -35,8 +35,7 @@ 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 @@ mbox->box.list = list; mbox->box.mail_vfuncs = &raw_mail_vfuncs; - index_storage_mailbox_alloc(&mbox->box, name, input, flags, NULL); - - mbox->storage = (struct raw_storage *)storage; + index_storage_mailbox_alloc(&mbox->box, name, flags, NULL); - if (input != NULL) - mbox->mtime = mbox->ctime = ioloop_time; - else { - mbox->mtime = mbox->ctime = (time_t)-1; - mbox->have_filename = TRUE; - } + mbox->mtime = mbox->ctime = (time_t)-1; + mbox->storage = (struct raw_storage *)storage; 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 @@ 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,
--- a/src/lib-storage/mail-storage-private.h Fri Feb 12 21:31:49 2010 +0200 +++ b/src/lib-storage/mail-storage-private.h Fri Feb 12 23:27:16 2010 +0200 @@ -39,7 +39,6 @@ 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 @@ /* 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 {
--- a/src/lib-storage/mail-storage.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/lib-storage/mail-storage.c Fri Feb 12 23:27:16 2010 +0200 @@ -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 @@ } 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 @@ } 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 @@ 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);
--- a/src/lib-storage/mail-storage.h Fri Feb 12 21:31:49 2010 +0200 +++ b/src/lib-storage/mail-storage.h Fri Feb 12 23:27:16 2010 +0200 @@ -320,16 +320,15 @@ 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. */
--- a/src/lib-storage/test-mail-storage.h Fri Feb 12 21:31:49 2010 +0200 +++ b/src/lib-storage/test-mail-storage.h Fri Feb 12 23:27:16 2010 +0200 @@ -5,8 +5,7 @@ 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,
--- a/src/lib-storage/test-mailbox.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/lib-storage/test-mailbox.c Fri Feb 12 23:27:16 2010 +0200 @@ -359,8 +359,7 @@ 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;
--- a/src/lmtp/commands.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/lmtp/commands.c Fri Feb 12 23:27:16 2010 +0200 @@ -580,9 +580,10 @@ 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);
--- a/src/plugins/autocreate/autocreate-plugin.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/plugins/autocreate/autocreate-plugin.c Fri Feb 12 23:27:16 2010 +0200 @@ -25,7 +25,7 @@ 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);
--- a/src/plugins/expire/expire-tool.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/plugins/expire/expire-tool.c Fri Feb 12 23:27:16 2010 +0200 @@ -105,7 +105,7 @@ 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);
--- a/src/plugins/imap-acl/imap-acl-plugin.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/plugins/imap-acl/imap-acl-plugin.c Fri Feb 12 23:27:16 2010 +0200 @@ -70,7 +70,7 @@ /* 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 @@ 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) {
--- a/src/plugins/imap-quota/imap-quota-plugin.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/plugins/imap-quota/imap-quota-plugin.c Fri Feb 12 23:27:16 2010 +0200 @@ -96,7 +96,7 @@ 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 */
--- a/src/plugins/lazy-expunge/lazy-expunge-plugin.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/plugins/lazy-expunge/lazy-expunge-plugin.c Fri Feb 12 23:27:16 2010 +0200 @@ -76,7 +76,7 @@ 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 @@ 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 @@ /* 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);
--- a/src/plugins/listescape/listescape-plugin.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/plugins/listescape/listescape-plugin.c Fri Feb 12 23:27:16 2010 +0200 @@ -203,8 +203,7 @@ 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 @@ 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
--- a/src/plugins/mbox-snarf/mbox-snarf-plugin.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/plugins/mbox-snarf/mbox-snarf-plugin.c Fri Feb 12 23:27:16 2010 +0200 @@ -109,7 +109,7 @@ /* 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 @@ 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 @@ } 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;
--- a/src/plugins/quota/quota-count.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/plugins/quota/quota-count.c Fri Feb 12 23:27:16 2010 +0200 @@ -27,7 +27,7 @@ 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);
--- a/src/plugins/trash/trash-plugin.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/plugins/trash/trash-plugin.c Fri Feb 12 23:27:16 2010 +0200 @@ -52,7 +52,7 @@ { 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);
--- a/src/plugins/virtual/virtual-storage.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/plugins/virtual/virtual-storage.c Fri Feb 12 23:27:16 2010 +0200 @@ -131,7 +131,7 @@ 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 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 @@ 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 @@ 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) {
--- a/src/plugins/zlib/zlib-plugin.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/plugins/zlib/zlib-plugin.c Fri Feb 12 23:27:16 2010 +0200 @@ -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 @@ 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 @@ } 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 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)
--- a/src/pop3/pop3-client.c Fri Feb 12 21:31:49 2010 +0200 +++ b/src/pop3/pop3-client.c Fri Feb 12 23:27:16 2010 +0200 @@ -237,7 +237,7 @@ 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",