cydir-sync.c revision 1d2b188f0eedc3cab6e27ceac5425a037f38042e
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch/* Copyright (c) 2007-2009 Dovecot authors, see the included COPYING file */
088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainenstatic void cydir_sync_set_uidvalidity(struct cydir_sync_context *ctx)
c53af2efae7a3484a23412e9be2c8e81523ab65eTimo Sirainen offsetof(struct mail_index_header, uid_validity),
088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainenstatic string_t *cydir_get_path_prefix(struct cydir_mailbox *mbox)
6303191abcb37164f435ccdc56e9dbddf1288851Timo Sirainen const char *dir;
c53af2efae7a3484a23412e9be2c8e81523ab65eTimo Sirainen dir = mailbox_list_get_path(mbox->ibox.box.list, mbox->ibox.box.name,
7dc4bf28c0c4c673a198070edd1ed54e14ae39aeTimo Sirainencydir_sync_expunge(struct cydir_sync_context *ctx, uint32_t seq1, uint32_t seq2)
7dc4bf28c0c4c673a198070edd1ed54e14ae39aeTimo Sirainen ctx->path_dir_prefix_len = str_len(ctx->path);
088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainen mail_index_lookup_uid(ctx->sync_view, seq1, &uid);
088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainen str_truncate(ctx->path, ctx->path_dir_prefix_len);
088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainen mail_storage_set_critical(&ctx->mbox->storage->storage,
088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainen /* continue anyway */
c53af2efae7a3484a23412e9be2c8e81523ab65eTimo Sirainenstatic void cydir_sync_index(struct cydir_sync_context *ctx)
623eaaf530b2bd9cddbaeb88a211873ec9dee436Timo Sirainen /* mark the newly seen messages as recent */
623eaaf530b2bd9cddbaeb88a211873ec9dee436Timo Sirainen if (mail_index_lookup_seq_range(ctx->sync_view, hdr->first_recent_uid,
623eaaf530b2bd9cddbaeb88a211873ec9dee436Timo Sirainen index_mailbox_set_recent_seq(&ctx->mbox->ibox, ctx->sync_view,
c53af2efae7a3484a23412e9be2c8e81523ab65eTimo Sirainen while (mail_index_sync_next(ctx->index_sync_ctx, &sync_rec)) {
088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainen if (!mail_index_lookup_seq_range(ctx->sync_view,
088cb24027234024aff2c1ce5b6870c5a308a44bTimo Sirainen /* already expunged, nothing to do. */
7dc4bf28c0c4c673a198070edd1ed54e14ae39aeTimo Sirainen /* don't care */
7dc4bf28c0c4c673a198070edd1ed54e14ae39aeTimo Sirainen /* FIXME: should be bother calling sync_notify()? */
c53af2efae7a3484a23412e9be2c8e81523ab65eTimo Sirainenint cydir_sync_begin(struct cydir_mailbox *mbox,
c53af2efae7a3484a23412e9be2c8e81523ab65eTimo Sirainen struct cydir_sync_context **ctx_r, bool force)
2129efcd74a72d051d182171b7e07916308e386dTimo Sirainen sync_flags = MAIL_INDEX_SYNC_FLAG_FLUSH_DIRTY;
2129efcd74a72d051d182171b7e07916308e386dTimo Sirainen sync_flags |= MAIL_INDEX_SYNC_FLAG_DROP_RECENT;
c53af2efae7a3484a23412e9be2c8e81523ab65eTimo Sirainen sync_flags |= MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES;
2129efcd74a72d051d182171b7e07916308e386dTimo Sirainen ret = mail_index_sync_begin(mbox->ibox.index, &ctx->index_sync_ctx,
2129efcd74a72d051d182171b7e07916308e386dTimo Sirainenint cydir_sync_finish(struct cydir_sync_context **_ctx, bool success)
6303191abcb37164f435ccdc56e9dbddf1288851Timo Sirainen if (mail_index_sync_commit(&ctx->index_sync_ctx) < 0) {
6303191abcb37164f435ccdc56e9dbddf1288851Timo Sirainen mail_storage_set_index_error(&ctx->mbox->ibox);
6303191abcb37164f435ccdc56e9dbddf1288851Timo Sirainen mail_index_sync_rollback(&ctx->index_sync_ctx);
6303191abcb37164f435ccdc56e9dbddf1288851Timo Sirainenstatic int cydir_sync(struct cydir_mailbox *mbox)
c53af2efae7a3484a23412e9be2c8e81523ab65eTimo Sirainen if (cydir_sync_begin(mbox, &sync_ctx, FALSE) < 0)
struct mailbox_sync_context *
int ret = 0;