From ae2bf8e61d24887e8cb1398258c01ab8b40c3cdc Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Sun, 9 Mar 2003 11:56:05 +0200 Subject: [PATCH] mbox: CREATE mailbox/ now mkdir()s it. --HG-- branch : HEAD --- src/imap/cmd-create.c | 21 +++++++++++-------- .../index/maildir/maildir-storage.c | 7 ++++++- src/lib-storage/index/mbox/mbox-storage.c | 10 +++++++-- src/lib-storage/mail-storage.h | 7 +++++-- 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/imap/cmd-create.c b/src/imap/cmd-create.c index 0139daaea7..c45714f659 100644 --- a/src/imap/cmd-create.c +++ b/src/imap/cmd-create.c @@ -6,26 +6,29 @@ int cmd_create(struct client *client) { const char *mailbox; - int ignore; + int only_hiearchy; + size_t len; /* */ 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; } diff --git a/src/lib-storage/index/maildir/maildir-storage.c b/src/lib-storage/index/maildir/maildir-storage.c index 4f6d55f65f..1c6bd459d6 100644 --- a/src/lib-storage/index/maildir/maildir-storage.c +++ b/src/lib-storage/index/maildir/maildir-storage.c @@ -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; diff --git a/src/lib-storage/index/mbox/mbox-storage.c b/src/lib-storage/index/mbox/mbox-storage.c index 1ba6f495b5..9ce2d4e06d 100644 --- a/src/lib-storage/index/mbox/mbox-storage.c +++ b/src/lib-storage/index/mbox/mbox-storage.c @@ -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 */ diff --git a/src/lib-storage/mail-storage.h b/src/lib-storage/mail-storage.h index a665325281..93e8c92d72 100644 --- a/src/lib-storage/mail-storage.h +++ b/src/lib-storage/mail-storage.h @@ -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. */ -- 2.47.3