cydir-sync.c revision ccec5f82349eae44087900c0e64ed1fd5a1a6fca
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen/* Copyright (C) 2007 Timo Sirainen */
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainenstatic int cydir_sync_set_uidvalidity(struct cydir_sync_context *ctx)
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen offsetof(struct mail_index_header, uid_validity),
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainenstatic string_t *cydir_get_path_prefix(struct cydir_mailbox *mbox)
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen const char *dir;
ccc895c0358108d2304239063e940b7d75f364abTimo Sirainen dir = mailbox_list_get_path(mbox->storage->storage.list,
5137d2d80255938a0f5fb8f3c1a21b34cf11ada3Timo Sirainencydir_sync_expunge(struct cydir_sync_context *ctx, uint32_t seq1, uint32_t seq2)
5137d2d80255938a0f5fb8f3c1a21b34cf11ada3Timo Sirainen ctx->path_dir_prefix_len = str_len(ctx->path);
5137d2d80255938a0f5fb8f3c1a21b34cf11ada3Timo Sirainen if (mail_index_lookup_uid(ctx->sync_view, seq1, &uid) < 0) {
5137d2d80255938a0f5fb8f3c1a21b34cf11ada3Timo Sirainen mail_storage_set_index_error(&ctx->mbox->ibox);
5137d2d80255938a0f5fb8f3c1a21b34cf11ada3Timo Sirainen str_truncate(ctx->path, ctx->path_dir_prefix_len);
5137d2d80255938a0f5fb8f3c1a21b34cf11ada3Timo Sirainen mail_storage_set_critical(&ctx->mbox->storage->storage,
5137d2d80255938a0f5fb8f3c1a21b34cf11ada3Timo Sirainen /* continue anyway */
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainenstatic int cydir_sync_index(struct cydir_sync_context *ctx)
1d3f7c1278168d5b1cbfa9a2cc9929a0909056b4Timo Sirainen /* mark the newly seen messages as recent */
1d3f7c1278168d5b1cbfa9a2cc9929a0909056b4Timo Sirainen if (mail_index_lookup_uid_range(ctx->sync_view, hdr->first_recent_uid,
1d3f7c1278168d5b1cbfa9a2cc9929a0909056b4Timo Sirainen mail_storage_set_index_error(&ctx->mbox->ibox);
1d3f7c1278168d5b1cbfa9a2cc9929a0909056b4Timo Sirainen index_mailbox_set_recent_seq(&ctx->mbox->ibox, ctx->sync_view,
4b41116563110d00330896a568eff1078c382827Timo Sirainen while (ret > 0 &&
4b41116563110d00330896a568eff1078c382827Timo Sirainen (ret = mail_index_sync_next(ctx->index_sync_ctx,
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen if (mail_index_lookup_uid_range(ctx->sync_view,
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen mail_storage_set_index_error(&ctx->mbox->ibox);
5137d2d80255938a0f5fb8f3c1a21b34cf11ada3Timo Sirainen /* already expunged, nothing to do. */
5137d2d80255938a0f5fb8f3c1a21b34cf11ada3Timo Sirainen /* don't care */
5137d2d80255938a0f5fb8f3c1a21b34cf11ada3Timo Sirainen /* FIXME: should be bother calling sync_notify()? */
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainenint cydir_sync_begin(struct cydir_mailbox *mbox,
2d39dc1a453546892109b35c0d9770369011a13dTimo Sirainen sync_flags = MAIL_INDEX_SYNC_FLAG_FLUSH_DIRTY;
2d39dc1a453546892109b35c0d9770369011a13dTimo Sirainen sync_flags |= MAIL_INDEX_SYNC_FLAG_DROP_RECENT;
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen ret = mail_index_sync_begin(mbox->ibox.index, &ctx->index_sync_ctx,
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen mail_index_sync_rollback(&ctx->index_sync_ctx);
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainenint cydir_sync_finish(struct cydir_sync_context **_ctx, bool success)
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen if (mail_index_sync_commit(&ctx->index_sync_ctx) < 0) {
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen mail_storage_set_index_error(&ctx->mbox->ibox);
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen mail_index_sync_rollback(&ctx->index_sync_ctx);
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainencydir_storage_sync_init(struct mailbox *box, enum mailbox_sync_flags flags)
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen struct cydir_mailbox *mbox = (struct cydir_mailbox *)box;
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen mbox->ibox.sync_last_check + MAILBOX_FULL_SYNC_INTERVAL <=