void dsync_proxy_mailbox_export(string_t *str,
const struct dsync_mailbox *box)
{
+ char s[2];
+
str_tabescape_write(str, box->name);
str_append_c(str, '\t');
+ s[0] = box->name_sep; s[1] = '\0';
+ str_tabescape_write(str, s);
+ str_append_c(str, '\t');
dsync_proxy_mailbox_guid_export(str, &box->dir_guid);
str_printfa(str, "\t%lu\t%u", (unsigned long)box->last_renamed,
box->flags);
struct dsync_mailbox *box_r,
const char **error_r)
{
- unsigned int i, count;
+ unsigned int i = 0, count;
char *p;
memset(box_r, 0, sizeof(*box_r));
count = str_array_length(args);
- if (count != 4 && count < 8) {
+ if (count != 5 && count < 9) {
*error_r = "Mailbox missing parameters";
return -1;
}
/* name dir_guid mailbox_guid uid_validity uid_next highest_modseq */
- box_r->name = p_strdup(pool, args[0]);
+ box_r->name = p_strdup(pool, args[i++]);
+
+ if (strlen(args[i]) != 1) {
+ *error_r = "Invalid mailbox name hierarchy separator";
+ return -1;
+ }
+ box_r->name_sep = args[i++][0];
- if (dsync_proxy_mailbox_guid_import(args[1], &box_r->dir_guid) < 0) {
+ if (dsync_proxy_mailbox_guid_import(args[i++], &box_r->dir_guid) < 0) {
*error_r = "Invalid dir GUID";
return -1;
}
- box_r->last_renamed = strtoul(args[2], &p, 10);
+ box_r->last_renamed = strtoul(args[i++], &p, 10);
if (*p != '\0') {
*error_r = "Invalid mailbox last_renamed";
return -1;
}
- box_r->flags = strtoul(args[3], &p, 10);
+ box_r->flags = strtoul(args[i++], &p, 10);
if (*p != '\0') {
*error_r = "Invalid mailbox flags";
return -1;
}
- if (args[4] == NULL) {
+ if (args[i] == NULL) {
/* \noselect mailbox */
return 0;
}
- if (dsync_proxy_mailbox_guid_import(args[4], &box_r->mailbox_guid) < 0) {
+ if (dsync_proxy_mailbox_guid_import(args[i++],
+ &box_r->mailbox_guid) < 0) {
*error_r = "Invalid mailbox GUID";
return -1;
}
- box_r->uid_validity = strtoul(args[5], &p, 10);
+ box_r->uid_validity = strtoul(args[i++], &p, 10);
if (box_r->uid_validity == 0 || *p != '\0') {
*error_r = "Invalid mailbox uid_validity";
return -1;
}
- box_r->uid_next = strtoul(args[6], &p, 10);
+ box_r->uid_next = strtoul(args[i++], &p, 10);
if (box_r->uid_validity == 0 || *p != '\0') {
*error_r = "Invalid mailbox uid_next";
return -1;
}
- box_r->highest_modseq = strtoull(args[7], &p, 10);
+ box_r->highest_modseq = strtoull(args[i++], &p, 10);
if (*p != '\0') {
*error_r = "Invalid mailbox highest_modseq";
return -1;
}
- args += 8;
- count -= 8;
+ args += i;
+ count -= i;
p_array_init(&box_r->cache_fields, pool, count + 1);
for (i = 0; i < count; i++) {
const char *field_name = p_strdup(pool, args[i]);
static void test_dsync_brain(void)
{
static struct dsync_mailbox src_boxes[] = {
- { "box1", { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
- { "box2", { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
- { "box3", { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
- { "box4", { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
- { "box5", { { 0, } }, { { 0, } }, 1234567890, 5433, 123123123123ULL, 3636, 0, ARRAY_INIT },
- { "box6", { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123124ULL, 3636, 0, ARRAY_INIT },
- { "boxx", { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
- { "boxd1", { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
- { "boxd2", { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, DSYNC_MAILBOX_FLAG_DELETED_MAILBOX, ARRAY_INIT },
- { NULL, { { 0, } }, { { 0, } }, 0, 0, 0, 0, 0, ARRAY_INIT }
+ { "box1", '/', { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
+ { "box2", '/', { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
+ { "box3", '/', { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
+ { "box4", '/', { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
+ { "box5", '/', { { 0, } }, { { 0, } }, 1234567890, 5433, 123123123123ULL, 3636, 0, ARRAY_INIT },
+ { "box6", '/', { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123124ULL, 3636, 0, ARRAY_INIT },
+ { "boxx", '/', { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
+ { "boxd1", '/', { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
+ { "boxd2", '/', { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, DSYNC_MAILBOX_FLAG_DELETED_MAILBOX, ARRAY_INIT },
+ { NULL, 0, { { 0, } }, { { 0, } }, 0, 0, 0, 0, 0, ARRAY_INIT }
};
static struct dsync_mailbox dest_boxes[] = {
- { "box1", { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
- { "box2", { { 0, } }, { { 0, } }, 1234567891, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
- { "box3", { { 0, } }, { { 0, } }, 1234567890, 5433, 123123123123ULL, 3636, 0, ARRAY_INIT },
- { "box4", { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123124ULL, 3636, 0, ARRAY_INIT },
- { "box5", { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
- { "box6", { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
- { "boxy", { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
- { "boxd1", { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, DSYNC_MAILBOX_FLAG_DELETED_MAILBOX, ARRAY_INIT },
- { "boxd2", { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
- { NULL, { { 0, } }, { { 0, } }, 0, 0, 0, 0, 0, ARRAY_INIT }
+ { "box1", '/', { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
+ { "box2", '/', { { 0, } }, { { 0, } }, 1234567891, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
+ { "box3", '/', { { 0, } }, { { 0, } }, 1234567890, 5433, 123123123123ULL, 3636, 0, ARRAY_INIT },
+ { "box4", '/', { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123124ULL, 3636, 0, ARRAY_INIT },
+ { "box5", '/', { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
+ { "box6", '/', { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
+ { "boxy", '/', { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
+ { "boxd1", '/', { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, DSYNC_MAILBOX_FLAG_DELETED_MAILBOX, ARRAY_INIT },
+ { "boxd2", '/', { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 3636, 0, ARRAY_INIT },
+ { NULL, 0, { { 0, } }, { { 0, } }, 0, 0, 0, 0, 0, ARRAY_INIT }
};
struct dsync_brain *brain;
struct dsync_worker *src_worker, *dest_worker;
static void test_dsync_brain_full(void)
{
static struct dsync_mailbox boxes[] = {
- { "box1", { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 2352, 0, ARRAY_INIT },
- { NULL, { { 0, } }, { { 0, } }, 0, 0, 0, 0, 0, ARRAY_INIT }
+ { "box1", '/', { { 0, } }, { { 0, } }, 1234567890, 5432, 123123123123ULL, 2352, 0, ARRAY_INIT },
+ { NULL, 0, { { 0, } }, { { 0, } }, 0, 0, 0, 0, 0, ARRAY_INIT }
};
struct dsync_brain *brain;
struct dsync_worker *src_worker, *dest_worker;
/* \noselect mailbox */
memset(&box, 0, sizeof(box));
box.name = "\t\001\r\nname\t\001\n\r";
+ box.name_sep = '/';
box.last_renamed = 992;
box.flags = 123;
memcpy(box.dir_guid.guid, test_mailbox_guid1, MAIL_GUID_128_SIZE);
test_worker->box_iter.next_box = &box;
test_assert(run_more() == 0);
test_assert(strcmp(str_c(out), t_strconcat(str_tabescape(box.name),
- "\t"TEST_MAILBOX_GUID1"\t992\t123\n", NULL)) == 0);
+ "\t/\t"TEST_MAILBOX_GUID1"\t992\t123\n", NULL)) == 0);
out_clear();
/* selectable mailbox */
memset(&box, 0, sizeof(box));
box.name = "foo/bar";
+ box.name_sep = '/';
memcpy(box.dir_guid.guid, test_mailbox_guid2, MAIL_GUID_128_SIZE);
memcpy(box.mailbox_guid.guid, test_mailbox_guid1, MAIL_GUID_128_SIZE);
box.uid_validity = 4275878552;
test_assert(run_more() == 0);
- test_assert(strcmp(str_c(out), "foo/bar\t"
+ test_assert(strcmp(str_c(out), "foo/bar\t/\t"
TEST_MAILBOX_GUID2"\t0\t0\t"
TEST_MAILBOX_GUID1"\t"
"4275878552\t"
test_begin("proxy server box create");
- test_assert(run_cmd("BOX-CREATE", "noselect",
+ test_assert(run_cmd("BOX-CREATE", "noselect", "/",
TEST_MAILBOX_GUID2, "553", "99", NULL) == 1);
test_assert(test_dsync_worker_next_box_event(test_worker, &event));
test_assert(event.type == LAST_BOX_TYPE_CREATE);
test_assert(strcmp(event.box.name, "noselect") == 0);
+ test_assert(event.box.name_sep == '/');
test_assert(memcmp(event.box.dir_guid.guid, test_mailbox_guid2, MAIL_GUID_128_SIZE) == 0);
test_assert(event.box.last_renamed == 553);
test_assert(event.box.flags == 99);
test_assert(event.box.uid_validity == 0);
- test_assert(run_cmd("BOX-CREATE", "selectable", TEST_MAILBOX_GUID1,
+ test_assert(run_cmd("BOX-CREATE", "selectable", "?", TEST_MAILBOX_GUID1,
"61", "2", TEST_MAILBOX_GUID2, "1234567890", "9876",
"28427847284728", NULL) == 1);
test_assert(test_dsync_worker_next_box_event(test_worker, &event));
test_assert(event.type == LAST_BOX_TYPE_CREATE);
test_assert(strcmp(event.box.name, "selectable") == 0);
+ test_assert(event.box.name_sep == '?');
test_assert(memcmp(event.box.dir_guid.guid, test_mailbox_guid1, MAIL_GUID_128_SIZE) == 0);
test_assert(memcmp(event.box.mailbox_guid.guid, test_mailbox_guid2, MAIL_GUID_128_SIZE) == 0);
test_assert(event.box.flags == 2);
test_begin("proxy server box update");
- test_assert(run_cmd("BOX-UPDATE", "updated", TEST_MAILBOX_GUID2,
+ test_assert(run_cmd("BOX-UPDATE", "updated", "/", TEST_MAILBOX_GUID2,
"53", "9", TEST_MAILBOX_GUID1, "34343", "22",
"2238427847284728", NULL) == 1);
test_assert(test_dsync_worker_next_box_event(test_worker, &event));
test_assert(event.type == LAST_BOX_TYPE_UPDATE);
test_assert(strcmp(event.box.name, "updated") == 0);
+ test_assert(event.box.name_sep == '/');
test_assert(memcmp(event.box.dir_guid.guid, test_mailbox_guid2, MAIL_GUID_128_SIZE) == 0);
test_assert(memcmp(event.box.mailbox_guid.guid, test_mailbox_guid1, MAIL_GUID_128_SIZE) == 0);
test_assert(event.box.flags == 9);