]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
autocreate plugin: If mail_debug=yes, log the reason why mailbox creation fails.
authorTimo Sirainen <tss@iki.fi>
Sun, 30 Nov 2008 22:04:27 +0000 (00:04 +0200)
committerTimo Sirainen <tss@iki.fi>
Sun, 30 Nov 2008 22:04:27 +0000 (00:04 +0200)
--HG--
branch : HEAD

src/plugins/autocreate/autocreate-plugin.c

index d4a8adf25401448f1304fd698cc1fc1e692421e4..57d167e459c4bedc182ccff5ab658c9aaa4a053c 100644 (file)
@@ -12,9 +12,31 @@ const char *autocreate_plugin_version = PACKAGE_VERSION;
 static void (*autocreate_next_hook_mail_namespaces_created)
        (struct mail_namespace *ns);
 
-static void autocreate_mailboxes(struct mail_namespace *namespaces)
+static void
+autocreate_mailbox(struct mail_namespace *namespaces, const char *name)
 {
        struct mail_namespace *ns;
+       const char *str;
+       enum mail_error error;
+
+       ns = mail_namespace_find(namespaces, &name);
+       if (ns == NULL) {
+               if (getenv("DEBUG") != NULL)
+                       i_info("autocreate: No namespace found for %s", name);
+               return;
+       }
+
+       if (mail_storage_mailbox_create(ns->storage, name, FALSE) < 0) {
+               str = mail_storage_get_last_error(ns->storage, &error);
+               if (error != MAIL_ERROR_EXISTS && getenv("DEBUG") != NULL) {
+                       i_info("autocreate: Failed to create mailbox %s: %s",
+                              name, str);
+               }
+       }
+}
+
+static void autocreate_mailboxes(struct mail_namespace *namespaces)
+{
        char env_name[20];
        const char *name;
        unsigned int i;
@@ -22,11 +44,7 @@ static void autocreate_mailboxes(struct mail_namespace *namespaces)
        i = 1;
        name = getenv("AUTOCREATE");
        while (name != NULL) {
-               ns = mail_namespace_find(namespaces, &name);
-               if (ns != NULL) {
-                       (void)mail_storage_mailbox_create(ns->storage,
-                                                         name, FALSE);
-               }
+               autocreate_mailbox(namespaces, name);
 
                i_snprintf(env_name, sizeof(env_name), "AUTOCREATE%d", ++i);
                name = getenv(env_name);