]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Fixed plugins to use the new mailbox rename API.
authorTimo Sirainen <tss@iki.fi>
Sun, 14 Feb 2010 20:49:11 +0000 (22:49 +0200)
committerTimo Sirainen <tss@iki.fi>
Sun, 14 Feb 2010 20:49:11 +0000 (22:49 +0200)
--HG--
branch : HEAD

src/plugins/acl/acl-mailbox-list.c
src/plugins/acl/acl-mailbox.c
src/plugins/listescape/listescape-plugin.c
src/plugins/mail-log/mail-log-plugin.c
src/plugins/notify/notify-noop.c
src/plugins/notify/notify-plugin-private.h
src/plugins/notify/notify-plugin.c
src/plugins/notify/notify-plugin.h
src/plugins/notify/notify-storage.c

index ff83179fa8ee1b6d2b33a0ec02267da4255d8730..4df41829cfcd0641a96e14c69007665822c35f3c 100644 (file)
@@ -487,55 +487,6 @@ acl_mailbox_list_create_dir(struct mailbox_list *list, const char *name,
                create_mailbox_dir(list, name, directory);
 }
 
-static int
-acl_mailbox_list_rename(struct mailbox_list *oldlist, const char *oldname,
-                       struct mailbox_list *newlist, const char *newname,
-                       bool rename_children)
-{
-       struct acl_mailbox_list *old_alist = ACL_LIST_CONTEXT(oldlist);
-       bool can_see;
-       int ret;
-
-       /* renaming requires rights to delete the old mailbox */
-       ret = acl_mailbox_list_have_right(oldlist, oldname, FALSE,
-                                         ACL_STORAGE_RIGHT_DELETE, &can_see);
-       if (ret <= 0) {
-               if (ret < 0)
-                       return -1;
-               if (can_see) {
-                       mailbox_list_set_error(oldlist, MAIL_ERROR_PERM,
-                                              MAIL_ERRSTR_NO_PERMISSION);
-               } else {
-                       mailbox_list_set_error(oldlist, MAIL_ERROR_NOTFOUND,
-                               T_MAIL_ERR_MAILBOX_NOT_FOUND(oldname));
-               }
-               return 0;
-       }
-
-       /* and create the new one under the parent mailbox */
-       T_BEGIN {
-               ret = acl_mailbox_list_have_right(newlist, newname, TRUE,
-                                               ACL_STORAGE_RIGHT_CREATE, NULL);
-       } T_END;
-
-       if (ret <= 0) {
-               if (ret == 0) {
-                       /* Note that if the mailbox didn't have LOOKUP
-                          permission, this not reveals to user the mailbox's
-                          existence. Can't help it. */
-                       mailbox_list_set_error(oldlist, MAIL_ERROR_PERM,
-                                              MAIL_ERRSTR_NO_PERMISSION);
-               } else {
-                       mailbox_list_set_internal_error(oldlist);
-               }
-               return -1;
-       }
-
-       return old_alist->module_ctx.super.
-               rename_mailbox(oldlist, oldname, newlist, newname,
-                              rename_children);
-}
-
 static void acl_mailbox_list_init_shared(struct mailbox_list *list)
 {
        struct acl_mailbox_list *alist;
@@ -601,7 +552,6 @@ static void acl_mailbox_list_init_default(struct mailbox_list *list)
        list->v.iter_deinit = acl_mailbox_list_iter_deinit;
        list->v.get_mailbox_name_status = acl_get_mailbox_name_status;
        list->v.create_mailbox_dir = acl_mailbox_list_create_dir;
-       list->v.rename_mailbox = acl_mailbox_list_rename;
 
        acl_storage_rights_ctx_init(&alist->rights, backend);
        MODULE_CONTEXT_SET(list, acl_mailbox_list_module, alist);
index 6ab4b9b9ea8f2699f82f3a4b05e697683a0d6874..81ab8ed4ee09d1d105be5344531eda883660db62 100644 (file)
@@ -190,6 +190,43 @@ acl_mailbox_delete(struct mailbox *box)
        return ret;
 }
 
