diff -r 3ed51d56e2a3 src/doveadm/dsync/dsync-mailbox-tree-sync.c
--- a/src/doveadm/dsync/dsync-mailbox-tree-sync.c	Wed Mar 18 17:10:23 2015 +0200
+++ b/src/doveadm/dsync/dsync-mailbox-tree-sync.c	Thu Mar 19 00:29:34 2015 +0200
@@ -363,6 +363,9 @@
 	const char *full_name;
 	unsigned int prefix_len = node->ns == NULL ? 0 : node->ns->prefix_len;
 
+	if (strcmp(node->name, "INBOX") == 0 && node->parent == &tree->root)
+		return TRUE;
+
 	if (prefix_len == 0)
 		return FALSE;
 
@@ -585,6 +588,14 @@
 	return ts;
 }
 
+static bool sync_node_is_namespace_root(struct dsync_mailbox_tree *tree,
+					struct dsync_mailbox_node *node)
+{
+	if (node == &tree->root)
+		return TRUE;
+	return sync_node_is_namespace_prefix(tree, node);
+}
+
 static bool ATTR_NULL(3, 4)
 sync_rename_lower_ts(struct dsync_mailbox_tree_sync_ctx *ctx,
 		     struct dsync_mailbox_node *local_node1,
@@ -604,6 +615,16 @@
 	   at all. Note that node1 and node2 may be the same node pointers. */
 	i_assert(strcmp(local_node1->name, remote_node2->name) == 0);
 
+	if (sync_node_is_namespace_root(ctx->remote_tree, remote_node1) ||
+	    sync_node_is_namespace_root(ctx->remote_tree, remote_node2) ||
+	    sync_node_is_namespace_root(ctx->local_tree, local_node1) ||
+	    sync_node_is_namespace_root(ctx->local_tree, local_node2)) {
+		local_node1->sync_delayed_guid_change = TRUE;
+		remote_node2->sync_delayed_guid_change = TRUE;
+		*reason_r = "Can't rename namespace prefixes - will be merged later";
+		return FALSE;
+	}
+
 	local_ts = nodes_get_timestamp(local_node1, local_node2);
 	remote_ts = nodes_get_timestamp(remote_node1, remote_node2);
 
@@ -791,14 +812,6 @@
 	return NULL;
 }
 
-static bool sync_node_is_namespace_root(struct dsync_mailbox_tree *tree,
-					struct dsync_mailbox_node *node)
-{
-	if (node == &tree->root)
-		return TRUE;
-	return sync_node_is_namespace_prefix(tree, node);
-}
-
 static bool sync_rename_directory(struct dsync_mailbox_tree_sync_ctx *ctx,
 				  struct dsync_mailbox_node *local_node1,
 				  struct dsync_mailbox_node *remote_node2,
@@ -821,13 +834,6 @@
 		*reason_r = "Directory name paths are equal";
 		return FALSE;
 	}
-	if (sync_node_is_namespace_root(ctx->remote_tree, remote_node1) ||
-	    sync_node_is_namespace_root(ctx->remote_tree, remote_node2) ||
-	    sync_node_is_namespace_root(ctx->local_tree, local_node1) ||
-	    sync_node_is_namespace_root(ctx->local_tree, local_node2)) {
-		*reason_r = "Directory is part of namespace prefix";
-		return FALSE;
-	}
 
 	return sync_rename_lower_ts(ctx, local_node1, remote_node1,
 				    local_node2, remote_node2, reason_r);
@@ -878,8 +884,11 @@
 				    remote_node->existence);
 		}
 
-		if (dsync_mailbox_node_is_dir(local_node) &&
-		    dsync_mailbox_node_is_dir(remote_node)) {
+		/*if (sync_node_is_namespace_root(ctx->remote_tree, remote_node) ||
+		    sync_node_is_namespace_root(ctx->local_tree, local_node))
+			reason = "Skip rename checking for namespace root";
+		else */if (dsync_mailbox_node_is_dir(local_node) &&
+			 dsync_mailbox_node_is_dir(remote_node)) {
 			/* both nodes are directories (or other side is
 			   nonexistent). see if we can match them by their
 			   child mailboxes */
diff -r b28de884c470 src/doveadm/dsync/test-dsync-mailbox-tree-sync.c
--- a/src/doveadm/dsync/test-dsync-mailbox-tree-sync.c	Thu Mar 19 00:38:01 2015 +0200
+++ b/src/doveadm/dsync/test-dsync-mailbox-tree-sync.c	Thu Mar 19 00:39:34 2015 +0200
@@ -181,7 +181,8 @@
 	dsync_mailbox_tree_build_guid_hash(tree1, &dup_node1, &dup_node2);
 	dsync_mailbox_tree_build_guid_hash(tree2, &dup_node1, &dup_node2);
 	ctx = dsync_mailbox_trees_sync_init(tree1, tree2,
-					    DSYNC_MAILBOX_TREES_SYNC_TYPE_TWOWAY, 0);
+					    DSYNC_MAILBOX_TREES_SYNC_TYPE_TWOWAY,
+					    DSYNC_MAILBOX_TREES_SYNC_FLAG_DEBUG);
 	while ((change = dsync_mailbox_trees_sync_next(ctx)) != NULL) {
 	}
 	dsync_mailbox_trees_sync_deinit(&ctx);
@@ -681,6 +682,25 @@
 	test_end();
 }
 
+static void test_dsync_mailbox_tree_sync_renames21(void)
+{
+	struct dsync_mailbox_tree *tree1, *tree2;
+
+	test_begin("dsync mailbox tree sync renames 21");
+	tree1 = dsync_mailbox_tree_init('/', '_');
+	tree2 = dsync_mailbox_tree_init('/', '_');
+
+	node_create(tree1, 1, "INBOX", 0);
+	node_create(tree1, 2, "foo", 0);
+	/* swap INBOX and foo - the INBOX name is important since it's
+	   treated specially */
+	node_create(tree2, 1, "foo", 0);
+	node_create(tree2, 2, "INBOX", 1);
+
+	test_trees(tree1, tree2);
+	test_end();
+}
+
 static void test_dsync_mailbox_tree_sync_random(void)
 {
 	struct dsync_mailbox_tree *tree1, *tree2;
@@ -717,6 +737,7 @@
 		test_dsync_mailbox_tree_sync_renames18,
 		test_dsync_mailbox_tree_sync_renames19,
 		test_dsync_mailbox_tree_sync_renames20,
+		test_dsync_mailbox_tree_sync_renames21,
 		test_dsync_mailbox_tree_sync_random,
 		NULL
 	};
