]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mbox: CREATE mailbox/ now mkdir()s it.
authorTimo Sirainen <tss@iki.fi>
Sun, 9 Mar 2003 09:56:05 +0000 (11:56 +0200)
committerTimo Sirainen <tss@iki.fi>
Sun, 9 Mar 2003 09:56:05 +0000 (11:56 +0200)
--HG--
branch : HEAD

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

index 0139daaea7eb329add9b1c7b8b4bc07e36286749..c45714f659e21059057ddb083c9e979e39f9a514 100644 (file)
@@ -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;
        }
index 4f6d55f65fa10cd8733057c97ce61ef63f4bf073..1c6bd459d69bdb5115583154c6cbea75ebdafef1 100644 (file)
@@ -298,7 +298,7 @@ maildir_open_mailbox(struct mail_storage *storage,
 }
 
 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 @@ static int maildir_create_mailbox(struct mail_storage *storage,
                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;
index 1ba6f495b54ccdb2c9d00521eea7f956bb59426b..9ce2d4e06d43aae319fe6f9bfb3e03e18d16ce20 100644 (file)
@@ -408,7 +408,8 @@ mbox_open_mailbox(struct mail_storage *storage,
        }
 }
 
-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 @@ static int mbox_create_mailbox(struct mail_storage *storage, const char *name)
        }
 
        /* 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 @@ static int mbox_create_mailbox(struct mail_storage *storage, const char *name)
                                path);
                        return FALSE;
                }
+
+               if (only_hierarchy) {
+                       /* wanted to create only the directory */
+                       return TRUE;
+               }
        }
 
        /* create the mailbox file */
index a6653252811ee41771d256fc7254d6515dd13533..93e8c92d725355a33c27adaeb88abc43648b7ff7 100644 (file)
@@ -145,8 +145,11 @@ struct mail_storage {
                                        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. */