index-sync.c revision 26ff8f8a4867bf8e9551a27a2de8c12cd138b065
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington/* Copyright (C) 2002 Timo Sirainen */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fostervoid index_mailbox_set_recent(struct index_mailbox *ibox, uint32_t seq)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster unsigned char *p;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ibox->recent_flags = buffer_create_dynamic(default_pool, 128);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (seq < ibox->recent_flags_start_seq) {
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington dest_idx = ibox->recent_flags_start_seq - seq;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster memset(buffer_get_modifyable_data(ibox->recent_flags, NULL),
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster p = buffer_get_space_unsafe(ibox->recent_flags,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (*p == 0) {
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonint index_mailbox_is_recent(struct index_mailbox *ibox, uint32_t seq)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster const unsigned char *data;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster data = buffer_get_data(ibox->recent_flags, &size);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterstatic void index_mailbox_expunge_recent(struct index_mailbox *ibox,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster const unsigned char *data;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington /* no recent flags */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* expunging messages before recent flags, just modify
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster the recent start position */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ibox->recent_flags_start_seq -= seq2 - seq1 + 1;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster data = buffer_get_data(ibox->recent_flags, &size);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (i = 0; i < count; i++) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster buffer_write_zero(ibox->recent_flags, size - count, count);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster buffer_set_used_size(ibox->recent_flags, size - count);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterstatic int index_mailbox_update_recent(struct index_mailbox *ibox,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (mail_index_lookup(ibox->view, seq1, &rec) < 0) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterindex_mailbox_sync_init(struct mailbox *box, enum mailbox_sync_flags flags,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster struct index_mailbox *ibox = (struct index_mailbox *)box;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ctx = i_new(struct index_mailbox_sync_context, 1);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ctx->messages_count = mail_index_view_get_messages_count(ibox->view);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((flags & MAILBOX_SYNC_FLAG_NO_EXPUNGES) != 0)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (mail_index_view_sync_begin(ibox->view, sync_mask,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster index_mailbox_update_recent(ibox, 1, ctx->messages_count);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((flags & MAILBOX_SYNC_FLAG_NO_EXPUNGES) == 0) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mail_index_view_sync_get_expunges(ctx->sync_ctx,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterint index_mailbox_sync_next(struct mailbox_sync_context *_ctx,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster while ((ret = mail_index_view_sync_next(ctx->sync_ctx, &sync)) > 0) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* not interested */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* FIXME: hide the flag updates for expunged messages */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (mail_index_lookup_uid_range(ctx->ibox->view,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* expunges[] is a sorted array of sequences. it's easiest for
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster us to print them from end to beginning. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster sync_rec_r->seq1 = ctx->expunges[ctx->expunges_count*2-2];
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster sync_rec_r->seq2 = ctx->expunges[ctx->expunges_count*2-1];
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster index_mailbox_expunge_recent(ctx->ibox, sync_rec_r->seq1,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ctx->messages_count -= sync_rec_r->seq2 - sync_rec_r->seq1 + 1;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster (STATUS_MESSAGES | STATUS_RECENT | STATUS_UIDNEXT | \
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster STATUS_UIDVALIDITY | STATUS_UNSEEN | STATUS_KEYWORDS)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterint index_mailbox_sync_deinit(struct mailbox_sync_context *_ctx,
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington messages_count = mail_index_view_get_messages_count(ibox->view);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ibox->synced_recent_count = ibox->recent_flags_count;