~ubuntu-branches/ubuntu/utopic/dovecot/utopic-proposed

« back to all changes in this revision

Viewing changes to src/lib-storage/list/mailbox-list-notify-tree.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-01-08 09:35:49 UTC
  • mfrom: (4.1.35 sid)
  • Revision ID: package-import@ubuntu.com-20140108093549-i72o93pux8p0dlaf
Tags: 1:2.2.9-1ubuntu1
* Merge from Debian unstable, remaining changes:
  + Add mail-stack-delivery package:
    - Update d/rules
    - d/control: convert existing dovecot-postfix package to a dummy
      package and add new mail-stack-delivery package.
    - Update maintainer scripts.
    - Rename d/dovecot-postfix.* to debian/mail-stack-delivery.*
    - d/mail-stack-delivery.preinst: Move previously installed backups and
      config files to a new package namespace.
    - d/mail-stack-delivery.prerm: Added to handle downgrades.
  + Use Snakeoil SSL certificates by default:
    - d/control: Depend on ssl-cert.
    - d/dovecot-core.postinst: Relax grep for SSL_* a bit.
  + Add autopkgtest to debian/tests/*.
  + Add ufw integration:
    - d/dovecot-core.ufw.profile: new ufw profile.
    - d/rules: install profile in dovecot-core.
    - d/control: dovecot-core - suggest ufw.
  + d/dovecot-core.dirs: Added usr/share/doc/dovecot-core
  + Add apport hook:
    - d/rules, d/source_dovecot.py
  + Add upstart job:
    - d/rules, d/dovecot-core.dovecot.upstart, d/control,
      d/dovecot-core.dirs, dovecot-imapd.{postrm, postinst, prerm},
      d/dovecot-pop3d.{postinst, postrm, prerm}.
      d/mail-stack-deliver.postinst: Convert init script to upstart.
  + Use the autotools-dev dh addon to update config.guess/config.sub for
    arm64.
* Dropped changes, included in Debian:
  - Update Dovecot name to reflect distribution in login greeting.
  - Update Drac plugin for >= 2.0.0 support.
* d/control: Drop dovecot-postfix package as its no longer required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2013 Dovecot authors, see the included COPYING file */
 
2
 
 
3
#include "lib.h"
 
4
#include "str.h"
 
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"
 
10
 
 
11
struct mailbox_list_notify_tree {
 
12
        struct mailbox_list *list;
 
13
        struct mailbox_tree_context *mailboxes;
 
14
 
 
15
        struct mail_index_view *view;
 
16
        bool failed;
 
17
};
 
18
 
 
19
static void
 
20
mailbox_list_notify_node_get_status(struct mailbox_list_notify_tree *tree,
 
21
                                    struct mailbox_notify_node *nnode)
 
22
{
 
23
        struct mailbox_status status;
 
24
        uint32_t seq;
 
25
 
 
26
        if (!mail_index_lookup_seq(tree->view, nnode->index_uid, &seq))
 
27
                return;
 
28
 
 
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;
 
38
}
 
39
 
 
40
static void
 
41
mailbox_list_notify_node_build(struct mailbox_list_notify_tree *tree,
 
42
                               struct mailbox_list_index_node *index_node,
 
43
                               string_t *path)
 
44
{
 
45
        struct mailbox_node *node;
 
46
        struct mailbox_notify_node *nnode;
 
47
        unsigned int prefix_len;
 
48
        bool created;
 
49
 
 
50
        str_append(path, index_node->name);
 
51
 
 
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;
 
55
 
 
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;
 
60
        else {
 
61
                node->flags = 0;
 
62
                mailbox_list_notify_node_get_status(tree, nnode);
 
63
        }
 
64
        if ((index_node->flags & MAILBOX_LIST_INDEX_FLAG_NOINFERIORS) != 0)
 
65
                node->flags |= MAILBOX_NOINFERIORS;
 
66
 
 
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);
 
74
                }
 
75
        }
 
76
}
 
77
 
 
78
static void
 
79
mailbox_list_notify_tree_build(struct mailbox_list_notify_tree *tree)
 
80
{
 
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);
 
84
 
 
85
        if (mailbox_list_index_refresh(tree->list) < 0)
 
86
                tree->failed = TRUE;
 
87
 
 
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);
 
93
        }
 
94
        mail_index_view_close(&tree->view);
 
95
}
 
96
 
 
97
struct mailbox_list_notify_tree *
 
98
mailbox_list_notify_tree_init(struct mailbox_list *list)
 
99
{
 
100
        struct mailbox_list_notify_tree *tree;
 
101
 
 
102
        tree = i_new(struct mailbox_list_notify_tree, 1);
 
103
        tree->list = list;
 
104
        tree->mailboxes =
 
105
                mailbox_tree_init_size(mailbox_list_get_hierarchy_sep(list),
 
106
                                       sizeof(struct mailbox_notify_node));
 
107
        mailbox_list_notify_tree_build(tree);
 
108
        return tree;
 
109
}
 
110
 
 
111
void mailbox_list_notify_tree_deinit(struct mailbox_list_notify_tree **_tree)
 
112
{
 
113
        struct mailbox_list_notify_tree *tree = *_tree;
 
114
 
 
115
        *_tree = NULL;
 
116
 
 
117
        mailbox_tree_deinit(&tree->mailboxes);
 
118
        i_free(tree);
 
119
}
 
120
 
 
121
struct mailbox_notify_node *
 
122
mailbox_list_notify_tree_lookup(struct mailbox_list_notify_tree *tree,
 
123
                                const char *storage_name)
 
124
{
 
125
        struct mailbox_node *node;
 
126
 
 
127
        node = mailbox_tree_lookup(tree->mailboxes, storage_name);
 
128
        return (struct mailbox_notify_node *)node;
 
129
}