]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Thread code cleanups + fixes
authorTimo Sirainen <tss@iki.fi>
Fri, 20 Jun 2008 02:29:19 +0000 (05:29 +0300)
committerTimo Sirainen <tss@iki.fi>
Fri, 20 Jun 2008 02:29:19 +0000 (05:29 +0300)
--HG--
branch : HEAD

src/imap/cmd-thread.c
src/lib-storage/index/index-thread.c
src/lib-storage/mail-thread.h

index bd862593b06d65ebff44eeddea51ea02fa700e68..6e57c20f5e87dac139cfec8373315bcf1dae299d 100644 (file)
@@ -141,15 +141,7 @@ bool cmd_thread(struct client_command_context *cmd)
        }
 
        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;
        }
index a649196085e9226a211db5dde93749d55472cc59..7e9b63e99febf8fd6594d32f322b736be848ccaa 100644 (file)
@@ -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"
 
@@ -41,6 +42,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)
 {
        const struct msgid_search_key *key_rec = key;
@@ -413,6 +425,13 @@ int mail_thread_init(struct mailbox *box, bool reset,
 
        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, bool reset,
        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,15 +458,6 @@ int mail_thread_init(struct mailbox *box, bool reset,
        return 0;
 }
 
-struct mail_thread_iterate_context *
-mail_thread_iterate_init(struct mail_thread_context *ctx,
-                        enum mail_thread_type thread_type, bool write_seqs)
-{
-       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;
@@ -468,9 +481,20 @@ void mail_thread_deinit(struct mail_thread_context **_ctx)
 
        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)
+{
+       return mail_thread_iterate_init_full(ctx->thread_ctx.tmp_mail,
+                                            ctx->thread_ctx.hash_trans,
+                                            thread_type, write_seqs);
 }
 
 static bool
index 600865bede9ff0cea0a1784543558148cfbaca43..c5ebe998ca5bc975a43adeb35e46fa1427faf381 100644 (file)
@@ -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);