return &ctx->ctx;
}
-static void
-path_split(const char *path, const char **dir_r, const char **fname_r)
-{
- const char *p;
-
- p = strrchr(path, '/');
- if (p == NULL) {
- *dir_r = "";
- *fname_r = path;
- } else {
- *dir_r = t_strdup_until(path, p);
- *fname_r = p + 1;
- }
-}
-
const struct mailbox_info *
mailbox_list_subscriptions_iter_next(struct mailbox_list_iterate_context *_ctx)
{
struct mailbox_list *list = _ctx->list;
struct mailbox_node *node;
enum mailbox_info_flags subs_flags;
- const char *path, *vname, *dir, *fname, *storage_name;
- struct stat st;
+ const char *vname, *storage_name;
+ int ret;
node = mailbox_tree_iterate_next(ctx->iter, &vname);
if (node == NULL)
if (!mailbox_list_is_valid_pattern(list, storage_name)) {
/* broken entry in subscriptions file */
ctx->info.flags = MAILBOX_NONEXISTENT;
- } else {
- path = mailbox_list_get_path(list, storage_name,
- MAILBOX_LIST_PATH_TYPE_DIR);
- path_split(path, &dir, &fname);
- if (list->v.get_mailbox_flags(list, dir, fname,
- MAILBOX_LIST_FILE_TYPE_UNKNOWN,
- &st, &ctx->info.flags) < 0)
+ } else if (mailbox_list_mailbox(list, storage_name,
+ &ctx->info.flags) < 0) {
+ ctx->info.flags = 0;
+ _ctx->failed = TRUE;
+ } else if ((_ctx->flags & MAILBOX_LIST_ITER_RETURN_CHILDREN) != 0 &&
+ (ctx->info.flags & (MAILBOX_CHILDREN |
+ MAILBOX_NOCHILDREN)) == 0) {
+ ret = mailbox_has_children(list, storage_name);
+ if (ret < 0)
_ctx->failed = TRUE;
+ else if (ret == 0)
+ ctx->info.flags |= MAILBOX_NOCHILDREN;
+ else
+ ctx->info.flags |= MAILBOX_CHILDREN;
+
}
ctx->info.flags &= ~(MAILBOX_SUBSCRIBED | MAILBOX_CHILD_SUBSCRIBED);
return ctx->list->v.iter_deinit(ctx);
}
+int mailbox_has_children(struct mailbox_list *list, const char *name)
+{
+ struct mailbox_list_iterate_context *iter;
+ const char *pattern;
+ int ret;
+
+ pattern = t_strdup_printf("%s%c%%", name,
+ mail_namespace_get_sep(list->ns));
+ iter = mailbox_list_iter_init(list, pattern,
+ MAILBOX_LIST_ITER_RETURN_NO_FLAGS);
+ ret = mailbox_list_iter_next(iter) != NULL ? 1 : 0;
+ if (mailbox_list_iter_deinit(&iter) < 0)
+ ret = -1;
+ return ret;
+}
+
int mailbox_list_mailbox(struct mailbox_list *list, const char *name,
enum mailbox_info_flags *flags_r)
{
-1 if error. */
int mailbox_list_mailbox(struct mailbox_list *list, const char *name,
enum mailbox_info_flags *flags_r);
+/* Returns 1 if mailbox has children, 0 if not, -1 if error. */
+int mailbox_has_children(struct mailbox_list *list, const char *name);
/* Subscribe/unsubscribe mailbox. There should be no error when
subscribing to already subscribed mailbox. Subscribing to