summaryrefslogtreecommitdiffstats
path: root/src/lib-index/mail-cache-sync-update.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:51:24 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:51:24 +0000
commitf7548d6d28c313cf80e6f3ef89aed16a19815df1 (patch)
treea3f6f2a3f247293bee59ecd28e8cd8ceb6ca064a /src/lib-index/mail-cache-sync-update.c
parentInitial commit. (diff)
downloaddovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.tar.xz
dovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.zip
Adding upstream version 1:2.3.19.1+dfsg1.upstream/1%2.3.19.1+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/lib-index/mail-cache-sync-update.c')
-rw-r--r--src/lib-index/mail-cache-sync-update.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/lib-index/mail-cache-sync-update.c b/src/lib-index/mail-cache-sync-update.c
new file mode 100644
index 0000000..9073187
--- /dev/null
+++ b/src/lib-index/mail-cache-sync-update.c
@@ -0,0 +1,68 @@
+/* Copyright (c) 2004-2018 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "mail-cache-private.h"
+#include "mail-index-sync-private.h"
+
+struct mail_cache_sync_context {
+ unsigned expunge_count;
+};
+
+void mail_cache_expunge_count(struct mail_cache *cache, unsigned int count)
+{
+ if (mail_cache_lock(cache) > 0) {
+ cache->hdr_copy.deleted_record_count += count;
+ if (cache->hdr_copy.record_count >= count)
+ cache->hdr_copy.record_count -= count;
+ else
+ cache->hdr_copy.record_count = 0;
+ cache->hdr_modified = TRUE;
+ (void)mail_cache_flush_and_unlock(cache);
+ }
+}
+
+static struct mail_cache_sync_context *mail_cache_handler_init(void **context)
+{
+ struct mail_cache_sync_context *ctx;
+
+ if (*context != NULL)
+ ctx = *context;
+ else {
+ *context = i_new(struct mail_cache_sync_context, 1);
+ ctx = *context;
+ }
+ return ctx;
+}
+
+static void mail_cache_handler_deinit(struct mail_index_sync_map_ctx *sync_ctx,
+ struct mail_cache_sync_context *ctx)
+{
+ struct mail_cache *cache = sync_ctx->view->index->cache;
+
+ if (ctx == NULL)
+ return;
+
+ mail_cache_expunge_count(cache, ctx->expunge_count);
+
+ i_free(ctx);
+}
+
+int mail_cache_expunge_handler(struct mail_index_sync_map_ctx *sync_ctx,
+ const void *data, void **sync_context)
+{
+ struct mail_cache_sync_context *ctx = *sync_context;
+ const uint32_t *cache_offset = data;
+
+ if (data == NULL) {
+ mail_cache_handler_deinit(sync_ctx, ctx);
+ *sync_context = NULL;
+ return 0;
+ }
+
+ if (*cache_offset == 0)
+ return 0;
+
+ ctx = mail_cache_handler_init(sync_context);
+ ctx->expunge_count++;
+ return 0;
+}