changeset 7462:068f6eefc62b HEAD

next_hook should be called after our hook is finished with its doings, that way they get executed in the intended order. This should fix some problems when multiple plugins are used.
author Timo Sirainen <tss@iki.fi>
date Fri, 25 Apr 2008 01:31:05 +0300
parents bf99bd33d69b
children d1bd08d468d0
files src/plugins/acl/acl-mailbox-list.c src/plugins/acl/acl-storage.c src/plugins/convert/convert-plugin.c src/plugins/expire/expire-plugin.c src/plugins/fts/fts-storage.c src/plugins/lazy-expunge/lazy-expunge-plugin.c src/plugins/mail-log/mail-log-plugin.c src/plugins/mbox-snarf/mbox-snarf-plugin.c src/plugins/quota/quota-storage.c src/plugins/zlib/zlib-plugin.c
diffstat 10 files changed, 67 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/acl/acl-mailbox-list.c	Fri Apr 25 01:29:15 2008 +0300
+++ b/src/plugins/acl/acl-mailbox-list.c	Fri Apr 25 01:31:05 2008 +0300
@@ -387,9 +387,6 @@
 	const char *acl_env, *current_username, *owner_username;
 	bool owner = TRUE;
 
-	if (acl_next_hook_mailbox_list_created != NULL)
-		acl_next_hook_mailbox_list_created(list);
-
 	acl_env = getenv("ACL");
 	i_assert(acl_env != NULL);
 
@@ -437,4 +434,7 @@
 	acl_storage_rights_ctx_init(&alist->rights, backend);
 
 	MODULE_CONTEXT_SET(list, acl_mailbox_list_module, alist);
+
+	if (acl_next_hook_mailbox_list_created != NULL)
+		acl_next_hook_mailbox_list_created(list);
 }
--- a/src/plugins/acl/acl-storage.c	Fri Apr 25 01:29:15 2008 +0300
+++ b/src/plugins/acl/acl-storage.c	Fri Apr 25 01:31:05 2008 +0300
@@ -160,9 +160,6 @@
 	struct acl_mail_storage *astorage;
 	struct acl_backend *backend;
 
-	if (acl_next_hook_mail_storage_created != NULL)
-		acl_next_hook_mail_storage_created(storage);
-
 	astorage = p_new(storage->pool, struct acl_mail_storage, 1);
 	astorage->module_ctx.super = storage->v;
 	storage->v.destroy = acl_storage_destroy;
@@ -173,5 +170,8 @@
 	acl_storage_rights_ctx_init(&astorage->rights, backend);
 
 	MODULE_CONTEXT_SET(storage, acl_storage_module, astorage);
+
+	if (acl_next_hook_mail_storage_created != NULL)
+		acl_next_hook_mail_storage_created(storage);
 }
 
--- a/src/plugins/convert/convert-plugin.c	Fri Apr 25 01:29:15 2008 +0300
+++ b/src/plugins/convert/convert-plugin.c	Fri Apr 25 01:31:05 2008 +0300
@@ -12,19 +12,12 @@
 static void (*convert_next_hook_mail_namespaces_created)
 	(struct mail_namespace *namespaces);
 
-static void
-convert_hook_mail_namespaces_created(struct mail_namespace *namespaces)
+static void convert_mail_storage(struct mail_namespace *namespaces,
+				 const char *convert_mail)
 {
-	const char *convert_mail, *str;
+	const char *str;
 	struct convert_settings set;
 
-	if (convert_next_hook_mail_namespaces_created != NULL)
-		convert_next_hook_mail_namespaces_created(namespaces);
-
-	convert_mail = getenv("CONVERT_MAIL");
-	if (convert_mail == NULL)
-		return;
-
 	memset(&set, 0, sizeof(set));
 	set.user = getenv("USER");
 	if (set.user == NULL)
@@ -44,6 +37,19 @@
 		i_fatal("Mailbox conversion failed, exiting");
 }
 
