index-sync.c revision ff78c4ba4e897026eb99788e0a6ac15e9205fcd7
45312f52ff3a3d4c137447be4c7556500c2f8bf2Timo Sirainen/* Copyright (c) 2002-2007 Dovecot authors, see the included COPYING file */
d80f37f025593d959bdfa9c378915e4322f4f504Timo Sirainenvoid index_mailbox_set_recent_uid(struct index_mailbox *ibox, uint32_t uid)
d80f37f025593d959bdfa9c378915e4322f4f504Timo Sirainen i_assert(seq_range_exists(&ibox->recent_flags, uid));
d80f37f025593d959bdfa9c378915e4322f4f504Timo Sirainen seq_range_array_add(&ibox->recent_flags, 64, uid);
4c892b0d94c5b1d6853dbe8e0b38059ea5b08ecaTimo Sirainenvoid index_mailbox_set_recent_seq(struct index_mailbox *ibox,
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainenbool index_mailbox_is_recent(struct index_mailbox *ibox, uint32_t uid)
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen return array_is_created(&ibox->recent_flags) &&
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainenunsigned int index_mailbox_get_recent_count(struct index_mailbox *ibox)
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen range = array_get(&ibox->recent_flags, &count);
d80f37f025593d959bdfa9c378915e4322f4f504Timo Sirainen for (i = count; i > 0; ) {
d80f37f025593d959bdfa9c378915e4322f4f504Timo Sirainen /* completely invisible to this view */
67c47dbb3fde79218320fd38a45c33f61bbf3012Timo Sirainen recent_count -= range[i].seq2 - range[i].seq1 + 1;
67c47dbb3fde79218320fd38a45c33f61bbf3012Timo Sirainen /* partially invisible */
67c47dbb3fde79218320fd38a45c33f61bbf3012Timo Sirainen recent_count -= range[i].seq2 - hdr->next_uid + 1;
d80f37f025593d959bdfa9c378915e4322f4f504Timo Sirainenstatic void index_mailbox_expunge_recent(struct index_mailbox *ibox,
a443e5aaf632257bfd1e7aa9b3c42c09512bbe43Timo Sirainen mail_index_lookup_uid(ibox->view, seq1, &uid);
a443e5aaf632257bfd1e7aa9b3c42c09512bbe43Timo Sirainen if (seq_range_array_remove(&ibox->recent_flags, uid))
a443e5aaf632257bfd1e7aa9b3c42c09512bbe43Timo Sirainenindex_mailbox_sync_init(struct mailbox *box, enum mailbox_sync_flags flags,
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen struct index_mailbox *ibox = (struct index_mailbox *)box;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen enum mail_index_view_sync_flags sync_flags = 0;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen ctx = i_new(struct index_mailbox_sync_context, 1);
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen if ((flags & MAILBOX_SYNC_FLAG_NO_EXPUNGES) != 0)
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen sync_flags |= MAIL_INDEX_VIEW_SYNC_FLAG_NOEXPUNGES;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen if ((flags & MAILBOX_SYNC_FLAG_FIX_INCONSISTENT) != 0) {
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen sync_flags |= MAIL_INDEX_VIEW_SYNC_FLAG_FIX_INCONSISTENT;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen mail_index_view_get_messages_count(ibox->view);
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen if (mail_index_view_sync_begin(ibox->view, sync_flags,
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen if ((flags & MAILBOX_SYNC_FLAG_NO_EXPUNGES) == 0) {
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen mail_index_view_sync_get_expunges(ctx->sync_ctx,
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen ctx->expunge_pos = array_count(ctx->expunges);
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainenstatic bool sync_rec_check_skips(struct index_mailbox_sync_context *ctx,
4654f788834c9d7920a351306b89cf5d1c21772eTimo Sirainen /* FIXME: we're only skipping messages from the beginning and from
94ce7e7700cda14a8342cb08e7285507b4b531daTimo Sirainen the end. we should skip also the middle ones. This takes care of
4654f788834c9d7920a351306b89cf5d1c21772eTimo Sirainen the most common repeats though. */
4654f788834c9d7920a351306b89cf5d1c21772eTimo Sirainen /* skip expunged messages from the beginning and the end */
4654f788834c9d7920a351306b89cf5d1c21772eTimo Sirainen for (seq = sync_rec->seq1; seq <= sync_rec->seq2; seq++) {
4654f788834c9d7920a351306b89cf5d1c21772eTimo Sirainen /* everything skipped */
4654f788834c9d7920a351306b89cf5d1c21772eTimo Sirainen for (seq = sync_rec->seq2; seq >= sync_rec->seq1; seq--) {
3398d5e2b883812de5d569721c8294b581e1d9e6Timo Sirainenindex_mailbox_sync_next_expunge(struct index_mailbox_sync_context *ctx,
96f2533c48ce5def0004931606a2fdf275578880Timo Sirainen /* expunges is a sorted array of sequences. it's easiest for
96f2533c48ce5def0004931606a2fdf275578880Timo Sirainen us to print them from end to beginning. */
67c47dbb3fde79218320fd38a45c33f61bbf3012Timo Sirainen range = array_idx(ctx->expunges, ctx->expunge_pos);
67c47dbb3fde79218320fd38a45c33f61bbf3012Timo Sirainen index_mailbox_expunge_recent(ctx->ibox, range->seq1, range->seq2);
67c47dbb3fde79218320fd38a45c33f61bbf3012Timo Sirainen ctx->messages_count -= range->seq2 - range->seq1 + 1;
67c47dbb3fde79218320fd38a45c33f61bbf3012Timo Sirainenbool index_mailbox_sync_next(struct mailbox_sync_context *_ctx,
67c47dbb3fde79218320fd38a45c33f61bbf3012Timo Sirainen while (mail_index_view_sync_next(ctx->sync_ctx, &sync)) {
67c47dbb3fde79218320fd38a45c33f61bbf3012Timo Sirainen /* not interested */
96f2533c48ce5def0004931606a2fdf275578880Timo Sirainen /* FIXME: hide the flag updates for expunged messages */
67c47dbb3fde79218320fd38a45c33f61bbf3012Timo Sirainen return index_mailbox_sync_next_expunge(ctx, sync_rec_r);
67c47dbb3fde79218320fd38a45c33f61bbf3012Timo Sirainenindex_mailbox_expunge_unseen_recent(struct index_mailbox_sync_context *ctx)
uid = 0;
#ifdef DEBUG
unsigned int i, count;
for (i = 0; i < count; i++) {
if (seq1 != 0) {
return ret;
return FALSE;
for (i = 0; i < count1; i++) {
for (j = 0; j < count1; j++) {
if (j == count1)
return FALSE;
return TRUE;