dovecot-2.0: mdbox: Added support for autodetection of ~/mdbox/ ...
dovecot at dovecot.org
dovecot at dovecot.org
Tue Nov 15 18:35:16 EET 2011
details: http://hg.dovecot.org/dovecot-2.0/rev/ddbf1bf524cc
changeset: 12962:ddbf1bf524cc
user: Timo Sirainen <tss at iki.fi>
date: Tue Nov 15 18:31:34 2011 +0200
description:
mdbox: Added support for autodetection of ~/mdbox/ as mdbox storage.
diffstat:
src/lib-storage/index/dbox-multi/mdbox-storage.c | 57 +++++++++++++++++++++++-
1 files changed, 56 insertions(+), 1 deletions(-)
diffs (74 lines):
diff -r bef7acd675f3 -r ddbf1bf524cc src/lib-storage/index/dbox-multi/mdbox-storage.c
--- a/src/lib-storage/index/dbox-multi/mdbox-storage.c Tue Nov 15 18:21:39 2011 +0200
+++ b/src/lib-storage/index/dbox-multi/mdbox-storage.c Tue Nov 15 18:31:34 2011 +0200
@@ -81,6 +81,61 @@
dbox_storage_destroy(_storage);
}
+static const char *
+mdbox_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->user, &home) > 0) {
+ path = t_strconcat(home, "/mdbox", NULL);
+ if (access(path, R_OK|W_OK|X_OK) == 0) {
+ if (debug)
+ i_debug("mdbox: root exists (%s)", path);
+ return path;
+ }
+ if (debug)
+ i_debug("mdbox: access(%s, rwx): failed: %m", path);
+ }
+ return NULL;
+}
+
+static bool mdbox_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 = mdbox_storage_find_root_dir(ns);
+ if (root_dir == NULL) {
+ if (debug)
+ i_debug("mdbox: couldn't find root dir");
+ return FALSE;
+ }
+ }
+
+ path = t_strconcat(root_dir, "/"MDBOX_GLOBAL_DIR_NAME, NULL);
+ if (stat(path, &st) < 0) {
+ if (debug)
+ i_debug("mdbox autodetect: stat(%s) failed: %m", path);
+ return FALSE;
+ }
+
+ if (!S_ISDIR(st.st_mode)) {
+ if (debug)
+ i_debug("mdbox autodetect: %s not a directory", path);
+ return FALSE;
+ }
+
+ set->root_dir = root_dir;
+ dbox_storage_get_list_settings(ns, set);
+ return TRUE;
+}
+
struct mailbox *
mdbox_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
const char *name, enum mailbox_flags flags)
@@ -386,7 +441,7 @@
mdbox_storage_destroy,
NULL,
dbox_storage_get_list_settings,
- NULL,
+ mdbox_storage_autodetect,
mdbox_mailbox_alloc,
mdbox_purge
}
More information about the dovecot-cvs
mailing list