dovecot: Fixes to handling INBOX with non-INBOX namespaces.

dovecot at dovecot.org dovecot at dovecot.org
Sun Jan 6 00:48:21 EET 2008


details:   http://hg.dovecot.org/dovecot/rev/d5dd0841b2db
changeset: 7113:d5dd0841b2db
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Jan 06 00:48:18 2008 +0200
description:
Fixes to handling INBOX with non-INBOX namespaces.

diffstat:

3 files changed, 29 insertions(+), 10 deletions(-)
src/lib-storage/index/maildir/maildir-storage.c |   26 +++++++++++++++++++----
src/lib-storage/list/mailbox-list-maildir.c     |   10 ++++----
src/lib-storage/mailbox-list.c                  |    3 +-

diffs (97 lines):

diff -r bffc8788eb94 -r d5dd0841b2db src/lib-storage/index/maildir/maildir-storage.c
--- 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 @@ maildir_get_list_settings(struct mailbox
 		*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 @@ maildir_create(struct mail_storage *_sto
 	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 @@ maildir_list_delete_mailbox(struct mailb
 {
 	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
@@ -728,6 +732,20 @@ maildir_list_delete_mailbox(struct mailb
 			return -1;
 		}
 		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);
diff -r bffc8788eb94 -r d5dd0841b2db src/lib-storage/list/mailbox-list-maildir.c
--- 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 @@ maildir_list_get_path(struct mailbox_lis
 		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 @@ maildir_list_get_mailbox_name_status(str
 	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;
 	}
diff -r bffc8788eb94 -r d5dd0841b2db src/lib-storage/mailbox-list.c
--- 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 @@ int mailbox_list_delete_mailbox(struct m
 				       "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;


More information about the dovecot-cvs mailing list