dovecot-2.0: Fixed plugins to use the new mailbox rename API.
dovecot at dovecot.org
dovecot at dovecot.org
Sun Feb 14 22:49:14 EET 2010
details: http://hg.dovecot.org/dovecot-2.0/rev/38897b223957
changeset: 10712:38897b223957
user: Timo Sirainen <tss at iki.fi>
date: Sun Feb 14 22:49:11 2010 +0200
description:
Fixed plugins to use the new mailbox rename API.
diffstat:
src/plugins/acl/acl-mailbox-list.c | 50 -------------------------
src/plugins/acl/acl-mailbox.c | 38 +++++++++++++++++++
src/plugins/listescape/listescape-plugin.c | 16 --------
src/plugins/mail-log/mail-log-plugin.c | 10 ++---
src/plugins/notify/notify-noop.c | 6 +--
src/plugins/notify/notify-plugin-private.h | 6 +--
src/plugins/notify/notify-plugin.c | 12 ++----
src/plugins/notify/notify-plugin.h | 12 ++----
src/plugins/notify/notify-storage.c | 50 +++++++-----------------
9 files changed, 69 insertions(+), 131 deletions(-)
diffs (truncated from 349 to 300 lines):
diff -r 292562f9b12c -r 38897b223957 src/plugins/acl/acl-mailbox-list.c
--- a/src/plugins/acl/acl-mailbox-list.c Sun Feb 14 22:32:59 2010 +0200
+++ b/src/plugins/acl/acl-mailbox-list.c Sun Feb 14 22:49:11 2010 +0200
@@ -487,55 +487,6 @@
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 @@
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 -r 292562f9b12c -r 38897b223957 src/plugins/acl/acl-mailbox.c
--- a/src/plugins/acl/acl-mailbox.c Sun Feb 14 22:32:59 2010 +0200
+++ b/src/plugins/acl/acl-mailbox.c Sun Feb 14 22:49:11 2010 +0200
@@ -191,6 +191,43 @@
}
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 @@
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 -r 292562f9b12c -r 38897b223957 src/plugins/listescape/listescape-plugin.c
--- a/src/plugins/listescape/listescape-plugin.c Sun Feb 14 22:32:59 2010 +0200
+++ b/src/plugins/listescape/listescape-plugin.c Sun Feb 14 22:49:11 2010 +0200
@@ -214,21 +214,6 @@
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 @@
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 -r 292562f9b12c -r 38897b223957 src/plugins/mail-log/mail-log-plugin.c
--- a/src/plugins/mail-log/mail-log-plugin.c Sun Feb 14 22:32:59 2010 +0200
+++ b/src/plugins/mail-log/mail-log-plugin.c Sun Feb 14 22:49:11 2010 +0200
@@ -389,17 +389,15 @@
}
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 -r 292562f9b12c -r 38897b223957 src/plugins/notify/notify-noop.c
--- a/src/plugins/notify/notify-noop.c Sun Feb 14 22:32:59 2010 +0200
+++ b/src/plugins/notify/notify-noop.c Sun Feb 14 22:49:11 2010 +0200
@@ -23,8 +23,6 @@
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 -r 292562f9b12c -r 38897b223957 src/plugins/notify/notify-plugin-private.h
--- a/src/plugins/notify/notify-plugin-private.h Sun Feb 14 22:32:59 2010 +0200
+++ b/src/plugins/notify/notify-plugin-private.h Sun Feb 14 22:49:11 2010 +0200
@@ -17,10 +17,8 @@
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 -r 292562f9b12c -r 38897b223957 src/plugins/notify/notify-plugin.c
--- a/src/plugins/notify/notify-plugin.c Sun Feb 14 22:32:59 2010 +0200
+++ b/src/plugins/notify/notify-plugin.c Sun Feb 14 22:49:11 2010 +0200
@@ -160,17 +160,13 @@
}
}
-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 -r 292562f9b12c -r 38897b223957 src/plugins/notify/notify-plugin.h
--- a/src/plugins/notify/notify-plugin.h Sun Feb 14 22:32:59 2010 +0200
+++ b/src/plugins/notify/notify-plugin.h Sun Feb 14 22:49:11 2010 +0200
@@ -26,10 +26,8 @@
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_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 -r 292562f9b12c -r 38897b223957 src/plugins/notify/notify-storage.c
--- a/src/plugins/notify/notify-storage.c Sun Feb 14 22:32:59 2010 +0200
+++ b/src/plugins/notify/notify-storage.c Sun Feb 14 22:49:11 2010 +0200
@@ -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 @@
&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 @@
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;
More information about the dovecot-cvs
mailing list