--- maildir-storage.c 2006-08-10 22:35:11.000000000 +0200 +++ ../../../../../asd/src/lib-storage/index/maildir/maildir-storage.c 2006-09-28 01:31:54.000000000 +0200 @@ -56,6 +56,19 @@ (void)rename(oldpath, path); } +/* string for setting inboxes */ +#define INBOXSTR ":INBOX=" +#define INBOXLEN 7 + +/* string for setting indexes */ +#define INDEXSTR ":INDEX=" +#define INDEXLEN 7 + +/* string for setting control */ +#define CONTROLSTR ":CONTROL=" +#define CONTROLLEN 9 + + static struct mail_storage * maildir_create(const char *data, const char *user, enum mail_storage_flags flags, @@ -99,26 +112,50 @@ root_dir = "/"; } } else { + const char *p_inbox, *p_index, *p_control; + /* [:INBOX=] [:INDEX=] [:CONTROL=] */ - if (debug) - i_info("maildir: data=%s", data); - p = strchr(data, ':'); - if (p == NULL) - root_dir = data; - else { - root_dir = t_strdup_until(data, p); + if (debug) + i_info("maildir: data=%s", data); - do { - p++; - if (strncmp(p, "INBOX=", 6) == 0) - inbox_dir = t_strcut(p+6, ':'); - else if (strncmp(p, "INDEX=", 6) == 0) - index_dir = t_strcut(p+6, ':'); - else if (strncmp(p, "CONTROL=", 8) == 0) - control_dir = t_strcut(p+8, ':'); - p = strchr(p, ':'); - } while (p != NULL); - } + /* expecting INBOX, INDEX, CONTROL in order */ + p_inbox = strstr(data, INBOXSTR); + p_index = strstr(data, INDEXSTR); + p_control = strstr(data, CONTROLSTR); + + /* safety check p_inbox < p_index < p_control */ + if (p_control != NULL && !(p_control > p_index && p_control > p_inbox)) { + i_error("inbox/index/control args in config do not appear in the order required."); + return NULL; + } + if (p_index != NULL && !(p_index > p_inbox)) { + i_error("inbox/index/control args in config do not appear in the order required."); + return NULL; + } + + /* set root_dir */ + if ((p = p_inbox) != NULL || (p = p_index) != NULL || (p = p_control) != NULL) { + /* p is where the first option begin */ + root_dir = t_strdup_until(data, p); + if (p_inbox != NULL) { /* set ":INBOX=" if available */ + if ((p = p_index) != NULL || (p = p_control) != NULL) { + /* p holds the next arg */ + inbox_dir = t_strdup_until(p_inbox + INBOXLEN, p); + } else { + inbox_dir = t_strdup(p_inbox + INBOXLEN); + } + } + if (p_index != NULL) { /* set ":INDEX=" if available */ + if (p_control != NULL) index_dir = t_strdup_until(p_index + INDEXLEN, p_control); + else index_dir = t_strdup(p_index + INDEXLEN); + } + if (p_control != NULL) { /* set ":INDEX=" if available */ + control_dir = t_strdup(p_control + CONTROLLEN); + } + } else { + /* no options set */ + root_dir = data; + } } if (root_dir == NULL) {