cydir-sync.c revision e9fbe5e18b798728041b7e2ffc6c4fa964fc35a3
2435290e44809a9e6036dbb2701933c44cb0b0e7Stephan Bosch/* Copyright (c) 2007-2018 Dovecot authors, see the included COPYING file */
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainenstatic void cydir_sync_set_uidvalidity(struct cydir_sync_context *ctx)
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen offsetof(struct mail_index_header, uid_validity),
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainenstatic string_t *cydir_get_path_prefix(struct cydir_mailbox *mbox)
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen str_append(path, mailbox_get_path(&mbox->box));
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainencydir_sync_expunge(struct cydir_sync_context *ctx, uint32_t seq1, uint32_t seq2)
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen ctx->path_dir_prefix_len = str_len(ctx->path);
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen mail_index_lookup_uid(ctx->sync_view, seq1, &uid);
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen str_truncate(ctx->path, ctx->path_dir_prefix_len);
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen if (i_unlink_if_exists(str_c(ctx->path)) < 0) {
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen /* continue anyway */
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainenstatic void cydir_sync_index(struct cydir_sync_context *ctx)
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen /* mark the newly seen messages as recent */
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen if (mail_index_lookup_seq_range(ctx->sync_view, hdr->first_recent_uid,
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen mailbox_recent_flags_set_seqs(&ctx->mbox->box, ctx->sync_view,
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen while (mail_index_sync_next(ctx->index_sync_ctx, &sync_rec)) {
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen if (!mail_index_lookup_seq_range(ctx->sync_view,
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen /* already expunged, nothing to do. */
6f213bf43fe6c0f2f2192330d591b4e62d72b4bcTimo Sirainen /* FIXME: should be bother calling sync_notify()? */
5329bb264c32fa887e53063ff53272160cb8d7e8Timo Sirainenint cydir_sync_begin(struct cydir_mailbox *mbox,
5329bb264c32fa887e53063ff53272160cb8d7e8Timo Sirainen struct cydir_sync_context **ctx_r, bool force)
5329bb264c32fa887e53063ff53272160cb8d7e8Timo Sirainen sync_flags = index_storage_get_sync_flags(&mbox->box) |
5329bb264c32fa887e53063ff53272160cb8d7e8Timo Sirainen sync_flags |= MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES;
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen ret = index_storage_expunged_sync_begin(&mbox->box, &ctx->index_sync_ctx,
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainenint cydir_sync_finish(struct cydir_sync_context **_ctx, bool success)
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen if (mail_index_sync_commit(&ctx->index_sync_ctx) < 0) {
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen mail_index_sync_rollback(&ctx->index_sync_ctx);
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainenstatic int cydir_sync(struct cydir_mailbox *mbox)
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen if (cydir_sync_begin(mbox, &sync_ctx, FALSE) < 0)
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainencydir_storage_sync_init(struct mailbox *box, enum mailbox_sync_flags flags)
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen struct cydir_mailbox *mbox = CYDIR_MAILBOX(box);
5233c86a95d3865500c291f00d08b1f4c678a424Timo Sirainen if (index_mailbox_want_full_sync(&mbox->box, flags))