mail-index-view-sync.c revision ebee99dd900dc68fa280b1e93b8a71706013b31b
b9f30617c2c96d54acbc4f85ed17b939c4f28916Timo Sirainen/* Copyright (c) 2003-2009 Dovecot authors, see the included COPYING file */
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen /* After syncing view, map is replaced with sync_new_map. */
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen /* temporary variables while handling lost transaction logs: */
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen ARRAY_TYPE(keyword_indexes) lost_old_kw, lost_new_kw;
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen /* result of lost transaction logs: */
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainenmail_transaction_log_sort_expunges(ARRAY_TYPE(seq_range) *expunges,
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen /* Note that all the sequences are actually still UIDs at this point */
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen /* @UNSAFE */
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen dest = array_get_modifiable(expunges, &dest_count);
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen array_append(expunges, src, src_size / sizeof(*src));
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen /* src[] must be sorted. */
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen (src+1 != src_end && src->seq2 >= src[1].seq1))
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen for (; i < dest_count; i++) {
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen while (i < dest_count && src->seq2 >= dest[i].seq1-1) {
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen /* we can/must merge with next record */
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen if (first > 0 && new_exp.seq1 <= dest[first-1].seq2+1) {
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen /* continue previous record */
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen } else if (i == first) {
e9e5e84ffb2ce2e606a24ce6d930580367562ff0Timo Sirainen dest = array_get_modifiable(expunges, &dest_count);
e9e5e84ffb2ce2e606a24ce6d930580367562ff0Timo Sirainen /* use next record */
383d0e8c24451468d6bea17e4b55d74de744abe6Timo Sirainen dest = array_get_modifiable(expunges, &dest_count);
a8284e999d091cd29210fa75ecdc8076376a7345Timo Sirainenview_sync_set_log_view_range(struct mail_index_view *view, bool sync_expunges,
a8284e999d091cd29210fa75ecdc8076376a7345Timo Sirainen const struct mail_index_header *hdr = &view->index->map->hdr;
a8284e999d091cd29210fa75ecdc8076376a7345Timo Sirainen /* the view begins from the first non-synced transaction */
a8284e999d091cd29210fa75ecdc8076376a7345Timo Sirainen ret = mail_transaction_log_view_set(view->log_view,
a8284e999d091cd29210fa75ecdc8076376a7345Timo Sirainen /* log was reset, but we don't want to sync expunges.
a8284e999d091cd29210fa75ecdc8076376a7345Timo Sirainen we can't do this, so sync only up to the reset. */
a8284e999d091cd29210fa75ecdc8076376a7345Timo Sirainen mail_transaction_log_view_get_prev_pos(view->log_view,
a8284e999d091cd29210fa75ecdc8076376a7345Timo Sirainen /* we have only this reset log */
a8284e999d091cd29210fa75ecdc8076376a7345Timo Sirainen mail_transaction_log_view_clear(view->log_view,
a8284e999d091cd29210fa75ecdc8076376a7345Timo Sirainenstatic unsigned int
a8284e999d091cd29210fa75ecdc8076376a7345Timo Sirainenview_sync_expunges2seqs(struct mail_index_view_sync_ctx *ctx)
a8284e999d091cd29210fa75ecdc8076376a7345Timo Sirainen /* convert UIDs to sequences */
a8284e999d091cd29210fa75ecdc8076376a7345Timo Sirainen src = dest = array_get_modifiable(&ctx->expunges, &count);
count--;
dest++;
return expunge_count;
unsigned int *expunge_count_r)
const void *data;
int ret;
return TRUE;
return FALSE;
const void *data;
int ret;
return FALSE;
const unsigned int *kw_idx;
const char *const *kw_names;
unsigned int i, count;
if (count == 0)
for (i = 0; i < count; i++) {
&flag_update) < 0)
&kw_reset) < 0)
if (changed) {
if (changed)
unsigned int *expunge_count_r)
for (; i < old_count; i++) {
for (; j < new_count; j++) {
bool reset;
struct mail_index_view_sync_ctx *
unsigned int expunge_count = 0;
int ret;
if (sync_expunges)
return ctx;
return ctx;
if (ret < 0) {
return ctx;
if (ret == 0) {
if (!sync_expunges)
if (ret < 0) {
return ctx;
} else if (sync_expunges) {
return ctx;
if (!have_expunges) {
if (sync_expunges) {
#ifdef DEBUG
return ctx;
unsigned int i, count;
return FALSE;
for (i = 0; i < count; i++) {
return TRUE;
return FALSE;
return FALSE;
return FALSE;
return FALSE;
return TRUE;
int ret;
bool synced_to_map;
if (ret <= 0) {
if (ret < 0)
} T_END;
if (ret < 0)
case MAIL_TRANSACTION_FLAG_UPDATE: {
case MAIL_TRANSACTION_KEYWORD_UPDATE: {
case MAIL_TRANSACTION_KEYWORD_RESET: {
return FALSE;
return TRUE;
unsigned int count;
return FALSE;
return TRUE;
int ret;
if (ret <= 0) {
if (ret < 0)
return FALSE;
return TRUE;
unsigned int i, count;
for (i = 0; i < count; i++) {
bool *delayed_expunges_r)
#ifdef DEBUG
return ret;
unsigned int length)