a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen#ifndef MAILBOX_LIST_ITER_H
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen#define MAILBOX_LIST_ITER_H
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen#include "mail-namespace.h"
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen#include "mailbox-list.h"
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainenenum mailbox_list_iter_flags {
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen /* Ignore index file and ACLs (used by ACL plugin internally) */
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen MAILBOX_LIST_ITER_RAW_LIST = 0x000001,
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen /* Don't list autocreated mailboxes (e.g. INBOX) unless they
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen physically exist */
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen MAILBOX_LIST_ITER_NO_AUTO_BOXES = 0x000004,
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen
fca7aa88ab19375aba5a8fd9d4100ea885dccb68Timo Sirainen /* Skip all kinds of mailbox aliases. This typically includes symlinks
fca7aa88ab19375aba5a8fd9d4100ea885dccb68Timo Sirainen that point to the same directory. Also when iterating with
fca7aa88ab19375aba5a8fd9d4100ea885dccb68Timo Sirainen mailbox_list_iter_init_namespaces() skip namespaces that
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen have alias_for set. */
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen MAILBOX_LIST_ITER_SKIP_ALIASES = 0x000008,
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen /* For mailbox_list_iter_init_namespaces(): '*' in a pattern doesn't
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen match beyond namespace boundary (e.g. "foo*" or "*o" doesn't match
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen "foo." namespace's mailboxes, but "*.*" does). also '%' can't match
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen namespace prefixes, if there exists a parent namespace whose children
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen it matches. */
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen MAILBOX_LIST_ITER_STAR_WITHIN_NS = 0x000010,
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen /* List only subscribed mailboxes */
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen MAILBOX_LIST_ITER_SELECT_SUBSCRIBED = 0x000100,
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen /* Return MAILBOX_CHILD_* if mailbox's children match selection
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen criteria, even if the mailbox itself wouldn't match. */
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen MAILBOX_LIST_ITER_SELECT_RECURSIVEMATCH = 0x000200,
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen /* Return only mailboxes that have special use flags */
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen MAILBOX_LIST_ITER_SELECT_SPECIALUSE = 0x000400,
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen /* Don't return any flags unless it can be done without cost */
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen MAILBOX_LIST_ITER_RETURN_NO_FLAGS = 0x001000,
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen /* Return MAILBOX_SUBSCRIBED flag */
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen MAILBOX_LIST_ITER_RETURN_SUBSCRIBED = 0x002000,
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen /* Return children flags */
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen MAILBOX_LIST_ITER_RETURN_CHILDREN = 0x004000,
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen /* Return IMAP special use flags */
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen MAILBOX_LIST_ITER_RETURN_SPECIALUSE = 0x008000
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen};
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainenstruct mailbox_info {
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen const char *vname;
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen const char *special_use;
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen enum mailbox_info_flags flags;
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen struct mail_namespace *ns;
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen};
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen/* Returns a single pattern from given reference and pattern. */
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainenconst char *mailbox_list_join_refpattern(struct mailbox_list *list,
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen const char *ref, const char *pattern);
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen/* Initialize new mailbox list request. Pattern may contain '%' and '*'
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen wildcards as defined by RFC-3501. */
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainenstruct mailbox_list_iterate_context *
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainenmailbox_list_iter_init(struct mailbox_list *list, const char *pattern,
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen enum mailbox_list_iter_flags flags);
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen/* Like mailbox_list_iter_init(), but support multiple patterns. Patterns is
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen a NULL-terminated list of strings. It must contain at least one pattern. */
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainenstruct mailbox_list_iterate_context *
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainenmailbox_list_iter_init_multiple(struct mailbox_list *list,
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen const char *const *patterns,
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen enum mailbox_list_iter_flags flags);
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen/* List mailbox_list_iter_init_multiple(), but list mailboxes from all the
4947cf0826d274afb3712e7292b1bd554f75872aTimo Sirainen specified namespaces. If it fails, the error message is set to the first
4947cf0826d274afb3712e7292b1bd554f75872aTimo Sirainen namespaces->list. */
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainenstruct mailbox_list_iterate_context *
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainenmailbox_list_iter_init_namespaces(struct mail_namespace *namespaces,
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen const char *const *patterns,
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen enum mail_namespace_type type_mask,
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen enum mailbox_list_iter_flags flags);
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen/* Get next mailbox. Returns the mailbox name */
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainenconst struct mailbox_info *
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainenmailbox_list_iter_next(struct mailbox_list_iterate_context *ctx);
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen/* Deinitialize mailbox list request. Returns -1 if some error
4947cf0826d274afb3712e7292b1bd554f75872aTimo Sirainen occurred while listing. The error string can be looked up with
4947cf0826d274afb3712e7292b1bd554f75872aTimo Sirainen mailbox_list_get_last_error(). */
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainenint mailbox_list_iter_deinit(struct mailbox_list_iterate_context **ctx);
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen/* List one mailbox. Returns 1 if info returned, 0 if mailbox doesn't exist,
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen -1 if error. */
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainenint mailbox_list_mailbox(struct mailbox_list *list, const char *name,
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen enum mailbox_info_flags *flags_r);
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen/* Returns 1 if mailbox has children, 0 if not, -1 if error. */
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainenint mailbox_has_children(struct mailbox_list *list, const char *name);
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen#endif