+static void
+convert_hook_mail_namespaces_created(struct mail_namespace *namespaces)
+{
+	const char *convert_mail;
+
+	convert_mail = getenv("CONVERT_MAIL");
+	if (convert_mail != NULL)
+		convert_mail_storage(namespaces, convert_mail);
+
+	if (convert_next_hook_mail_namespaces_created != NULL)
+		convert_next_hook_mail_namespaces_created(namespaces);
+}
+
 void convert_plugin_init(void)
 {
 	convert_next_hook_mail_namespaces_created =
--- a/src/plugins/expire/expire-plugin.c	Fri Apr 25 01:29:15 2008 +0300
+++ b/src/plugins/expire/expire-plugin.c	Fri Apr 25 01:31:05 2008 +0300
@@ -271,15 +271,15 @@
 {
 	union mail_storage_module_context *xpr_storage;
 
-	if (expire.next_hook_mail_storage_created != NULL)
-		expire.next_hook_mail_storage_created(storage);
-
 	xpr_storage =
 		p_new(storage->pool, union mail_storage_module_context, 1);
 	xpr_storage->super = storage->v;
 	storage->v.mailbox_open = expire_mailbox_open;
 
 	MODULE_CONTEXT_SET_SELF(storage, expire_storage_module, xpr_storage);
+
+	if (expire.next_hook_mail_storage_created != NULL)
+		expire.next_hook_mail_storage_created(storage);
 }
 
 void expire_plugin_init(void)
--- a/src/plugins/fts/fts-storage.c	Fri Apr 25 01:29:15 2008 +0300
+++ b/src/plugins/fts/fts-storage.c	Fri Apr 25 01:31:05 2008 +0300
@@ -659,17 +659,9 @@
 	return ret;
 }
 
-void fts_mailbox_opened(struct mailbox *box)
+static void fts_mailbox_init(struct mailbox *box, const char *env)
 {
 	struct fts_mailbox *fbox;
-	const char *env;
-
-	if (fts_next_hook_mailbox_opened != NULL)
-		fts_next_hook_mailbox_opened(box);
-
-	env = getenv("FTS");
-	if (env == NULL)
-		return;
 
 	fbox = i_new(struct fts_mailbox, 1);
 	fbox->env = env;
@@ -686,3 +678,15 @@
 
 	MODULE_CONTEXT_SET(box, fts_storage_module, fbox);
 }
+
+void fts_mailbox_opened(struct mailbox *box)
+{
+	const char *env;
+
+	env = getenv("FTS");
+	if (env != NULL)
+		fts_mailbox_init(box, env);
+
+	if (fts_next_hook_mailbox_opened != NULL)
+		fts_next_hook_mailbox_opened(box);
+}
--- a/src/plugins/lazy-expunge/lazy-expunge-plugin.c	Fri Apr 25 01:29:15 2008 +0300
+++ b/src/plugins/lazy-expunge/lazy-expunge-plugin.c	Fri Apr 25 01:31:05 2008 +0300
@@ -472,7 +472,7 @@
 	return 0;
 }
 
-static void lazy_expunge_mail_storage_created(struct mail_storage *storage)
+static void lazy_expunge_mail_storage_init(struct mail_storage *storage)
 {
 	struct lazy_expunge_mailbox_list *llist =
 		LAZY_EXPUNGE_LIST_CONTEXT(storage->list);
@@ -480,13 +480,6 @@
 	const char *const *p;
 	unsigned int i;
 
-	if (lazy_expunge_next_hook_mail_storage_created != NULL)
-		lazy_expunge_next_hook_mail_storage_created(storage);
-
-	/* only maildir supported for now */
-	if (strcmp(storage->name, "maildir") != 0)
-		return;
-
 	/* if this is one of our internal storages, mark it as such before
 	   quota plugin sees it */
 	p = t_strsplit_spaces(getenv("LAZY_EXPUNGE"), " ");
@@ -506,6 +499,16 @@
 	MODULE_CONTEXT_SET(storage, lazy_expunge_mail_storage_module, lstorage);
 }
 
