return NULL;
}
- box = mailbox_open(ns->storage, name, NULL, open_flags);
+ box = mailbox_open(storage_r, name, NULL, open_flags);
if (box != NULL || !deliver_set->mailbox_autocreate)
return box;
- (void)mail_storage_get_last_error(ns->storage, &error);
+ (void)mail_storage_get_last_error(*storage_r, &error);
if (error != MAIL_ERROR_NOTFOUND)
return NULL;
/* try creating it. */
- if (mail_storage_mailbox_create(ns->storage, name, FALSE) < 0)
+ if (mail_storage_mailbox_create(*storage_r, name, FALSE) < 0)
return NULL;
if (deliver_set->mailbox_autosubscribe) {
/* (try to) subscribe to it */
}
/* and try opening again */
- box = mailbox_open(ns->storage, name, NULL, open_flags);
+ box = mailbox_open(storage_r, name, NULL, open_flags);
if (box == NULL)
return NULL;
i_fatal("Couldn't create internal raw storage: %s", errstr);
if (path == NULL) {
input = create_raw_stream(0, &mtime);
- box = mailbox_open(raw_ns->storage, "Dovecot Delivery Mail",
+ box = mailbox_open(&raw_ns->storage, "Dovecot Delivery Mail",
input, MAILBOX_OPEN_NO_INDEX_FILES);
i_stream_unref(&input);
} else {
mtime = (time_t)-1;
- box = mailbox_open(raw_ns->storage, path, NULL,
+ box = mailbox_open(&raw_ns->storage, path, NULL,
MAILBOX_OPEN_NO_INDEX_FILES);
}
if (box == NULL)
mailbox_equals(cmd->client->mailbox, storage, name))
return cmd->client->mailbox;
- box = mailbox_open(storage, name, NULL, MAILBOX_OPEN_SAVEONLY |
+ box = mailbox_open(&storage, name, NULL, MAILBOX_OPEN_SAVEONLY |
MAILBOX_OPEN_FAST | MAILBOX_OPEN_KEEP_RECENT);
if (box == NULL) {
client_send_storage_error(cmd, storage);
if (mailbox_equals(client->mailbox, storage, mailbox))
destbox = client->mailbox;
else {
- destbox = mailbox_open(storage, mailbox, NULL,
+ destbox = mailbox_open(&storage, mailbox, NULL,
MAILBOX_OPEN_SAVEONLY |
MAILBOX_OPEN_FAST |
MAILBOX_OPEN_KEEP_RECENT);
if (readonly)
open_flags |= MAILBOX_OPEN_READONLY | MAILBOX_OPEN_KEEP_RECENT;
- ctx->box = mailbox_open(ctx->storage, mailbox, NULL, open_flags);
+ ctx->box = mailbox_open(&ctx->storage, mailbox, NULL, open_flags);
if (ctx->box == NULL)
return -1;
}
/* open the mailbox */
- box = mailbox_open(storage, mailbox, NULL, MAILBOX_OPEN_FAST |
+ box = mailbox_open(&storage, mailbox, NULL, MAILBOX_OPEN_FAST |
MAILBOX_OPEN_READONLY | MAILBOX_OPEN_KEEP_RECENT);
if (box == NULL)
return FALSE;
return TRUE;
}
-struct mailbox *mailbox_open(struct mail_storage *storage, const char *name,
+struct mailbox *mailbox_open(struct mail_storage **_storage, const char *name,
struct istream *input,
enum mailbox_open_flags flags)
{
+ struct mail_storage *storage = *_storage;
struct mailbox *box;
mail_storage_clear_error(storage);
if (hook_mailbox_opened != NULL && box != NULL)
hook_mailbox_opened(box);
} T_END;
+
+ if (box != NULL)
+ *_storage = box->storage;
return box;
}
tried to be used, NULL is returned.
Note that append and copy may open the selected mailbox again
- with possibly different readonly-state. */
-struct mailbox *mailbox_open(struct mail_storage *storage, const char *name,
+ with possibly different readonly-state.
+
+ Given storage is a pointer-to-pointer because it may change as a result of
+ a new namespace being created for shared mailboxes. */
+struct mailbox *mailbox_open(struct mail_storage **storage, const char *name,
struct istream *input,
enum mailbox_open_flags flags);
/* Close the box. Returns -1 if some cleanup errors occurred, but
/* First open the source mailbox. If we can't open it, don't create
the destination mailbox either. */
- srcbox = mailbox_open(source_storage, name, NULL,
+ srcbox = mailbox_open(&source_storage, name, NULL,
MAILBOX_OPEN_READONLY | MAILBOX_OPEN_KEEP_RECENT);
if (srcbox == NULL) {
if (set->skip_broken_mailboxes)
}
}
- destbox = mailbox_open(dest_storage, dest_name, NULL,
+ destbox = mailbox_open(&dest_storage, dest_name, NULL,
MAILBOX_OPEN_KEEP_RECENT);
if (destbox == NULL) {
i_error("Mailbox conversion: Couldn't open dest mailbox %s: %s",
time_t *oldest_r)
{
struct mail_namespace *ns;
+ struct mail_storage *storage;
struct mailbox *box;
struct mail_search_context *search_ctx;
struct mailbox_transaction_context *t;
return 0;
}
- box = mailbox_open(ns->storage, ns_mailbox, NULL, 0);
+ storage = ns->storage;
+ box = mailbox_open(&storage, ns_mailbox, NULL, 0);
if (box == NULL) {
- errstr = mail_storage_get_last_error(ns->storage, &error);
+ errstr = mail_storage_get_last_error(storage, &error);
if (error != MAIL_ERROR_NOTFOUND) {
i_error("%s: Opening mailbox %s failed: %s",
user, mailbox, errstr);
/* Force opening the mailbox so that we can give a nicer error message
if mailbox isn't selectable but is listable. */
- box = mailbox_open(storage, name, NULL, ACL_MAILBOX_OPEN_FLAGS |
+ box = mailbox_open(&storage, name, NULL, ACL_MAILBOX_OPEN_FLAGS |
MAILBOX_OPEN_IGNORE_ACLS);
if (box == NULL) {
client_send_storage_error(cmd, storage);
if (storage == NULL)
return TRUE;
- box = mailbox_open(storage, real_mailbox, NULL, ACL_MAILBOX_OPEN_FLAGS |
- MAILBOX_OPEN_IGNORE_ACLS);
+ box = mailbox_open(&storage, real_mailbox, NULL,
+ ACL_MAILBOX_OPEN_FLAGS | MAILBOX_OPEN_IGNORE_ACLS);
if (box == NULL) {
client_send_storage_error(cmd, storage);
return TRUE;
if (storage == NULL)
return TRUE;
- box = mailbox_open(storage, mailbox, NULL, (MAILBOX_OPEN_READONLY |
- MAILBOX_OPEN_FAST |
- MAILBOX_OPEN_KEEP_RECENT));
+ box = mailbox_open(&storage, mailbox, NULL, (MAILBOX_OPEN_READONLY |
+ MAILBOX_OPEN_FAST |
+ MAILBOX_OPEN_KEEP_RECENT));
if (box == NULL) {
client_send_storage_error(cmd, storage);
return TRUE;
struct mailbox *box;
enum mail_error error;
- box = mailbox_open(storage, name, NULL, MAILBOX_OPEN_FAST |
+ box = mailbox_open(&storage, name, NULL, MAILBOX_OPEN_FAST |
MAILBOX_OPEN_KEEP_RECENT |
MAILBOX_OPEN_NO_INDEX_FILES);
if (box != NULL)
return NULL;
/* and try opening again */
- box = mailbox_open(storage, name, NULL, MAILBOX_OPEN_FAST |
+ box = mailbox_open(&storage, name, NULL, MAILBOX_OPEN_FAST |
MAILBOX_OPEN_KEEP_RECENT);
return box;
}
{
struct mbox_snarf_mail_storage *mstorage =
MBOX_SNARF_CONTEXT(box->storage);
+ struct mail_storage *storage;
struct mbox_snarf_mailbox *mbox = MBOX_SNARF_CONTEXT(box);
if (mbox->spool_mbox == NULL) {
/* try to open the spool mbox */
mstorage->open_spool_inbox = TRUE;
+ storage = box->storage;
mbox->spool_mbox =
- mailbox_open(box->storage, "INBOX", NULL,
+ mailbox_open(&storage, "INBOX", NULL,
MAILBOX_OPEN_KEEP_RECENT |
MAILBOX_OPEN_NO_INDEX_FILES);
mstorage->open_spool_inbox = FALSE;
return 0;
}
- box = mailbox_open(storage, name, NULL,
+ box = mailbox_open(&storage, name, NULL,
MAILBOX_OPEN_READONLY | MAILBOX_OPEN_KEEP_RECENT);
if (box == NULL)
return -1;
quota_mailbox_list_delete(struct mailbox_list *list, const char *name)
{
struct quota_mailbox_list *qlist = QUOTA_LIST_CONTEXT(list);
+ struct mail_storage *storage;
struct mailbox *box;
enum mail_error error;
const char *str;
and free the quota for all the messages existing in it. Open the
mailbox locked so that other processes can't mess up the quota
calculations by adding/removing mails while we're doing this. */
- box = mailbox_open(qlist->storage, name, NULL, MAILBOX_OPEN_FAST |
+ storage = qlist->storage;
+ box = mailbox_open(&storage, name, NULL, MAILBOX_OPEN_FAST |
MAILBOX_OPEN_KEEP_RECENT | MAILBOX_OPEN_KEEP_LOCKED);
if (box == NULL) {
str = mail_storage_get_last_error(qlist->storage, &error);
static int trash_clean_mailbox_open(struct trash_mailbox *trash)
{
+ struct mail_storage *storage = trash->storage;
struct mail_search_args *search_args;
- trash->box = mailbox_open(trash->storage, trash->name, NULL,
+ trash->box = mailbox_open(&storage, trash->name, NULL,
MAILBOX_OPEN_KEEP_RECENT);
if (trash->box == NULL)
return 0;
struct mail_user *user = mbox->storage->storage.ns->user;
struct virtual_backend_box *const *bboxes;
struct mail_namespace *ns;
+ struct mail_storage *storage;
unsigned int i, count;
enum mail_error error;
const char *str, *mailbox;
for (i = 0; i < count; i++) {
mailbox = bboxes[i]->name;
ns = mail_namespace_find(user->namespaces, &mailbox);
- bboxes[i]->box = mailbox_open(ns->storage, mailbox,
+ storage = ns->storage;
+ bboxes[i]->box = mailbox_open(&storage, mailbox,
NULL, open_flags);
if (bboxes[i]->box == NULL) {
- if (ns->storage != mbox->ibox.box.storage) {
+ if (storage != mbox->ibox.box.storage) {
/* copy the error */
- str = mail_storage_get_last_error(ns->storage,
+ str = mail_storage_get_last_error(storage,
&error);
mail_storage_set_error(mbox->ibox.box.storage,
error, str);
flags |= MAILBOX_OPEN_KEEP_RECENT;
if (lock_session)
flags |= MAILBOX_OPEN_KEEP_LOCKED;
- client->mailbox = mailbox_open(storage, "INBOX", NULL, flags);
+ client->mailbox = mailbox_open(&storage, "INBOX", NULL, flags);
if (client->mailbox == NULL) {
errmsg = t_strdup_printf("Couldn't open INBOX: %s",
mail_storage_get_last_error(storage,