mail-cache-sync-update.c revision 38228c961f0e2c5fb8a0620a8ce620bb245dc88d
883N/A/* Copyright (c) 2004-2017 Dovecot authors, see the included COPYING file */
883N/A
883N/A#include "lib.h"
883N/A#include "mail-cache-private.h"
883N/A#include "mail-index-sync-private.h"
883N/A
883N/Astruct mail_cache_sync_context {
883N/A unsigned expunge_count;
883N/A};
883N/A
883N/Avoid mail_cache_expunge_count(struct mail_cache *cache, unsigned int count)
883N/A{
883N/A if (mail_cache_lock(cache) > 0) {
883N/A cache->hdr_copy.deleted_record_count += count;
883N/A if (cache->hdr_copy.record_count >= count)
883N/A cache->hdr_copy.record_count -= count;
883N/A else
883N/A cache->hdr_copy.record_count = 0;
883N/A cache->hdr_modified = TRUE;
883N/A (void)mail_cache_unlock(cache);
883N/A }
883N/A}
883N/A
883N/Astatic struct mail_cache_sync_context *mail_cache_handler_init(void **context)
883N/A{
883N/A struct mail_cache_sync_context *ctx;
883N/A
883N/A if (*context != NULL)
883N/A ctx = *context;
883N/A else {
883N/A *context = i_new(struct mail_cache_sync_context, 1);
883N/A ctx = *context;
883N/A }
883N/A return ctx;
883N/A}
883N/A
883N/Astatic void mail_cache_handler_deinit(struct mail_index_sync_map_ctx *sync_ctx,
883N/A struct mail_cache_sync_context *ctx)
883N/A{
883N/A struct mail_cache *cache = sync_ctx->view->index->cache;
883N/A
883N/A if (ctx == NULL)
956N/A return;
883N/A
883N/A mail_cache_expunge_count(cache, ctx->expunge_count);
883N/A
883N/A i_free(ctx);
883N/A}
883N/A
883N/Aint mail_cache_expunge_handler(struct mail_index_sync_map_ctx *sync_ctx,
883N/A uint32_t seq ATTR_UNUSED, const void *data,
883N/A void **sync_context, void *context ATTR_UNUSED)
883N/A{
883N/A struct mail_cache_sync_context *ctx = *sync_context;
883N/A const uint32_t *cache_offset = data;
883N/A
883N/A if (data == NULL) {
883N/A mail_cache_handler_deinit(sync_ctx, ctx);
883N/A *sync_context = NULL;
883N/A return 0;
883N/A }
887N/A
887N/A if (*cache_offset == 0)
887N/A return 0;
913N/A
913N/A ctx = mail_cache_handler_init(sync_context);
913N/A ctx->expunge_count++;
913N/A return 0;
883N/A}
883N/A