]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
When autocreating a new shared namespace, drop existing namespaces where we haven...
authorTimo Sirainen <tss@iki.fi>
Wed, 19 Nov 2008 16:57:43 +0000 (18:57 +0200)
committerTimo Sirainen <tss@iki.fi>
Wed, 19 Nov 2008 16:57:43 +0000 (18:57 +0200)
--HG--
branch : HEAD

src/lib-storage/index/shared/shared-storage.c
src/lib-storage/mail-namespace.h
src/lib-storage/mailbox-list.c

index 3e9498af649afc1e062ff5bdde79f62352a16da2..dd1696c951be9c28ce1fc278f2b498abc4465508 100644 (file)
@@ -163,6 +163,20 @@ static void get_nonexisting_user_location(struct shared_storage *storage,
        str_append(location, PKG_RUNDIR"/user-not-found");
 }
 
+static void drop_unusable_shared_namespaces(struct mail_user *user)
+{
+#define NS_UNUSABLE_FLAGS (NAMESPACE_FLAG_AUTOCREATED | )
+       struct mail_namespace *ns, *next;
+
+       for (ns = user->namespaces; ns != NULL; ns = next) {
+               next = ns->next;
+
+               if ((ns->flags & NAMESPACE_FLAG_USABLE) == 0 &&
+                   (ns->flags & NAMESPACE_FLAG_AUTOCREATED) != 0)
+                       mail_namespace_destroy(ns);
+       }
+}
+
 int shared_storage_get_namespace(struct mail_storage *_storage,
                                 const char **_name,
                                 struct mail_namespace **ns_r)
@@ -284,8 +298,7 @@ int shared_storage_get_namespace(struct mail_storage *_storage,
                                          ns->prefix, error);
                return -1;
        }
-       /* FIXME: we could remove namespaces here that don't have usable
-          mailboxes. otherwise the memory usage could just keep growing. */
+       drop_unusable_shared_namespaces(user);
        mail_user_add_namespace(user, ns);
 
        *_name = mail_namespace_fix_sep(ns, name);
@@ -325,6 +338,8 @@ shared_mailbox_open(struct mail_storage *storage, const char *name,
                mailbox_open(ns->storage, name, NULL, flags);
        if (box == NULL)
                shared_mailbox_copy_error(storage, ns);
+       else
+               ns->flags |= NAMESPACE_FLAG_USABLE;
        return box;
 }
 
index 26ffeef228e1e135a15ac3f2a36310ac8a313914..ac24a3e73a8cca6e5188fa038d5f79d533ab2830 100644 (file)
@@ -22,7 +22,10 @@ enum namespace_flags {
        /* Namespace is created for internal use only. */
        NAMESPACE_FLAG_INTERNAL         = 0x1000,
        /* Namespace was created automatically (for shared mailboxes) */
-       NAMESPACE_FLAG_AUTOCREATED      = 0x2000
+       NAMESPACE_FLAG_AUTOCREATED      = 0x2000,
+       /* Namespace has at least some usable mailboxes. Autocreated namespaces
+          that don't have usable mailboxes may be removed automatically. */
+       NAMESPACE_FLAG_USABLE           = 0x4000
 };
 
 struct mail_namespace {
index fd6e2354bcb3a92822c48656c45fe7fb20f30eb9..989d10e89f6991899d1d79e2a718c38105751794 100644 (file)
@@ -492,7 +492,12 @@ mailbox_list_iter_init_namespaces(struct mail_namespace *namespaces,
 const struct mailbox_info *
 mailbox_list_iter_next(struct mailbox_list_iterate_context *ctx)
 {
-       return ctx->list->v.iter_next(ctx);
+       const struct mailbox_info *info;
+
+       info = ctx->list->v.iter_next(ctx);
+       if (info != NULL)
+               ctx->list->ns->flags |= NAMESPACE_FLAG_USABLE;
+       return info;
 }
 
 int mailbox_list_iter_deinit(struct mailbox_list_iterate_context **_ctx)