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;
}
}
static int maildir_create_mailbox(struct mail_storage *storage,
- const char *name)
+ const char *name, int only_hierarchy)
{
const char *path;
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;
}
}
-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;
}
/* 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,
path);
return FALSE;
}
+
+ if (only_hierarchy) {
+ /* wanted to create only the directory */
+ return TRUE;
+ }
}
/* create the mailbox file */
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. */