From: Timo Sirainen Date: Sun, 14 Feb 2010 20:49:11 +0000 (+0200) Subject: Fixed plugins to use the new mailbox rename API. X-Git-Tag: 2.0.beta3~86 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=206ac4273fa102500fa017f0c21a4fd72e94665a;p=thirdparty%2Fdovecot%2Fcore.git Fixed plugins to use the new mailbox rename API. --HG-- branch : HEAD --- diff --git a/src/plugins/acl/acl-mailbox-list.c b/src/plugins/acl/acl-mailbox-list.c index ff83179fa8..4df41829cf 100644 --- a/src/plugins/acl/acl-mailbox-list.c +++ b/src/plugins/acl/acl-mailbox-list.c @@ -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); diff --git a/src/plugins/acl/acl-mailbox.c b/src/plugins/acl/acl-mailbox.c index 6ab4b9b9ea..81ab8ed4ee 100644 --- a/src/plugins/acl/acl-mailbox.c +++ b/src/plugins/acl/acl-mailbox.c @@ -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; diff --git a/src/plugins/listescape/listescape-plugin.c b/src/plugins/listescape/listescape-plugin.c index a5e6f7c740..cedd30b518 100644 --- a/src/plugins/listescape/listescape-plugin.c +++ b/src/plugins/listescape/listescape-plugin.c @@ -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; diff --git a/src/plugins/mail-log/mail-log-plugin.c b/src/plugins/mail-log/mail-log-plugin.c index f9892df130..e23d235d12 100644 --- a/src/plugins/mail-log/mail-log-plugin.c +++ b/src/plugins/mail-log/mail-log-plugin.c @@ -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 = { diff --git a/src/plugins/notify/notify-noop.c b/src/plugins/notify/notify-noop.c index d89e37f49b..b991828fb4 100644 --- a/src/plugins/notify/notify-noop.c +++ b/src/plugins/notify/notify-noop.c @@ -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) {} diff --git a/src/plugins/notify/notify-plugin-private.h b/src/plugins/notify/notify-plugin-private.h index 34363c1b2e..2e0043c1da 100644 --- a/src/plugins/notify/notify-plugin-private.h +++ b/src/plugins/notify/notify-plugin-private.h @@ -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); diff --git a/src/plugins/notify/notify-plugin.c b/src/plugins/notify/notify-plugin.c index 2ff5d787c3..bbe13c961e 100644 --- a/src/plugins/notify/notify-plugin.c +++ b/src/plugins/notify/notify-plugin.c @@ -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 * diff --git a/src/plugins/notify/notify-plugin.h b/src/plugins/notify/notify-plugin.h index 4d477d0a27..2af8079a90 100644 --- a/src/plugins/notify/notify-plugin.h +++ b/src/plugins/notify/notify-plugin.h @@ -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); diff --git a/src/plugins/notify/notify-storage.c b/src/plugins/notify/notify-storage.c index eba7c84c7d..ddd5cb6523 100644 --- a/src/plugins/notify/notify-storage.c +++ b/src/plugins/notify/notify-storage.c @@ -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)