8
8
bool cmd_create(struct client_command_context *cmd)
10
enum mailbox_name_status status;
11
10
struct mail_namespace *ns;
12
const char *mailbox, *storage_name;
11
const char *mailbox, *orig_mailbox;
13
12
struct mailbox *box;
18
17
if (!client_read_string_args(cmd, 1, &mailbox))
21
ns = client_find_namespace(cmd, mailbox, &storage_name, NULL);
20
orig_mailbox = mailbox;
21
ns = client_find_namespace(cmd, &mailbox);
25
len = strlen(mailbox);
26
if (len == 0 || mailbox[len-1] != ns->sep)
25
len = strlen(orig_mailbox);
26
if (len == 0 || orig_mailbox[len-1] != mail_namespace_get_sep(ns))
28
else if (*storage_name == '\0') {
29
client_send_tagline(cmd, "NO ["IMAP_RESP_CODE_ALREADYEXISTS
30
"] Namespace already exists.");
33
29
/* name ends with hierarchy separator - client is just
34
30
informing us that it wants to create children under this
37
storage_name = t_strndup(storage_name, strlen(storage_name)-1);
38
mailbox = t_strndup(mailbox, len-1);
41
ns = client_find_namespace(cmd, mailbox, &storage_name, &status);
45
case MAILBOX_NAME_VALID:
47
case MAILBOX_NAME_EXISTS_DIR:
51
case MAILBOX_NAME_EXISTS_MAILBOX:
52
case MAILBOX_NAME_INVALID:
53
case MAILBOX_NAME_NOINFERIORS:
54
client_fail_mailbox_name_status(cmd, mailbox, NULL, status);
58
box = mailbox_alloc(ns->list, storage_name, 0);
34
/* drop separator from mailbox. it's already dropped when
35
WORKAROUND_TB_EXTRA_MAILBOX_SEP is enabled */
36
if (len == strlen(mailbox))
37
mailbox = t_strndup(mailbox, len-1);
40
box = mailbox_alloc(ns->list, mailbox, 0);
59
41
if (mailbox_create(box, NULL, directory) < 0)
60
42
client_send_storage_error(cmd, mailbox_get_storage(box));