]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Added a way to create plugins that forcibly hook into mail storage.
authorTimo Sirainen <tss@iki.fi>
Tue, 19 Mar 2013 17:08:17 +0000 (19:08 +0200)
committerTimo Sirainen <tss@iki.fi>
Tue, 19 Mar 2013 17:08:17 +0000 (19:08 +0200)
Mostly meant for doveadm_sieve plugin.

src/lib-storage/mail-storage-hooks.c
src/lib-storage/mail-storage-hooks.h
src/lib-storage/mail-storage-private.h

index d4630f11225611246a97d08dcf912cdf3c75bc93..fd8d9a6a30e6ed18719c7a8f6392afbdd96a1434 100644 (file)
@@ -12,6 +12,7 @@
 struct mail_storage_module_hooks {
        struct module *module;
        const struct mail_storage_hooks *hooks;
+       bool forced;
 };
 
 struct hook_stack {
@@ -41,7 +42,8 @@ static ARRAY(const struct mail_storage_hooks *) internal_hooks = ARRAY_INIT;
 
 void mail_storage_hooks_init(void)
 {
-       i_array_init(&module_hooks, 32);
+       if (!array_is_created(&module_hooks))
+               i_array_init(&module_hooks, 32);
        i_array_init(&internal_hooks, 8);
 }
 
@@ -60,9 +62,23 @@ void mail_storage_hooks_add(struct module *module,
        new_hook.module = module;
        new_hook.hooks = hooks;
 
+       /* allow adding hooks before mail_storage_hooks_init() */
+       if (!array_is_created(&module_hooks))
+               i_array_init(&module_hooks, 32);
        array_append(&module_hooks, &new_hook, 1);
 }
 
+void mail_storage_hooks_add_forced(struct module *module,
+                                  const struct mail_storage_hooks *hooks)
+{
+       struct mail_storage_module_hooks *hook;
+
+       mail_storage_hooks_add(module, hooks);
+       hook = array_idx_modifiable(&module_hooks,
+                                   array_count(&module_hooks)-1);
+       hook->forced = TRUE;
+}
+
 void mail_storage_hooks_remove(const struct mail_storage_hooks *hooks)
 {
        const struct mail_storage_module_hooks *module_hook;
@@ -125,7 +141,7 @@ static void mail_user_add_plugin_hooks(struct mail_user *user)
        plugins = t_strsplit_spaces(user->set->mail_plugins, ", ");
        array_foreach(&module_hooks, module_hook) {
                name = module_get_plugin_name(module_hook->module);
-               if (str_array_find(plugins, name))
+               if (str_array_find(plugins, name) || module_hook->forced)
                        array_append(&tmp_hooks, module_hook, 1);
        }
 
index ae8583e91d2bc909e747ee4779de879b0996683e..0cba2a08f4d7620d3bc8be55c6fab2671b4f4324 100644 (file)
@@ -25,6 +25,10 @@ void mail_storage_hooks_deinit(void);
 
 void mail_storage_hooks_add(struct module *module,
                            const struct mail_storage_hooks *hooks);
+/* Add hooks to this plugin regardless of whether it exists in user's
+   mail_plugins setting. */
+void mail_storage_hooks_add_forced(struct module *module,
+                                  const struct mail_storage_hooks *hooks);
 void mail_storage_hooks_remove(const struct mail_storage_hooks *hooks);
 
 void mail_storage_hooks_add_internal(const struct mail_storage_hooks *hooks);
index 3c31ef09972ac605737df5e46ac9e1f0c20d29de..a1ffe251e0aac569f4ee1386298661cc7a17b5a3 100644 (file)
@@ -644,6 +644,9 @@ int mailbox_create_fd(struct mailbox *box, const char *path, int flags,
 unsigned int mail_storage_get_lock_timeout(struct mail_storage *storage,
                                           unsigned int secs);
 void mail_storage_free_binary_cache(struct mail_storage *storage);
+int mailbox_attribute_value_to_string(struct mail_storage *storage,
+                                     const struct mail_attribute_value *value,
+                                     const char **str_r);
 
 enum mail_index_open_flags
 mail_storage_settings_to_index_flags(const struct mail_storage_settings *set);