dovecot-2.0: sdbox: Added support for autodetection.

dovecot at dovecot.org dovecot at dovecot.org
Mon Dec 19 09:13:10 EET 2011


details:   http://hg.dovecot.org/dovecot-2.0/rev/e1fc2ab5e9f9
changeset: 13002:e1fc2ab5e9f9
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Dec 19 09:12:58 2011 +0200
description:
sdbox: Added support for autodetection.

diffstat:

 src/lib-storage/index/dbox-single/sdbox-storage.c |  63 +++++++++++++++++++++-
 1 files changed, 60 insertions(+), 3 deletions(-)

diffs (92 lines):

diff -r 4ea24cabfd88 -r e1fc2ab5e9f9 src/lib-storage/index/dbox-single/sdbox-storage.c
--- a/src/lib-storage/index/dbox-single/sdbox-storage.c	Fri Dec 16 13:12:04 2011 +0200
+++ b/src/lib-storage/index/dbox-single/sdbox-storage.c	Mon Dec 19 09:12:58 2011 +0200
@@ -28,6 +28,63 @@
 	return &storage->storage.storage;
 }
 
+static const char *
+sdbox_storage_find_root_dir(const struct mail_namespace *ns)
+{
+	bool debug = ns->mail_set->mail_debug;
+	const char *home, *path;
+
+	if (mail_user_get_home(ns->owner, &home) > 0) {
+		path = t_strconcat(home, "/sdbox", NULL);
+		if (access(path, R_OK|W_OK|X_OK) == 0) {
+			if (debug)
+				i_debug("sdbox: root exists (%s)", path);
+			return path;
+		} 
+		if (debug)
+			i_debug("sdbox: access(%s, rwx): failed: %m", path);
+	}
+	return NULL;
+}
+
+static bool sdbox_storage_autodetect(const struct mail_namespace *ns,
+				     struct mailbox_list_settings *set)
+{
+	bool debug = ns->mail_set->mail_debug;
+	struct stat st;
+	const char *path, *root_dir;
+
+	if (set->root_dir != NULL)
+		root_dir = set->root_dir;
+	else {
+		root_dir = sdbox_storage_find_root_dir(ns);
+		if (root_dir == NULL) {
+			if (debug)
+				i_debug("sdbox: couldn't find root dir");
+			return FALSE;
+		}
+	}
+
+	/* NOTE: this check works for mdbox as well. we'll rely on the
+	   autodetect ordering to catch mdbox before we get here. */
+	path = t_strconcat(root_dir, "/"DBOX_MAILBOX_DIR_NAME, NULL);
+	if (stat(path, &st) < 0) {
+		if (debug)
+			i_debug("sdbox autodetect: stat(%s) failed: %m", path);
+		return FALSE;
+	}
+
+	if (!S_ISDIR(st.st_mode)) {
+		if (debug)
+			i_debug("sdbox autodetect: %s not a directory", path);
+		return FALSE;
+	}
+
+	set->root_dir = root_dir;
+	dbox_storage_get_list_settings(ns, set);
+	return TRUE;
+}
+
 static struct mailbox *
 sdbox_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
 		    const char *name, enum mailbox_flags flags)
@@ -339,7 +396,7 @@
 		dbox_storage_destroy,
 		NULL,
 		dbox_storage_get_list_settings,
-		NULL,
+		sdbox_storage_autodetect,
 		sdbox_mailbox_alloc,
 		NULL
 	}
@@ -350,13 +407,13 @@
 	.class_flags = 0,
 
 	.v = {
-                NULL,
+		NULL,
 		sdbox_storage_alloc,
 		dbox_storage_create,
 		dbox_storage_destroy,
 		NULL,
 		dbox_storage_get_list_settings,
-		NULL,
+		sdbox_storage_autodetect,
 		sdbox_mailbox_alloc,
 		NULL
 	}


More information about the dovecot-cvs mailing list