1
#ifndef MAILBOX_LIST_INDEX_H
2
#define MAILBOX_LIST_INDEX_H
4
struct mailbox_list_index_view;
5
struct mailbox_list_index_sync_ctx;
7
/* Mailbox list index contains UID <-> mailbox name mapping. It also takes in
8
a mail_index index which contains UID -> metadata information for the
9
mailboxes. The mmap, in-memory and lock settings are taken from the
12
enum mailbox_list_index_flags {
13
/* Mailbox has children. They may not be indexed however, so
14
mailbox_list_index_info.has_children=FALSE is possible. */
15
MAILBOX_LIST_INDEX_FLAG_CHILDREN = 0x01,
16
/* Mailbox has no children. mailbox_list_index_info.has_children
18
MAILBOX_LIST_INDEX_FLAG_NOCHILDREN = 0x02,
19
/* The mailbox isn't selectable (eg. a directory) */
20
MAILBOX_LIST_INDEX_FLAG_NOSELECT = 0x04,
21
/* The mailbox doesn't exist at all. This is only a placeholder for
22
a child mailbox. When the children are deleted, this mailbox will
23
be automatically deleted as well. */
24
MAILBOX_LIST_INDEX_FLAG_NONEXISTENT = 0x08
28
enum mailbox_list_sync_flags {
29
/* All the child mailboxes are also being synced */
30
MAILBOX_LIST_SYNC_FLAG_RECURSIVE = 0x01,
31
/* New mailboxes may be added, but none are removed */
32
MAILBOX_LIST_SYNC_FLAG_PARTIAL = 0x02
35
struct mailbox_list_index_info {
41
struct mailbox_list_index *
42
mailbox_list_index_alloc(const char *path, char separator,
43
struct mail_index *mail_index);
44
void mailbox_list_index_free(struct mailbox_list_index **index);
46
/* Open or create mailbox list index. */
47
int mailbox_list_index_open_or_create(struct mailbox_list_index *index);
49
/* Synchronize the index with the backend. */
50
int mailbox_list_index_sync_init(struct mailbox_list_index *index,
52
enum mailbox_list_sync_flags flags,
53
struct mailbox_list_index_sync_ctx **ctx_r);
54
struct mail_index_view *
55
mailbox_list_index_sync_get_view(struct mailbox_list_index_sync_ctx *ctx);
56
struct mail_index_transaction *
57
mailbox_list_index_sync_get_transaction(struct mailbox_list_index_sync_ctx*ctx);
58
int mailbox_list_index_sync_more(struct mailbox_list_index_sync_ctx *ctx,
59
const char *name, uint32_t *seq_r);
60
int mailbox_list_index_sync_commit(struct mailbox_list_index_sync_ctx **ctx);
61
void mailbox_list_index_sync_rollback(struct mailbox_list_index_sync_ctx **ctx);
63
/* Mailbox list index and mail index must be kept in sync, so lookups and
64
iterations must know the mail index view. The mail_view can be set to NULL
65
to use the latest changes. Returns -1 if uidvalidity doesn't match. */
66
int mailbox_list_index_view_init(struct mailbox_list_index *index,
67
struct mail_index_view *mail_view,
68
struct mailbox_list_index_view **view_r);
69
void mailbox_list_index_view_deinit(struct mailbox_list_index_view **view);
71
/* Get mailbox UID for a given name. Returns 1 if found, 0 if not,
73
int mailbox_list_index_lookup(struct mailbox_list_index_view *view,
74
const char *name, uint32_t *uid_r);
76
/* Iterate through all the mailboxes. If recurse_level is -1, all the child
77
mailboxes are returned, otherwise it's the number of levels to return
78
(0 = only the mailboxes directly under the path). Returned mailbox names
79
are allocated from name_pool. */
80
struct mailbox_list_iter_ctx *
81
mailbox_list_index_iterate_init(struct mailbox_list_index_view *view,
82
const char *path, int recurse_level);
83
/* Returns 1 if mailbox was returned, 0 at the end of iteration, -1 if error */
84
int mailbox_list_index_iterate_next(struct mailbox_list_iter_ctx *ctx,
85
struct mailbox_list_index_info *info_r);
86
void mailbox_list_index_iterate_deinit(struct mailbox_list_iter_ctx **ctx);