1
/* Copyright (c) 2013 Dovecot authors, see the included COPYING file */
5
#include "mail-index.h"
6
#include "mail-storage.h"
7
#include "mailbox-list-private.h"
8
#include "mailbox-list-index.h"
9
#include "mailbox-list-notify-tree.h"
11
struct mailbox_list_notify_tree {
12
struct mailbox_list *list;
13
struct mailbox_tree_context *mailboxes;
15
struct mail_index_view *view;
20
mailbox_list_notify_node_get_status(struct mailbox_list_notify_tree *tree,
21
struct mailbox_notify_node *nnode)
23
struct mailbox_status status;
26
if (!mail_index_lookup_seq(tree->view, nnode->index_uid, &seq))
29
memset(&status, 0, sizeof(status));
30
(void)mailbox_list_index_status(tree->list, tree->view, seq,
31
STATUS_UIDVALIDITY | STATUS_UIDNEXT | STATUS_MESSAGES |
32
STATUS_UNSEEN | STATUS_HIGHESTMODSEQ, &status, nnode->guid);
33
nnode->uidvalidity = status.uidvalidity;
34
nnode->uidnext = status.uidnext;
35
nnode->messages = status.messages;
36
nnode->unseen = status.unseen;
37
nnode->highest_modseq = status.highest_modseq;
41
mailbox_list_notify_node_build(struct mailbox_list_notify_tree *tree,
42
struct mailbox_list_index_node *index_node,
45
struct mailbox_node *node;
46
struct mailbox_notify_node *nnode;
47
unsigned int prefix_len;
50
str_append(path, index_node->name);
52
node = mailbox_tree_get(tree->mailboxes, str_c(path), &created);
53
nnode = (struct mailbox_notify_node *)node;
54
nnode->index_uid = index_node->uid;
56
if ((index_node->flags & MAILBOX_LIST_INDEX_FLAG_NONEXISTENT) != 0)
57
node->flags = MAILBOX_NONEXISTENT;
58
else if ((index_node->flags & MAILBOX_LIST_INDEX_FLAG_NOSELECT) != 0)
59
node->flags = MAILBOX_NOSELECT;
62
mailbox_list_notify_node_get_status(tree, nnode);
64
if ((index_node->flags & MAILBOX_LIST_INDEX_FLAG_NOINFERIORS) != 0)
65
node->flags |= MAILBOX_NOINFERIORS;
67
if (index_node->children != NULL) {
68
str_append_c(path, mailbox_list_get_hierarchy_sep(tree->list));
69
prefix_len = str_len(path);
70
index_node = index_node->children;
71
for (; index_node != NULL; index_node = index_node->next) {
72
str_truncate(path, prefix_len);
73
mailbox_list_notify_node_build(tree, index_node, path);
79
mailbox_list_notify_tree_build(struct mailbox_list_notify_tree *tree)
81
struct mailbox_list_index *ilist = INDEX_LIST_CONTEXT(tree->list);
82
struct mailbox_list_index_node *index_node;
83
string_t *path = t_str_new(128);
85
if (mailbox_list_index_refresh(tree->list) < 0)
88
tree->view = mail_index_view_open(ilist->index);
89
index_node = ilist->mailbox_tree;
90
for (; index_node != NULL; index_node = index_node->next) {
91
str_truncate(path, 0);
92
mailbox_list_notify_node_build(tree, index_node, path);
94
mail_index_view_close(&tree->view);
97
struct mailbox_list_notify_tree *
98
mailbox_list_notify_tree_init(struct mailbox_list *list)
100
struct mailbox_list_notify_tree *tree;
102
tree = i_new(struct mailbox_list_notify_tree, 1);
105
mailbox_tree_init_size(mailbox_list_get_hierarchy_sep(list),
106
sizeof(struct mailbox_notify_node));
107
mailbox_list_notify_tree_build(tree);
111
void mailbox_list_notify_tree_deinit(struct mailbox_list_notify_tree **_tree)
113
struct mailbox_list_notify_tree *tree = *_tree;
117
mailbox_tree_deinit(&tree->mailboxes);
121
struct mailbox_notify_node *
122
mailbox_list_notify_tree_lookup(struct mailbox_list_notify_tree *tree,
123
const char *storage_name)
125
struct mailbox_node *node;
127
node = mailbox_tree_lookup(tree->mailboxes, storage_name);
128
return (struct mailbox_notify_node *)node;