int dsync_brain_mailbox_alloc(struct dsync_brain *brain, const guid_128_t guid, struct mailbox **box_r, const char **error_r) { struct mail_namespace *ns; int ret; *box_r = NULL; if (brain->sync_ns != NULL) { ret = ns_mailbox_try_alloc(brain->sync_ns, guid, box_r, error_r); if (ret < 0) brain->failed = TRUE; return ret; } for (ns = brain->user->namespaces; ns != NULL; ns = ns->next) { if (!dsync_brain_want_namespace(brain, ns)) continue; if ((ret = ns_mailbox_try_alloc(ns, guid, box_r, error_r)) != 0) { if (ret < 0) brain->failed = TRUE; return ret; } } return 0; }
void dsync_brain_mailbox_trees_init(struct dsync_brain *brain) { struct mail_namespace *ns; dsync_brain_check_namespaces(brain); brain->local_mailbox_tree = dsync_mailbox_tree_init(brain->hierarchy_sep, brain->alt_char); /* we'll convert remote mailbox names to use our own separator */ brain->remote_mailbox_tree = dsync_mailbox_tree_init(brain->hierarchy_sep, brain->alt_char); /* fill the local mailbox tree */ for (ns = brain->user->namespaces; ns != NULL; ns = ns->next) { if (!dsync_brain_want_namespace(brain, ns)) continue; if (dsync_mailbox_tree_fill(brain->local_mailbox_tree, ns, brain->sync_box, brain->sync_box_guid, brain->exclude_mailboxes, &brain->mail_error) < 0) { brain->failed = TRUE; break; } } brain->local_tree_iter = dsync_mailbox_tree_iter_init(brain->local_mailbox_tree); }
static void dsync_brain_check_namespaces(struct dsync_brain *brain) { struct mail_namespace *ns, *first_ns = NULL; char sep; i_assert(brain->hierarchy_sep == '\0'); for (ns = brain->user->namespaces; ns != NULL; ns = ns->next) { if (!dsync_brain_want_namespace(brain, ns)) continue; sep = mail_namespace_get_sep(ns); if (first_ns == NULL) { brain->hierarchy_sep = sep; first_ns = ns; } else if (brain->hierarchy_sep != sep) { i_fatal("Synced namespaces have conflicting separators " "('%c' for prefix=\"%s\", '%c' for prefix=\"%s\")", brain->hierarchy_sep, first_ns->prefix, sep, ns->prefix); } } if (brain->hierarchy_sep != '\0') return; i_fatal("All your namespaces have a location setting. " "Only namespaces with empty location settings are converted. " "(One namespace should default to mail_location setting)"); }
int dsync_brain_mailbox_alloc(struct dsync_brain *brain, const guid_128_t guid, struct mailbox **box_r, const char **errstr_r, enum mail_error *error_r) { struct mail_namespace *ns; int ret; *box_r = NULL; for (ns = brain->user->namespaces; ns != NULL; ns = ns->next) { if (!dsync_brain_want_namespace(brain, ns)) continue; if ((ret = ns_mailbox_try_alloc(brain, ns, guid, box_r, errstr_r, error_r)) != 0) return ret; } return 0; }
static struct mail_namespace * dsync_find_namespace(struct dsync_brain *brain, const char *const *name_parts) { struct mail_namespace *ns, *best_ns = NULL; for (ns = brain->user->namespaces; ns != NULL; ns = ns->next) { if (!dsync_brain_want_namespace(brain, ns)) continue; if (ns->prefix_len == 0) { /* prefix="" is the fallback namespace */ if (best_ns == NULL) best_ns = ns; } else if (dsync_namespace_match_parts(ns, name_parts)) { if (best_ns == NULL || best_ns->prefix_len < ns->prefix_len) best_ns = ns; } } return best_ns; }