Mercurial > dovecot > original-hg > dovecot-1.2
changeset 951:6f1e87a51872 HEAD
SORT and THREAD didn't work with sequence numbers at all. SEARCH was also a
bit broken with it if another session had deleted messages which we hadn't
yet told to client.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 11 Jan 2003 20:55:01 +0200 |
parents | ceb3ea5e1a2a |
children | 5c8cd0bf94c1 |
files | src/lib-storage/index/index-search.c src/lib-storage/index/index-sort.c src/lib-storage/index/index-sort.h |
diffstat | 3 files changed, 63 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/index/index-search.c Sat Jan 11 19:48:25 2003 +0200 +++ b/src/lib-storage/index/index-search.c Sat Jan 11 20:55:01 2003 +0200 @@ -824,6 +824,7 @@ struct mail_search_arg *args, struct mail_sort_context *sort_ctx, struct mail_thread_context *thread_ctx, + struct index_sort_context *index_sort_ctx, struct ostream *output, int uid_result) { struct search_index_context ctx; @@ -850,6 +851,7 @@ rec->uid, last_uid, &expunges_before); client_seq += expunges_before; + index_sort_ctx->synced_sequences = expunges->uid1 == 0; memset(&ctx, 0, sizeof(ctx)); ctx.ibox = ibox; @@ -860,8 +862,8 @@ while (expunges->uid1 != 0 && expunges->uid1 < rec->uid) { i_assert(expunges->uid2 < rec->uid); + client_seq += expunges->seq_count; expunges++; - client_seq += expunges->seq_count; } i_assert(!(expunges->uid1 <= rec->uid && expunges->uid2 >= rec->uid)); @@ -897,10 +899,16 @@ } if (found) { + unsigned int id = uid_result ? + rec->uid : client_seq; + + index_sort_ctx->current_client_seq = client_seq; + index_sort_ctx->current_rec = rec; + if (sort_ctx != NULL) - mail_sort_input(sort_ctx, rec->uid); + mail_sort_input(sort_ctx, id); else if (thread_ctx != NULL) { - mail_thread_input(thread_ctx, rec->uid, + mail_thread_input(thread_ctx, id, ctx.message_id, ctx.in_reply_to, ctx.references, @@ -908,8 +916,7 @@ } else { o_stream_send(output, " ", 1); - str = dec2str(uid_result ? rec->uid : - client_seq); + str = dec2str(id); o_stream_send_str(output, str); } } @@ -946,6 +953,7 @@ memset(&index_sort_ctx, 0, sizeof(index_sort_ctx)); index_sort_ctx.ibox = ibox; index_sort_ctx.output = output; + index_sort_ctx.id_is_uid = uid_result; thread_ctx = NULL; sort_ctx = mail_sort_init(sort_unsorted, sorting, output, @@ -955,6 +963,7 @@ } else if (threading != MAIL_THREAD_NONE) { memset(&index_sort_ctx, 0, sizeof(index_sort_ctx)); index_sort_ctx.ibox = ibox; + index_sort_ctx.id_is_uid = uid_result; sort_ctx = NULL; thread_ctx = mail_thread_init(threading, output, @@ -962,13 +971,14 @@ &index_sort_ctx); o_stream_send_str(output, "* THREAD"); } else { + memset(&index_sort_ctx, 0, sizeof(index_sort_ctx)); sort_ctx = NULL; thread_ctx = NULL; o_stream_send_str(output, "* SEARCH"); } failed = !search_messages(ibox, charset, args, sort_ctx, thread_ctx, - output, uid_result); + &index_sort_ctx, output, uid_result); if (sort_ctx != NULL) mail_sort_deinit(sort_ctx); if (thread_ctx != NULL)
--- a/src/lib-storage/index/index-sort.c Sat Jan 11 19:48:25 2003 +0200 +++ b/src/lib-storage/index/index-sort.c Sat Jan 11 20:55:01 2003 +0200 @@ -6,22 +6,55 @@ #include "imap-envelope.h" #include "imap-message-cache.h" #include "mail-index.h" +#include "mail-modifylog.h" #include "index-storage.h" #include "index-sort.h" -static struct imap_message_cache * -search_open_cache(struct index_sort_context *ctx, unsigned int uid) +static struct mail_index_record * +lookup_client_seq(struct index_sort_context *ctx, unsigned int client_seq) { - i_assert(uid != 0); + struct mail_index_record *rec; + unsigned int expunges_before; + + if (ctx->synced_sequences) + return ctx->ibox->index->lookup(ctx->ibox->index, client_seq); - if (ctx->last_uid != uid) { + t_push(); + if (mail_modifylog_seq_get_expunges(ctx->ibox->index->modifylog, + client_seq, client_seq, + &expunges_before) == NULL) { + rec = NULL; + } else { + rec = ctx->ibox->index->lookup(ctx->ibox->index, + client_seq - expunges_before); + } + t_pop(); + + return rec; +} + +static struct imap_message_cache * +search_open_cache(struct index_sort_context *ctx, unsigned int id) +{ + i_assert(id != 0); + + if (ctx->last_id != id) { ctx->cached = FALSE; - ctx->last_uid = uid; + ctx->last_id = id; - ctx->rec = ctx->ibox->index->lookup_uid_range(ctx->ibox->index, - uid, uid, NULL); + if ((ctx->id_is_uid && ctx->current_rec->uid == id) || + (!ctx->id_is_uid && ctx->current_client_seq == id)) { + ctx->rec = ctx->current_rec; + } else if (ctx->id_is_uid) { + ctx->rec = ctx->ibox->index-> + lookup_uid_range(ctx->ibox->index, + id, id, NULL); + } else { + ctx->rec = lookup_client_seq(ctx, id); + } + if (ctx->rec == NULL) { - ctx->last_uid = 0; + ctx->last_id = 0; return NULL; } }
--- a/src/lib-storage/index/index-sort.h Sat Jan 11 19:48:25 2003 +0200 +++ b/src/lib-storage/index/index-sort.h Sat Jan 11 20:55:01 2003 +0200 @@ -8,10 +8,15 @@ struct index_mailbox *ibox; struct ostream *output; - unsigned int last_uid; + unsigned int current_client_seq; + struct mail_index_record *current_rec; + + unsigned int last_id; struct mail_index_record *rec; unsigned int cached:1; + unsigned int id_is_uid:1; + unsigned int synced_sequences:1; }; extern struct mail_sort_callbacks index_sort_callbacks;