dovecot-2.0: mail_full_filesystem_access=yes: Replace absolute p...

dovecot at dovecot.org dovecot at dovecot.org
Thu Feb 18 06:44:56 EET 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/2c994f2f1ce6
changeset: 10743:2c994f2f1ce6
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Feb 18 06:44:54 2010 +0200
description:
mail_full_filesystem_access=yes: Replace absolute path with mailbox name whenever possible.
For example "foo", "~/mail/foo" and "~user/mail/foo" can all point to the
same "foo" mailbox. When accessing it via "foo", it may have different index
settings and such, so convert the other forms to it whenever possible.

diffstat:

 src/lib-storage/mailbox-list.c |  59 ++++++++++++++++++++++-------
 1 files changed, 44 insertions(+), 15 deletions(-)

diffs (77 lines):

diff -r 1b38bf29ac40 -r 2c994f2f1ce6 src/lib-storage/mailbox-list.c
--- a/src/lib-storage/mailbox-list.c	Thu Feb 18 06:20:38 2010 +0200
+++ b/src/lib-storage/mailbox-list.c	Thu Feb 18 06:44:54 2010 +0200
@@ -912,29 +912,58 @@
 	return type;
 }
 
+static bool
+mailbox_list_try_get_home_path(struct mailbox_list *list, const char **name)
+{
+	if ((*name)[1] == '/') {
+		/* ~/dir - use the configured home directory */
+		if (mail_user_try_home_expand(list->ns->user, name) < 0)
+			return FALSE;
+	} else {
+		/* ~otheruser/dir - assume we're using system users */
+		if (home_try_expand(name) < 0)
+			return FALSE;
+	}
+	return TRUE;
+}
+
 bool mailbox_list_try_get_absolute_path(struct mailbox_list *list,
 					const char **name)
 {
+	const char *root_dir, *path, *mailbox_name;
+	unsigned int len;
+
 	if (!list->mail_set->mail_full_filesystem_access)
 		return FALSE;
 
-	if (**name == '/')
-		return TRUE;
-	if (**name != '~')
-		return FALSE;
+	if (**name == '~') {
+		/* try to expand home directory */
+		if (!mailbox_list_try_get_home_path(list, name)) {
+			/* fallback to using actual "~name" mailbox */
+			return FALSE;
+		}
+	} else {
+		if (**name != '/')
+			return FALSE;
+	}
 
-	/* try to expand home directory */
-	if ((*name)[1] == '/') {
-		/* ~/dir - use the configured home directory */
-		if (mail_user_try_home_expand(list->ns->user, name) == 0)
-			return TRUE;
-	} else {
-		/* ~otheruser/dir - assume we're using system users */
-		if (home_try_expand(name) == 0)
-			return TRUE;
+	/* okay, we have an absolute path now. but check first if it points to
+	   same directory as one of our regular mailboxes. */
+	root_dir = mailbox_list_get_path(list, NULL,
+					 MAILBOX_LIST_PATH_TYPE_MAILBOX);
+	len = strlen(root_dir);
+	if (strncmp(root_dir, *name, len) == 0 && (*name)[len] == '/') {
+		mailbox_name = *name + len + 1;
+		path = mailbox_list_get_path(list, mailbox_name,
+					     MAILBOX_LIST_PATH_TYPE_MAILBOX);
+		if (strcmp(path, *name) == 0) {
+			/* yeah, we can replace the full path with mailbox
+			   name. this way we can use indexes. */
+			*name = mailbox_name;
+			return FALSE;
+		}
 	}
-	/* fallback to using ~dir */
-	return FALSE;
+	return TRUE;
 }
 
 int mailbox_list_create_parent_dir(struct mailbox_list *list,


More information about the dovecot-cvs mailing list