changeset 1290:9562ba6af1f1 HEAD

mbox: CREATE mailbox/ now mkdir()s it.
author Timo Sirainen <tss@iki.fi>
date Sun, 09 Mar 2003 11:56:05 +0200
parents c6c7867b2f6f
children ddb4ebbf32a9
files src/imap/cmd-create.c src/lib-storage/index/maildir/maildir-storage.c src/lib-storage/index/mbox/mbox-storage.c src/lib-storage/mail-storage.h
diffstat 4 files changed, 31 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/imap/cmd-create.c	Sun Mar 09 11:01:01 2003 +0200
+++ b/src/imap/cmd-create.c	Sun Mar 09 11:56:05 2003 +0200
@@ -6,26 +6,29 @@
 int cmd_create(struct client *client)
 {
 	const char *mailbox;
-	int ignore;
+	int only_hiearchy;
+	size_t len;
 
 	/* <mailbox> */
 	if (!client_read_string_args(client, 1, &mailbox))
 		return FALSE;
 
-	ignore = mailbox[strlen(mailbox)-1] == client->storage->hierarchy_sep;
-	if (ignore) {
+	len = strlen(mailbox);
+	if (mailbox[len-1] != client->storage->hierarchy_sep)
+		only_hiearchy = FALSE;
+	else {
 		/* name ends with hierarchy separator - client is just
 		   informing us that it wants to create a mailbox under
-		   this name. we don't need that information, but verify
-		   that the mailbox name is valid */
-		mailbox = t_strndup(mailbox, strlen(mailbox)-1);
+		   this name. */
+                only_hiearchy = TRUE;
+		mailbox = t_strndup(mailbox, len-1);
 	}
 
-	if (!client_verify_mailbox_name(client, mailbox, FALSE, !ignore))
+	if (!client_verify_mailbox_name(client, mailbox, FALSE, TRUE))
 		return TRUE;
 
-	if (!ignore &&
-	    !client->storage->create_mailbox(client->storage, mailbox)) {
+	if (!client->storage->create_mailbox(client->storage, mailbox,
+					     only_hiearchy)) {
 		client_send_storage_error(client);
 		return TRUE;
 	}
--- a/src/lib-storage/index/maildir/maildir-storage.c	Sun Mar 09 11:01:01 2003 +0200
+++ b/src/lib-storage/index/maildir/maildir-storage.c	Sun Mar 09 11:56:05 2003 +0200
@@ -298,7 +298,7 @@
 }
 
 static int maildir_create_mailbox(struct mail_storage *storage,
-				  const char *name)
+				  const char *name, int only_hierarchy)
 {
 	const char *path;
 
@@ -310,6 +310,11 @@
 		return FALSE;
 	}
 
+	if (only_hierarchy) {
+		/* no need to do anything */
+		return TRUE;
+	}
+
 	path = maildir_get_path(storage, name);
 	if (create_maildir(path, FALSE))
 		return TRUE;
--- a/src/lib-storage/index/mbox/mbox-storage.c	Sun Mar 09 11:01:01 2003 +0200
+++ b/src/lib-storage/index/mbox/mbox-storage.c	Sun Mar 09 11:56:05 2003 +0200
@@ -408,7 +408,8 @@
 	}
 }
 
-static int mbox_create_mailbox(struct mail_storage *storage, const char *name)
+static int mbox_create_mailbox(struct mail_storage *storage, const char *name,
+			       int only_hierarchy)
 {
 	const char *path, *p;
 	struct stat st;
@@ -444,7 +445,7 @@
 	}
 
 	/* create the hierarchy if needed */
-	p = strrchr(path, '/');
+	p = only_hierarchy ? path + strlen(path) : strrchr(path, '/');
 	if (p != NULL) {
 		if (mkdir_parents(t_strdup_until(path, p)) < 0) {
 			mail_storage_set_critical(storage,
@@ -452,6 +453,11 @@
 				path);
 			return FALSE;
 		}
+
+		if (only_hierarchy) {
+			/* wanted to create only the directory */
+			return TRUE;
+		}
 	}
 
 	/* create the mailbox file */
--- a/src/lib-storage/mail-storage.h	Sun Mar 09 11:01:01 2003 +0200
+++ b/src/lib-storage/mail-storage.h	Sun Mar 09 11:56:05 2003 +0200
@@ -145,8 +145,11 @@
 					const char *name,
 					int readonly, int fast);
 
-	/* name is allowed to contain multiple new hierarchy levels. */
-	int (*create_mailbox)(struct mail_storage *storage, const char *name);
+	/* name is allowed to contain multiple new hierarchy levels.
+	   If only_hierarchy is TRUE, the mailbox itself isn't created, just
+	   the hiearchy structure (if needed). */
+	int (*create_mailbox)(struct mail_storage *storage, const char *name,
+			      int only_hierarchy);
 
 	/* Only the specified mailbox is deleted, ie. folders under the
 	   specified mailbox must not be deleted. */