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,
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);
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);
&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;
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
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);
}
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);
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));
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) {
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
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 */
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));
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)
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",
return NULL;
}
- box = mailbox_alloc(ns->list, name, NULL, flags);
+ box = mailbox_alloc(ns->list, name, flags);
if (mailbox_open(box) == 0)
return box;
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;
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 |
{
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) {
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) {
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) {
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)
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;
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);
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);
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;
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);
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);
}
void index_storage_mailbox_alloc(struct mailbox *box, const char *name,
- struct istream *input,
enum mailbox_flags flags,
const char *index_prefix)
{
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);
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);
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;
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);
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;
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;
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;
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 &&
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,
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;
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)) {
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,
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);
};
/* 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 {
#include "ioloop.h"
#include "array.h"
#include "llist.h"
+#include "istream.h"
#include "eacces-error.h"
#include "mkdir-parents.h"
#include "var-expand.h"
}
struct mailbox *mailbox_alloc(struct mailbox_list *list, const char *name,
- struct istream *input,
enum mailbox_flags flags)
{
struct mailbox_list *new_list = list;
}
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;
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);
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. */
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,
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;
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);
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);
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);
/* 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)
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) {
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 */
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;
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 "
/* 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);
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);
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
/* 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;
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);
}
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;
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);
{
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);
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);
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;
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;
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) {
#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"
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;
} 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)
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)
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",