+static void lazy_expunge_mail_storage_created(struct mail_storage *storage)
+{
+	/* only maildir supported for now */
+	if (strcmp(storage->name, "maildir") == 0)
+		lazy_expunge_mail_storage_init(storage);
+
+	if (lazy_expunge_next_hook_mail_storage_created != NULL)
+		lazy_expunge_next_hook_mail_storage_created(storage);
+}
+
 static void lazy_expunge_mailbox_list_created(struct mailbox_list *list)
 {
 	struct lazy_expunge_mailbox_list *llist;
--- a/src/plugins/mail-log/mail-log-plugin.c	Fri Apr 25 01:29:15 2008 +0300
+++ b/src/plugins/mail-log/mail-log-plugin.c	Fri Apr 25 01:31:05 2008 +0300
@@ -499,29 +499,29 @@
 {
 	union mail_storage_module_context *lstorage;
 
-	if (mail_log_next_hook_mail_storage_created != NULL)
-		mail_log_next_hook_mail_storage_created(storage);
-
 	lstorage = p_new(storage->pool, union mail_storage_module_context, 1);
 	lstorage->super = storage->v;
 	storage->v.mailbox_open = mail_log_mailbox_open;
 
 	MODULE_CONTEXT_SET_SELF(storage, mail_log_storage_module, lstorage);
+
+	if (mail_log_next_hook_mail_storage_created != NULL)
+		mail_log_next_hook_mail_storage_created(storage);
 }
 
 static void mail_log_mailbox_list_created(struct mailbox_list *list)
 {
 	union mailbox_list_module_context *llist;
 
-	if (mail_log_next_hook_mailbox_list_created != NULL)
-		mail_log_next_hook_mailbox_list_created(list);
-
 	llist = p_new(list->pool, union mailbox_list_module_context, 1);
 	llist->super = list->v;
 	list->v.delete_mailbox = mail_log_mailbox_list_delete;
 	list->v.rename_mailbox = mail_log_mailbox_list_rename;
 
 	MODULE_CONTEXT_SET_SELF(list, mail_log_mailbox_list_module, llist);
+
+	if (mail_log_next_hook_mailbox_list_created != NULL)
+		mail_log_next_hook_mailbox_list_created(list);
 }
 
 static enum mail_log_field mail_log_parse_fields(const char *str)
--- a/src/plugins/mbox-snarf/mbox-snarf-plugin.c	Fri Apr 25 01:29:15 2008 +0300
+++ b/src/plugins/mbox-snarf/mbox-snarf-plugin.c	Fri Apr 25 01:31:05 2008 +0300
@@ -164,9 +164,6 @@
 {
 	struct mbox_snarf_mail_storage *mstorage;
 
-	if (mbox_snarf_next_hook_mail_storage_created != NULL)
-		mbox_snarf_next_hook_mail_storage_created(storage);
-
 	mstorage = p_new(storage->pool, struct mbox_snarf_mail_storage, 1);
 	mstorage->snarf_inbox_path =
 		p_strdup(storage->pool, home_expand(getenv("MBOX_SNARF")));
@@ -174,6 +171,9 @@
 	storage->v.mailbox_open = mbox_snarf_mailbox_open;
 
 	MODULE_CONTEXT_SET(storage, mbox_snarf_storage_module, mstorage);
+
+	if (mbox_snarf_next_hook_mail_storage_created != NULL)
+		mbox_snarf_next_hook_mail_storage_created(storage);
 }
 
 void mbox_snarf_plugin_init(void)
--- a/src/plugins/quota/quota-storage.c	Fri Apr 25 01:29:15 2008 +0300
+++ b/src/plugins/quota/quota-storage.c	Fri Apr 25 01:31:05 2008 +0300
@@ -454,9 +454,6 @@
 	struct quota_mailbox_list *qlist = QUOTA_LIST_CONTEXT(storage->list);
 	union mail_storage_module_context *qstorage;
 
-	if (quota_next_hook_mail_storage_created != NULL)
-		quota_next_hook_mail_storage_created(storage);
-
 	qlist->storage = storage;
 
 	qstorage = p_new(storage->pool, union mail_storage_module_context, 1);
@@ -471,18 +468,21 @@
 		/* register to user's quota roots */
 		quota_add_user_storage(quota_set, storage);
 	}
+
+	if (quota_next_hook_mail_storage_created != NULL)
+		quota_next_hook_mail_storage_created(storage);
 }
 
 void quota_mailbox_list_created(struct mailbox_list *list)
 {
 	struct quota_mailbox_list *qlist;
 
-	if (quota_next_hook_mailbox_list_created != NULL)
-		quota_next_hook_mailbox_list_created(list);
-
 	qlist = p_new(list->pool, struct quota_mailbox_list, 1);
 	qlist->module_ctx.super = list->v;
 	list->v.delete_mailbox = quota_mailbox_list_delete;
 
 	MODULE_CONTEXT_SET(list, quota_mailbox_list_module, qlist);
+
+	if (quota_next_hook_mailbox_list_created != NULL)
+		quota_next_hook_mailbox_list_created(list);
 }
--- a/src/plugins/zlib/zlib-plugin.c	Fri Apr 25 01:29:15 2008 +0300
+++ b/src/plugins/zlib/zlib-plugin.c	Fri Apr 25 01:31:05 2008 +0300
@@ -140,14 +140,14 @@
 {
 	union mail_storage_module_context *qstorage;
 
-	if (zlib_next_hook_mail_storage_created != NULL)
-		zlib_next_hook_mail_storage_created(storage);
-
 	qstorage = p_new(storage->pool, union mail_storage_module_context, 1);
 	qstorage->super = storage->v;
 	storage->v.mailbox_open = zlib_mailbox_open;
 
 	MODULE_CONTEXT_SET_SELF(storage, zlib_storage_module, qstorage);
+
+	if (zlib_next_hook_mail_storage_created != NULL)
+		zlib_next_hook_mail_storage_created(storage);
 }
 
 void zlib_plugin_init(void)