index-sync.c revision a5cc9935581d9503b5f77097390d903b8add6c44
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen/* Copyright (C) 2002 Timo Sirainen */
6789ed17e7ca4021713507baf0dcf6979bb42e0cTimo Sirainenvoid index_mailbox_set_recent(struct index_mailbox *ibox, uint32_t seq)
6789ed17e7ca4021713507baf0dcf6979bb42e0cTimo Sirainen unsigned char *p;
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen ibox->recent_flags = buffer_create_dynamic(default_pool, 128);
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen } else if (seq < ibox->recent_flags_start_seq) {
6789ed17e7ca4021713507baf0dcf6979bb42e0cTimo Sirainen dest_idx = ibox->recent_flags_start_seq - seq;
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen memset(buffer_get_modifiable_data(ibox->recent_flags, NULL),
6789ed17e7ca4021713507baf0dcf6979bb42e0cTimo Sirainen p = buffer_get_space_unsafe(ibox->recent_flags,
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen if (*p == 0) {
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainenbool index_mailbox_is_recent(struct index_mailbox *ibox, uint32_t seq)
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen const unsigned char *data;
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen data = buffer_get_data(ibox->recent_flags, &size);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic void index_mailbox_expunge_recent(struct index_mailbox *ibox,
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen const unsigned char *data;
4c07b08af30e1065f7022980b60474f229d8cadfTimo Sirainen /* no recent flags */
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen /* expunging messages before recent flags, just modify
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen the recent start position */
e60a349c641bb2f4723e4a395a25f55531682d2bTimo Sirainen ibox->recent_flags_start_seq -= seq2 - seq1 + 1;
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen data = buffer_get_data(ibox->recent_flags, &size);
88ea893b45d3ed8d68000921db9156c03cbe1b00Timo Sirainen for (i = 0; i < count; i++) {
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen buffer_write_zero(ibox->recent_flags, size - count, count);
88ea893b45d3ed8d68000921db9156c03cbe1b00Timo Sirainen buffer_set_used_size(ibox->recent_flags, size - count);
88ea893b45d3ed8d68000921db9156c03cbe1b00Timo Sirainenstatic int index_mailbox_update_recent(struct index_mailbox *ibox,
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen if (mail_index_lookup(ibox->view, seq1, &rec) < 0) {
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainenindex_mailbox_sync_init(struct mailbox *box, enum mailbox_sync_flags flags,
88ea893b45d3ed8d68000921db9156c03cbe1b00Timo Sirainen struct index_mailbox *ibox = (struct index_mailbox *)box;
88ea893b45d3ed8d68000921db9156c03cbe1b00Timo Sirainen ctx = i_new(struct index_mailbox_sync_context, 1);
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen ctx->messages_count = mail_index_view_get_messages_count(ibox->view);
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen if ((flags & MAILBOX_SYNC_FLAG_NO_EXPUNGES) != 0)
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen if ((flags & MAILBOX_SYNC_FLAG_NO_NEWMAIL) != 0)
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen if (mail_index_view_sync_begin(ibox->view, sync_mask,
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen index_mailbox_update_recent(ibox, 1, ctx->messages_count);
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen if ((flags & MAILBOX_SYNC_FLAG_NO_EXPUNGES) == 0) {
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen mail_index_view_sync_get_expunges(ctx->sync_ctx,
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen ctx->expunge_pos = array_count(ctx->expunges);
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainenstatic bool sync_rec_check_skips(struct index_mailbox_sync_context *ctx,
88ea893b45d3ed8d68000921db9156c03cbe1b00Timo Sirainen /* FIXME: we're only skipping messages from the beginning and from
88ea893b45d3ed8d68000921db9156c03cbe1b00Timo Sirainen the end. we should skip also the middle ones. This takes care of
88ea893b45d3ed8d68000921db9156c03cbe1b00Timo Sirainen the most common repeats though. */
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen /* skip expunged messages from the beginning and the end */
5ce2084ada06ade9f44fc2914c34658e9a842dc1Timo Sirainen for (seq = sync_rec->seq1; seq <= sync_rec->seq2; seq++) {
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen /* everything skipped */
d21f14c01d5546f4bf1b2cbb28ac1f00c24d952aTimo Sirainen for (seq = sync_rec->seq2; seq >= sync_rec->seq1; seq--) {
5ce2084ada06ade9f44fc2914c34658e9a842dc1Timo Sirainenint index_mailbox_sync_next(struct mailbox_sync_context *_ctx,
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen while ((ret = mail_index_view_sync_next(ctx->sync_ctx, &sync)) > 0) {
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen /* not interested */
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen /* FIXME: hide the flag updates for expunged messages */
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen if (mail_index_lookup_uid_range(ctx->ibox->view,
d21f14c01d5546f4bf1b2cbb28ac1f00c24d952aTimo Sirainen /* expunges is a sorted array of sequences. it's easiest for
d21f14c01d5546f4bf1b2cbb28ac1f00c24d952aTimo Sirainen us to print them from end to beginning. */
d21f14c01d5546f4bf1b2cbb28ac1f00c24d952aTimo Sirainen range = array_idx(ctx->expunges, ctx->expunge_pos);
d21f14c01d5546f4bf1b2cbb28ac1f00c24d952aTimo Sirainen index_mailbox_expunge_recent(ctx->ibox, sync_rec_r->seq1,
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen ctx->messages_count -= sync_rec_r->seq2 - sync_rec_r->seq1 + 1;
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainenint index_mailbox_sync_deinit(struct mailbox_sync_context *_ctx,
79fcd3f95a6266cc62ceaa753e56dd4456ab7c4bTimo Sirainen messages_count = mail_index_view_get_messages_count(ibox->view);
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen ibox->synced_recent_count = ibox->recent_flags_count;
1e62ad3955db977d527fa57d9584e504a8c26fd5Timo Sirainen index_storage_get_status_locked(ctx->ibox, status_items,
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainenbool index_keyword_array_cmp(const ARRAY_TYPE(keyword_indexes) *k1,
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen return !array_is_created(k2) || array_count(k2) == 0;
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen /* The arrays may not be sorted, but they usually are. Optimize for
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen the assumption that they are */
5ce2084ada06ade9f44fc2914c34658e9a842dc1Timo Sirainen for (i = 0; i < count1; i++) {
5ce2084ada06ade9f44fc2914c34658e9a842dc1Timo Sirainen /* not found / unsorted array. check. */
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen for (j = 0; j < count1; j++) {