+static int
+acl_mailbox_rename(struct mailbox *src, struct mailbox *dest,
+                  bool rename_children)
+{
+       struct acl_mailbox *abox = ACL_CONTEXT(src);
+       int ret;
+
+       /* renaming requires rights to delete the old mailbox */
+       ret = acl_mailbox_right_lookup(src, ACL_STORAGE_RIGHT_DELETE);
+       if (ret <= 0) {
+               if (ret == 0)
+                       acl_mailbox_fail_not_found(src);
+               return -1;
+       }
+
+       /* and create the new one under the parent mailbox */
+       T_BEGIN {
+               ret = acl_mailbox_list_have_right(dest->list, dest->name, TRUE,
+                                               ACL_STORAGE_RIGHT_CREATE, NULL);
+       } T_END;
+
+       if (ret <= 0) {
+               if (ret == 0) {
+                       /* Note that if the mailbox didn't have LOOKUP
+                          permission, this now reveals to user the mailbox's
+                          existence. Can't help it. */
+                       mail_storage_set_error(src->storage, MAIL_ERROR_PERM,
+                                              MAIL_ERRSTR_NO_PERMISSION);
+               } else {
+                       mail_storage_set_internal_error(src->storage);
+               }
+               return -1;
+       }
+
+       return abox->module_ctx.super.rename(src, dest, rename_children);
+}
+
 static int
 acl_get_write_rights(struct mailbox *box,
                     bool *flags_r, bool *flag_seen_r, bool *flag_del_r)
@@ -485,6 +522,7 @@ void acl_mailbox_allocated(struct mailbox *box)
                box->v.create = acl_mailbox_create;
                box->v.update = acl_mailbox_update;
                box->v.delete = acl_mailbox_delete;
+               box->v.rename = acl_mailbox_rename;
                box->v.mail_alloc = acl_mail_alloc;
                box->v.save_begin = acl_save_begin;
                box->v.keywords_create = acl_keywords_create;
index a5e6f7c7408a75d90b62cdb9365b4114a64a02fb..cedd30b51842c7262d903cf7a0239058c0648825 100644 (file)
@@ -214,21 +214,6 @@ listescape_mailbox_alloc(struct mail_storage *storage,
                mailbox_alloc(storage, list, name, flags);
 }
 
-static int
-listescape_rename_mailbox(struct mailbox_list *oldlist, const char *oldname,
-                         struct mailbox_list *newlist, const char *newname,
-                         bool rename_children)
-{
-       struct listescape_mailbox_list *old_mlist =
-               LIST_ESCAPE_LIST_CONTEXT(oldlist);
-
-       oldname = list_escape(oldlist->ns, oldname, FALSE);
-       newname = list_escape(newlist->ns, newname, FALSE);
-       return old_mlist->module_ctx.super.
-               rename_mailbox(oldlist, oldname, newlist, newname,
-                              rename_children);
-}
-
 static int listescape_set_subscribed(struct mailbox_list *list, 
                                     const char *name, bool set)
 {
@@ -303,7 +288,6 @@ static void listescape_mail_namespace_storage_added(struct mail_namespace *ns)
        list->v.iter_init = listescape_mailbox_list_iter_init;
        list->v.iter_next = listescape_mailbox_list_iter_next;
        list->v.iter_deinit = listescape_mailbox_list_iter_deinit;
-       list->v.rename_mailbox = listescape_rename_mailbox;
        list->v.set_subscribed = listescape_set_subscribed;
        list->v.get_mailbox_name_status = listescape_get_mailbox_name_status;
        list->v.is_valid_existing_name = listescape_is_valid_existing_name;
index f9892df1300b8887c8bf43f30b9503335cbd0aca..e23d235d123f94d649d02b8d6152c635f64e21fc 100644 (file)
@@ -389,17 +389,15 @@ mail_log_mailbox_delete_commit(void *txn ATTR_UNUSED, struct mailbox *box)
 }
 
 static void
