dovecot-1.2: Thread code cleanups + fixes
dovecot at dovecot.org
dovecot at dovecot.org
Fri Jun 20 05:37:40 EEST 2008
details: http://hg.dovecot.org/dovecot-1.2/rev/d987e018483b
changeset: 7906:d987e018483b
user: Timo Sirainen <tss at iki.fi>
date: Fri Jun 20 05:29:19 2008 +0300
description:
Thread code cleanups + fixes
diffstat:
3 files changed, 60 insertions(+), 38 deletions(-)
src/imap/cmd-thread.c | 10 ----
src/lib-storage/index/index-thread.c | 80 ++++++++++++++++++++++------------
src/lib-storage/mail-thread.h | 8 ++-
diffs (171 lines):
diff -r 3e8bcf4f6f5e -r d987e018483b src/imap/cmd-thread.c
--- a/src/imap/cmd-thread.c Fri Jun 20 04:41:03 2008 +0300
+++ b/src/imap/cmd-thread.c Fri Jun 20 05:29:19 2008 +0300
@@ -141,15 +141,7 @@ bool cmd_thread(struct client_command_co
}
str = IMAP_ARG_STR(args);
- if (strcasecmp(str, "REFERENCES") == 0)
- thread_type = MAIL_THREAD_REFERENCES;
- else if (strcasecmp(str, "X-REFERENCES2") == 0)
- thread_type = MAIL_THREAD_REFERENCES2;
- else if (strcasecmp(str, "ORDEREDSUBJECT") == 0) {
- client_send_command_error(cmd,
- "ORDEREDSUBJECT threading is currently not supported.");
- return TRUE;
- } else {
+ if (!mail_thread_type_parse(str, &thread_type)) {
client_send_command_error(cmd, "Unknown thread algorithm.");
return TRUE;
}
diff -r 3e8bcf4f6f5e -r d987e018483b src/lib-storage/index/index-thread.c
--- a/src/lib-storage/index/index-thread.c Fri Jun 20 04:41:03 2008 +0300
+++ b/src/lib-storage/index/index-thread.c Fri Jun 20 05:29:19 2008 +0300
@@ -8,6 +8,7 @@
#include "mail-index-private.h"
#include "mail-index-sync-private.h"
#include "mail-search.h"
+#include "mail-search-build.h"
#include "index-storage.h"
#include "index-thread-private.h"
@@ -40,6 +41,17 @@ struct mail_thread_mailbox {
static MODULE_CONTEXT_DEFINE_INIT(mail_thread_storage_module,
&mail_storage_module_register);
+
+bool mail_thread_type_parse(const char *str, enum mail_thread_type *type_r)
+{
+ if (strcasecmp(str, "REFERENCES") == 0)
+ *type_r = MAIL_THREAD_REFERENCES;
+ else if (strcasecmp(str, "X-REFERENCES2") == 0)
+ *type_r = MAIL_THREAD_REFERENCES2;
+ else
+ return FALSE;
+ return TRUE;
+}
static unsigned int mail_thread_hash_key(const void *key)
{
@@ -413,6 +425,13 @@ int mail_thread_init(struct mailbox *box
i_assert(tbox->ctx == NULL);
+ if (args != NULL)
+ mail_search_args_ref(args);
+ else {
+ args = mail_search_build_init();
+ mail_search_build_add_all(args);
+ }
+
ctx = i_new(struct mail_thread_context, 1);
tbox->ctx = &ctx->thread_ctx;
ctx->box = box;
@@ -421,6 +440,9 @@ int mail_thread_init(struct mailbox *box
while ((ret = mail_thread_update(ctx, reset)) < 0) {
if (ctx->thread_ctx.hash == tbox->hash) {
/* failed with in-memory hash */
+ mail_storage_set_critical(box->storage,
+ "Threading mailbox %s failed unexpectedly",
+ box->name);
mail_thread_deinit(&ctx);
return -1;
}
@@ -436,6 +458,36 @@ int mail_thread_init(struct mailbox *box
return 0;
}
+void mail_thread_deinit(struct mail_thread_context **_ctx)
+{
+ struct mail_thread_context *ctx = *_ctx;
+ struct mail_thread_mailbox *tbox = MAIL_THREAD_CONTEXT(ctx->box);
+ int ret;
+
+ *_ctx = NULL;
+
+ if (ctx->search_args->args == &ctx->tmp_search_arg)
+ ctx->search_args->args = ctx->tmp_search_arg.next;
+
+ mail_hash_transaction_end(&ctx->thread_ctx.hash_trans);
+
+ ret = mailbox_search_deinit(&ctx->search);
+ mail_free(&ctx->thread_ctx.tmp_mail);
+ (void)mailbox_transaction_commit(&ctx->t);
+
+ mail_hash_unlock(ctx->thread_ctx.hash);
+ if (ctx->thread_ctx.hash != tbox->hash)
+ mail_hash_free(&ctx->thread_ctx.hash);
+
+ array_free(&ctx->thread_ctx.msgid_cache);
+ pool_unref(&ctx->thread_ctx.msgid_pool);
+ mail_search_args_unref(&ctx->search_args);
+
+ i_assert(!tbox->ctx->syncing);
+ tbox->ctx = NULL;
+ i_free(ctx);
+}
+
struct mail_thread_iterate_context *
mail_thread_iterate_init(struct mail_thread_context *ctx,
enum mail_thread_type thread_type, bool write_seqs)
@@ -443,34 +495,6 @@ mail_thread_iterate_init(struct mail_thr
return mail_thread_iterate_init_full(ctx->thread_ctx.tmp_mail,
ctx->thread_ctx.hash_trans,
thread_type, write_seqs);
-}
-
-void mail_thread_deinit(struct mail_thread_context **_ctx)
-{
- struct mail_thread_context *ctx = *_ctx;
- struct mail_thread_mailbox *tbox = MAIL_THREAD_CONTEXT(ctx->box);
- int ret;
-
- *_ctx = NULL;
-
- if (ctx->search_args->args == &ctx->tmp_search_arg)
- ctx->search_args->args = ctx->tmp_search_arg.next;
-
- mail_hash_transaction_end(&ctx->thread_ctx.hash_trans);
-
- ret = mailbox_search_deinit(&ctx->search);
- mail_free(&ctx->thread_ctx.tmp_mail);
- (void)mailbox_transaction_commit(&ctx->t);
-
- mail_hash_unlock(ctx->thread_ctx.hash);
- if (ctx->thread_ctx.hash != tbox->hash)
- mail_hash_free(&ctx->thread_ctx.hash);
-
- array_free(&ctx->thread_ctx.msgid_cache);
- pool_unref(&ctx->thread_ctx.msgid_pool);
-
- i_assert(!tbox->ctx->syncing);
- tbox->ctx = NULL;
}
static bool
diff -r 3e8bcf4f6f5e -r d987e018483b src/lib-storage/mail-thread.h
--- a/src/lib-storage/mail-thread.h Fri Jun 20 04:41:03 2008 +0300
+++ b/src/lib-storage/mail-thread.h Fri Jun 20 05:29:19 2008 +0300
@@ -1,6 +1,8 @@
#ifndef MAIL_THREAD_H
#define MAIL_THREAD_H
+struct mailbox;
+struct mail_search_args;
struct mail_thread_context;
enum mail_thread_type {
@@ -20,8 +22,12 @@ struct mail_thread_child_node {
};
ARRAY_DEFINE_TYPE(mail_thread_child_node, struct mail_thread_child_node);
+/* Convert thread type string to enum. Returns TRUE if ok, FALSE if type is
+ unknown. */
+bool mail_thread_type_parse(const char *str, enum mail_thread_type *type_r);
+
/* Build thread from given search arguments. If reset=TRUE, build a new thread
- tree to memory even if thread index exists. */
+ tree to memory even if thread index exists. args=NULL searches everything. */
int mail_thread_init(struct mailbox *box, bool reset,
struct mail_search_args *args,
struct mail_thread_context **ctx_r);
More information about the dovecot-cvs
mailing list