dovecot-2.1: imapc: Fixed mailbox_exists() to actually work.
dovecot at dovecot.org
dovecot at dovecot.org
Mon Sep 12 13:14:36 EEST 2011
details: http://hg.dovecot.org/dovecot-2.1/rev/cc9332de9982
changeset: 13446:cc9332de9982
user: Timo Sirainen <tss at iki.fi>
date: Mon Sep 12 13:14:26 2011 +0300
description:
imapc: Fixed mailbox_exists() to actually work.
This fixes problems with subscribing to mailboxes.
diffstat:
src/lib-storage/index/imapc/imapc-list.c | 47 +++++++++++++++++++++++-----
src/lib-storage/index/imapc/imapc-list.h | 3 +
src/lib-storage/index/imapc/imapc-storage.c | 20 +++++++++++-
3 files changed, 60 insertions(+), 10 deletions(-)
diffs (148 lines):
diff -r 3844653d483a -r cc9332de9982 src/lib-storage/index/imapc/imapc-list.c
--- a/src/lib-storage/index/imapc/imapc-list.c Mon Sep 12 13:13:35 2011 +0300
+++ b/src/lib-storage/index/imapc/imapc-list.c Mon Sep 12 13:14:26 2011 +0300
@@ -31,6 +31,8 @@
list = p_new(pool, struct imapc_mailbox_list, 1);
list->list = imapc_mailbox_list;
list->list.pool = pool;
+ /* separator is set when storage is created */
+ list->mailboxes = mailbox_tree_init('\0');
return &list->list;
}
@@ -38,8 +40,7 @@
{
struct imapc_mailbox_list *list = (struct imapc_mailbox_list *)_list;
- if (list->mailboxes != NULL)
- mailbox_tree_deinit(&list->mailboxes);
+ mailbox_tree_deinit(&list->mailboxes);
if (list->tmp_subscriptions != NULL)
mailbox_tree_deinit(&list->tmp_subscriptions);
pool_unref(&list->list.pool);
@@ -118,8 +119,7 @@
/* we can't handle NIL separator yet */
list->sep = sep == NULL ? '/' : sep[0];
- if (list->mailboxes != NULL)
- mailbox_tree_set_separator(list->mailboxes, list->sep);
+ mailbox_tree_set_separator(list->mailboxes, list->sep);
} else {
(void)imapc_list_update_tree(list, list->mailboxes, args);
}
@@ -273,17 +273,15 @@
{
struct imapc_simple_context ctx;
+ i_assert(list->sep != '\0');
+
if (list->refreshed_mailboxes)
return 0;
- if (list->sep == '\0')
- (void)mailbox_list_get_hierarchy_sep(&list->list);
-
imapc_simple_context_init(&ctx, list->storage);
imapc_client_cmdf(list->storage->client,
imapc_list_simple_callback, &ctx, "LIST \"\" *");
- if (list->mailboxes != NULL)
- mailbox_tree_deinit(&list->mailboxes);
+ mailbox_tree_deinit(&list->mailboxes);
list->mailboxes = mailbox_tree_init(list->sep);
imapc_simple_run(&ctx);
@@ -557,6 +555,37 @@
return ctx.ret;
}
+int imapc_list_get_mailbox_flags(struct mailbox_list *_list, const char *name,
+ enum mailbox_info_flags *flags_r)
+{
+ struct imapc_mailbox_list *list = (struct imapc_mailbox_list *)_list;
+ struct imapc_simple_context sctx;
+ struct mailbox_node *node;
+ const char *vname;
+
+ i_assert(list->sep != '\0');
+
+ vname = mailbox_list_default_get_vname(_list, name);
+ node = mailbox_tree_lookup(list->mailboxes, vname);
+ if (node != NULL)
+ node->flags |= MAILBOX_NONEXISTENT;
+
+ /* refresh the mailbox flags */
+ imapc_simple_context_init(&sctx, list->storage);
+ imapc_client_cmdf(list->storage->client, imapc_simple_callback,
+ &sctx, "LIST \"\" %s", name);
+ imapc_simple_run(&sctx);
+ if (sctx.ret < 0)
+ return -1;
+
+ node = mailbox_tree_lookup(list->mailboxes, vname);
+ if (node == NULL)
+ *flags_r = MAILBOX_NONEXISTENT;
+ else
+ *flags_r = node->flags;
+ return 0;
+}
+
struct mailbox_list imapc_mailbox_list = {
.name = MAILBOX_LIST_NAME_IMAPC,
.props = MAILBOX_LIST_PROP_NO_ROOT,
diff -r 3844653d483a -r cc9332de9982 src/lib-storage/index/imapc/imapc-list.h
--- a/src/lib-storage/index/imapc/imapc-list.h Mon Sep 12 13:13:35 2011 +0300
+++ b/src/lib-storage/index/imapc/imapc-list.h Mon Sep 12 13:14:26 2011 +0300
@@ -22,6 +22,9 @@
unsigned int index_list_failed:1;
};
+int imapc_list_get_mailbox_flags(struct mailbox_list *list, const char *name,
+ enum mailbox_info_flags *flags_r);
+
void imapc_list_register_callbacks(struct imapc_mailbox_list *list);
#endif
diff -r 3844653d483a -r cc9332de9982 src/lib-storage/index/imapc/imapc-storage.c
--- a/src/lib-storage/index/imapc/imapc-storage.c Mon Sep 12 13:13:35 2011 +0300
+++ b/src/lib-storage/index/imapc/imapc-storage.c Mon Sep 12 13:14:26 2011 +0300
@@ -5,6 +5,7 @@
#include "str.h"
#include "imap-arg.h"
#include "imap-resp-code.h"
+#include "mailbox-tree.h"
#include "imapc-mail.h"
#include "imapc-client-private.h"
#include "imapc-connection.h"
@@ -341,6 +342,23 @@
return &mbox->box;
}
+static int
+imapc_mailbox_exists(struct mailbox *box, bool auto_boxes ATTR_UNUSED,
+ enum mailbox_existence *existence_r)
+{
+ enum mailbox_info_flags flags;
+
+ if (imapc_list_get_mailbox_flags(box->list, box->name, &flags) < 0)
+ return -1;
+ if ((flags & MAILBOX_NONEXISTENT) != 0)
+ *existence_r = MAILBOX_EXISTENCE_NONE;
+ else if ((flags & MAILBOX_NOSELECT) != 0)
+ *existence_r = MAILBOX_EXISTENCE_NOSELECT;
+ else
+ *existence_r = MAILBOX_EXISTENCE_SELECT;
+ return 0;
+}
+
static void
imapc_mailbox_open_callback(const struct imapc_command_reply *reply,
void *context)
@@ -647,7 +665,7 @@
.v = {
index_storage_is_readonly,
index_storage_mailbox_enable,
- index_storage_mailbox_exists,
+ imapc_mailbox_exists,
imapc_mailbox_open,
imapc_mailbox_close,
index_storage_mailbox_free,
More information about the dovecot-cvs
mailing list