-mail_log_mailbox_rename(struct mailbox_list *oldlist ATTR_UNUSED,
-                       const char *oldname,
-                       struct mailbox_list *newlist ATTR_UNUSED,
-                       const char *newname, bool rename_children ATTR_UNUSED)
+mail_log_mailbox_rename(struct mailbox *src,
+                       struct mailbox *dest, bool rename_children ATTR_UNUSED)
 {
        if ((mail_log_set.events & MAIL_LOG_EVENT_MAILBOX_RENAME) == 0)
                return;
 
        i_info("Mailbox renamed: %s -> %s",
-              str_sanitize(oldname, MAILBOX_NAME_LOG_LEN),
-              str_sanitize(newname, MAILBOX_NAME_LOG_LEN));
+              str_sanitize(src->name, MAILBOX_NAME_LOG_LEN),
+              str_sanitize(dest->name, MAILBOX_NAME_LOG_LEN));
 }
 
 static const struct notify_vfuncs mail_log_vfuncs = {
index d89e37f49b8cfd1d3c1222f3da1d63c74da6d416..b991828fb496fd9313abc7c11e8962e56f600fbf 100644 (file)
@@ -23,8 +23,6 @@ void *notify_noop_mailbox_delete_begin(struct mailbox *box ATTR_UNUSED) { return
 void notify_noop_mailbox_delete_commit(void *txn ATTR_UNUSED,
                                       struct mailbox *box ATTR_UNUSED) {}
 void notify_noop_mailbox_delete_rollback(void *txn ATTR_UNUSED) {}
-void notify_noop_mailbox_rename(struct mailbox_list *oldlist ATTR_UNUSED,
-                               const char *oldname ATTR_UNUSED,
-                               struct mailbox_list *newlist ATTR_UNUSED,
-                               const char *newname ATTR_UNUSED,
+void notify_noop_mailbox_rename(struct mailbox *src ATTR_UNUSED,
+                               struct mailbox *dest ATTR_UNUSED,
                                bool rename_children ATTR_UNUSED) {}
index 34363c1b2e02f7c02b79d751dc9332623dea6beb..2e0043c1da21f6890b73d49fe6c912cd9ffd6625 100644 (file)
@@ -17,10 +17,8 @@ void notify_contexts_mail_transaction_rollback(struct mailbox_transaction_contex
 void notify_contexts_mailbox_delete_begin(struct mailbox *box);
 void notify_contexts_mailbox_delete_commit(struct mailbox *box);
 void notify_contexts_mailbox_delete_rollback(void);
-void notify_contexts_mailbox_rename(struct mailbox_list *oldlist,
-                                   const char *oldname,
-                                   struct mailbox_list *newlist,
-                                   const char *newname, bool rename_children);
+void notify_contexts_mailbox_rename(struct mailbox *src, struct mailbox *dest,
+                                   bool rename_children);
 
 void notify_plugin_init_storage(struct module *module);
 void notify_plugin_deinit_storage(void);
index 2ff5d787c322da44d17c4043008969472edb55c4..bbe13c961e868eb2eceb9a4eedd9e9a8cef8a26c 100644 (file)
@@ -160,17 +160,13 @@ void notify_contexts_mailbox_delete_rollback(void)
        }
 }
 
-void notify_contexts_mailbox_rename(struct mailbox_list *oldlist,
-                                   const char *oldname,
-                                   struct mailbox_list *newlist,
-                                   const char *newname, bool rename_children)
+void notify_contexts_mailbox_rename(struct mailbox *src, struct mailbox *dest,
+                                   bool rename_children)
 {
        struct notify_context *ctx;
 
-       for (ctx = ctx_list; ctx != NULL; ctx = ctx->next) {
-               ctx->v.mailbox_rename(oldlist, oldname, newlist, newname,
-                                     rename_children);
-       }
+       for (ctx = ctx_list; ctx != NULL; ctx = ctx->next)
+               ctx->v.mailbox_rename(src, dest, rename_children);
 }
 
 struct notify_context *
index 4d477d0a2787d8fbfb6efdca71ea110f42b1c1e1..2af8079a9034e2affaad6d36bcfdcb8841485c37 100644 (file)
@@ -26,10 +26,8 @@ struct notify_vfuncs {
        void *(*mailbox_delete_begin)(struct mailbox *box);
        void (*mailbox_delete_commit)(void *txn, struct mailbox *box);
        void (*mailbox_delete_rollback)(void *txn);
-       void (*mailbox_rename)(struct mailbox_list *oldlist,
-                              const char *oldname,
-                              struct mailbox_list *newlist,
-                              const char *newname, bool rename_children);
+       void (*mailbox_rename)(struct mailbox *src, struct mailbox *dest,
+                              bool rename_children);
 };
 
 void notify_noop_mail_transaction_begin(struct mailbox_transaction_context *t);
@@ -46,10 +44,8 @@ void notify_noop_mail_transaction_rollback(void *txn);
 void *notify_noop_mailbox_delete_begin(struct mailbox *box);
 void notify_noop_mailbox_delete_commit(void *txn, struct mailbox *box);
 void notify_noop_mailbox_delete_rollback(void *txn);
-void notify_noop_mailbox_rename(struct mailbox_list *oldlist,
-                               const char *oldname,
-                               struct mailbox_list *newlist,
-                               const char *newname, bool rename_children);
+void notify_noop_mailbox_rename(struct mailbox *src, struct mailbox *dest,
+                               bool rename_children);
 
 struct notify_context *
 notify_register(const struct notify_vfuncs *vfuncs);
index eba7c84c7dfe8dcd64e6d5fd27b3d779c962208d..ddd5cb65237741f645bd81bb2a5d3a79298dcffb 100644 (file)
@@ -8,8 +8,6 @@
        MODULE_CONTEXT(obj, notify_storage_module)
 #define NOTIFY_MAIL_CONTEXT(obj) \
        MODULE_CONTEXT(obj, notify_mail_module)
-#define NOTIFY_LIST_CONTEXT(obj) \
-       MODULE_CONTEXT(obj, notify_mailbox_list_module)
 
 struct notify_transaction_context {
        union mailbox_transaction_module_context module_ctx;
@@ -20,8 +18,6 @@ static MODULE_CONTEXT_DEFINE_INIT(notify_storage_module,
                                  &mail_storage_module_register);
 static MODULE_CONTEXT_DEFINE_INIT(notify_mail_module,
                                  &mail_module_register);
-static MODULE_CONTEXT_DEFINE_INIT(notify_mailbox_list_module,
-                                 &mailbox_list_module_register);
 
 static void
 notify_mail_expunge(struct mail *_mail)
@@ -213,6 +209,19 @@ notify_mailbox_delete(struct mailbox *box)
        return 0;
 }
 
+static int
+notify_mailbox_rename(struct mailbox *src, struct mailbox *dest,
+                     bool rename_children)
+{
+       union mailbox_module_context *lbox = NOTIFY_CONTEXT(src);
+
+       if (lbox->super.rename(src, dest, rename_children) < 0)
+               return -1;
+
+       notify_contexts_mailbox_rename(src, dest, rename_children);
+       return 0;
+}
+
 static void notify_mailbox_allocated(struct mailbox *box)
 {
        union mailbox_module_context *lbox;
@@ -228,41 +237,12 @@ static void notify_mailbox_allocated(struct mailbox *box)
        box->v.transaction_commit = notify_transaction_commit;
        box->v.transaction_rollback = notify_transaction_rollback;
        box->v.delete = notify_mailbox_delete;
+       box->v.rename = notify_mailbox_rename;
        MODULE_CONTEXT_SET_SELF(box, notify_storage_module, lbox);
 }
 
-static int
-notify_mailbox_list_rename(struct mailbox_list *oldlist, const char *oldname,
-                          struct mailbox_list *newlist, const char *newname,
-                          bool rename_children)
-{
-       union mailbox_list_module_context *oldllist =
-               NOTIFY_LIST_CONTEXT(oldlist);
-
-       if (oldllist->super.rename_mailbox(oldlist, oldname, newlist, newname,
-                                          rename_children) < 0)
-               return -1;
-
-       notify_contexts_mailbox_rename(oldlist, oldname, newlist, newname,
-                                      rename_children);
-       return 0;
-}
-
-static void notify_mail_namespace_storage_added(struct mail_namespace *ns)
-{
-       struct mailbox_list *list = ns->list;
-       union mailbox_list_module_context *llist;
-
-       llist = p_new(list->pool, union mailbox_list_module_context, 1);
-       llist->super = list->v;
-       list->v.rename_mailbox = notify_mailbox_list_rename;
-
-       MODULE_CONTEXT_SET_SELF(list, notify_mailbox_list_module, llist);
-}
-
 static struct mail_storage_hooks notify_mail_storage_hooks = {
-       .mailbox_allocated = notify_mailbox_allocated,
-       .mail_namespace_storage_added = notify_mail_namespace_storage_added
+       .mailbox_allocated = notify_mailbox_allocated
 };
 
 void notify_plugin_init_storage(struct module *module)