/* Copyright (C) 2007 Timo Sirainen, LGPLv2.1 */ /* export DOVECOT=~/src/dovecot-1.0.0 gcc -fPIC -shared -Wall -I$DOVECOT -I$DOVECOT/src/lib \ -I$DOVECOT/src/lib-storage -I$DOVECOT/src/lib-mail \ -I$DOVECOT/src/lib-imap -DHAVE_CONFIG_H \ autocreate-plugin.c -o autocreate_plugin.so Usage: plugin { autocreate = Trash autocreate2 = Spam #autocreate3 = ..etc.. autosubscribe = Trash autosubscribe2 = Spam #autosubscribe3 = ..etc.. } */ #include "lib.h" #include "mail-storage-private.h" #include /* defined by imap, pop3, lda */ extern void (*hook_mail_storage_created)(struct mail_storage *storage); const char *autocreate_plugin_version = PACKAGE_VERSION; static void (*autocreate_next_hook_mail_storage_created) (struct mail_storage *storage); static void autocreate_mailboxes(struct mail_storage *storage) { char env_name[20]; const char *env; unsigned int i; i = 1; env = getenv("AUTOCREATE"); while (env != NULL) { (void)mail_storage_mailbox_create(storage, env, FALSE); i_snprintf(env_name, sizeof(env_name), "AUTOCREATE%d", ++i); env = getenv(env_name); } } static void autosubscribe_mailboxes(struct mail_storage *storage) { char env_name[20]; const char *env; unsigned int i; i = 1; env = getenv("AUTOSUBSCRIBE"); while (env != NULL) { (void)mail_storage_set_subscribed(storage, env, TRUE); i_snprintf(env_name, sizeof(env_name), "AUTOSUBSCRIBE%d", ++i); env = getenv(env_name); } } static void autocreate_mail_storage_created(struct mail_storage *storage) { if (autocreate_next_hook_mail_storage_created != NULL) autocreate_next_hook_mail_storage_created(storage); if ((storage->flags & MAIL_STORAGE_FLAG_SHARED_NAMESPACE) == 0) { autocreate_mailboxes(storage); autosubscribe_mailboxes(storage); } } void autocreate_plugin_init(void); void autocreate_plugin_deinit(void); void autocreate_plugin_init(void) { autocreate_next_hook_mail_storage_created = hook_mail_storage_created; hook_mail_storage_created = autocreate_mail_storage_created; } void autocreate_plugin_deinit(void) { hook_mail_storage_created = autocreate_next_hook_mail_storage_created; }