changeset 7113:d5dd0841b2db HEAD

Fixes to handling INBOX with non-INBOX namespaces.
author Timo Sirainen <tss@iki.fi>
date Sun, 06 Jan 2008 00:48:18 +0200
parents bffc8788eb94
children 9bbe74f6f2a9
files src/lib-storage/index/maildir/maildir-storage.c src/lib-storage/list/mailbox-list-maildir.c src/lib-storage/mailbox-list.c
diffstat 3 files changed, 29 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/maildir/maildir-storage.c	Sun Jan 06 00:19:10 2008 +0200
+++ b/src/lib-storage/index/maildir/maildir-storage.c	Sun Jan 06 00:48:18 2008 +0200
@@ -119,8 +119,6 @@
 		*error_r = "Root mail directory not given";
 		return -1;
 	}
-	if (list_set->inbox_path == NULL)
-		list_set->inbox_path = list_set->root_dir;
 	return 0;
 }
 
@@ -200,7 +198,13 @@
 	list_set.mail_storage_flags = &_storage->flags;
 	list_set.lock_method = &_storage->lock_method;
 
-	/* normally the maildir is created in verify_inbox() */
+	if (list_set.inbox_path == NULL &&
+	    strcmp(layout, MAILDIR_PLUSPLUS_DRIVER_NAME) == 0 &&
+	    (_storage->ns->flags & NAMESPACE_FLAG_INBOX) != 0) {
+		/* Maildir++ INBOX is the Maildir base itself */
+		list_set.inbox_path = list_set.root_dir;
+	}
+
 	if ((flags & MAIL_STORAGE_FLAG_NO_AUTOCREATE) != 0) {
 		if (stat(list_set.root_dir, &st) < 0) {
 			if (errno != ENOENT) {
@@ -699,7 +703,7 @@
 {
 	struct maildir_storage *storage = MAILDIR_LIST_CONTEXT(list);
 	struct stat st;
-	const char *src, *dest;
+	const char *src, *dest, *base;
 	int count;
 
 	/* Make sure the indexes are closed before trying to delete the
@@ -730,6 +734,20 @@
 		return 0;
 	}
 
+	if (strcmp(name, "INBOX") == 0) {
+		/* we shouldn't get this far if this is the actual INBOX.
+		   more likely we're just deleting a namespace/INBOX.
+		   be anyway sure that we don't accidentally delete the entire
+		   maildir (INBOX explicitly configured to maildir root). */
+		base = mailbox_list_get_path(list, NULL,
+					     MAILBOX_LIST_PATH_TYPE_MAILBOX);
+		if (strcmp(base, src) == 0) {
+			mailbox_list_set_error(list, MAIL_ERROR_NOTPOSSIBLE,
+					       "INBOX can't be deleted.");
+			return -1;
+		}
+	}
+
 	dest = maildir_get_unlink_dest(list, name);
 	if (dest == NULL) {
 		/* delete the directory directly without any renaming */
--- a/src/lib-storage/list/mailbox-list-maildir.c	Sun Jan 06 00:19:10 2008 +0200
+++ b/src/lib-storage/list/mailbox-list-maildir.c	Sun Jan 06 00:48:18 2008 +0200
@@ -212,10 +212,8 @@
 		break;
 	}
 
-	if (strcmp(name, "INBOX") == 0) {
-		return _list->set.inbox_path != NULL ?
-			_list->set.inbox_path : _list->set.root_dir;
-	}
+	if (strcmp(name, "INBOX") == 0 && _list->set.inbox_path != NULL)
+		return _list->set.inbox_path;
 
 	return maildir_list_get_dirname_path(_list, _list->set.root_dir, name);
 }
@@ -231,7 +229,9 @@
 	path = mailbox_list_get_path(_list, name,
 				     MAILBOX_LIST_PATH_TYPE_MAILBOX);
 
-	if (strcmp(name, "INBOX") == 0 || stat(path, &st) == 0) {
+	if ((strcmp(name, "INBOX") == 0 &&
+	     (_list->ns->flags & NAMESPACE_FLAG_INBOX) != 0) ||
+	    stat(path, &st) == 0) {
 		*status = MAILBOX_NAME_EXISTS;
 		return 0;
 	}
--- a/src/lib-storage/mailbox-list.c	Sun Jan 06 00:19:10 2008 +0200
+++ b/src/lib-storage/mailbox-list.c	Sun Jan 06 00:48:18 2008 +0200
@@ -392,7 +392,8 @@
 				       "Invalid mailbox name");
 		return -1;
 	}
-	if (strcmp(name, "INBOX") == 0) {
+	if (strcmp(name, "INBOX") == 0 &&
+	    (list->ns->flags & NAMESPACE_FLAG_INBOX) != 0) {
 		mailbox_list_set_error(list, MAIL_ERROR_NOTPOSSIBLE,
 				       "INBOX can't be deleted.");
 		return -1;