From d64280bc41338078701e79aefaab3169686b683d Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Wed, 26 Apr 2017 15:04:23 +0300 Subject: [PATCH] imap: Allow plugins to hook into syncing. Ideally all of the existing pieces in the syncing code would start using this at some point, so their code could be moved to a more logical location. --- src/imap/imap-client.c | 7 +++++++ src/imap/imap-client.h | 4 ++++ src/imap/imap-sync-private.h | 3 +++ src/imap/imap-sync.c | 5 +++++ 4 files changed, 19 insertions(+) diff --git a/src/imap/imap-client.c b/src/imap/imap-client.c index 4131abea13..cfd7e9791b 100644 --- a/src/imap/imap-client.c +++ b/src/imap/imap-client.c @@ -610,6 +610,12 @@ client_default_send_tagline(struct client_command_context *cmd, const char *data client->last_output = ioloop_time; } +static int +client_default_sync_notify_more(struct imap_sync_context *ctx ATTR_UNUSED) +{ + return 1; +} + void client_send_command_error(struct client_command_context *cmd, const char *msg) { @@ -1432,4 +1438,5 @@ struct imap_client_vfuncs imap_client_vfuncs = { imap_state_import_base, client_default_destroy, client_default_send_tagline, + client_default_sync_notify_more, }; diff --git a/src/imap/imap-client.h b/src/imap/imap-client.h index c723045265..5aa1bc967a 100644 --- a/src/imap/imap-client.h +++ b/src/imap/imap-client.h @@ -133,6 +133,10 @@ struct imap_client_vfuncs { void (*send_tagline)(struct client_command_context *cmd, const char *data); + /* Run "mailbox syncing". This can send any unsolicited untagged + replies. Returns 1 = done, 0 = wait for more space in output buffer, + -1 = failed. */ + int (*sync_notify_more)(struct imap_sync_context *ctx); }; struct client { diff --git a/src/imap/imap-sync-private.h b/src/imap/imap-sync-private.h index 21d4a1ee28..8d1c4d838d 100644 --- a/src/imap/imap-sync-private.h +++ b/src/imap/imap-sync-private.h @@ -25,6 +25,9 @@ struct imap_sync_context { unsigned int messages_count; + /* Module-specific contexts. */ + ARRAY(union imap_module_context *) module_contexts; + bool failed:1; bool finished:1; bool no_newmail:1; diff --git a/src/imap/imap-sync.c b/src/imap/imap-sync.c index 83a320f371..23140e8245 100644 --- a/src/imap/imap-sync.c +++ b/src/imap/imap-sync.c @@ -192,6 +192,7 @@ imap_sync_init(struct client *client, struct mailbox *box, ctx->client = client; ctx->box = box; ctx->imap_flags = imap_flags; + i_array_init(&ctx->module_contexts, 5); /* make sure user can't DoS the system by causing Dovecot to create tons of useless namespaces. */ @@ -341,6 +342,9 @@ static int imap_sync_notify_more(struct imap_sync_context *ctx) now it contains added/removed messages. */ if ((ret = imap_sync_send_search_updates(ctx, FALSE)) < 0) ctx->failed = TRUE; + + if (ret > 0) + ret = ctx->client->v.sync_notify_more(ctx); return ret; } @@ -362,6 +366,7 @@ int imap_sync_deinit(struct imap_sync_context *ctx, } array_free(&ctx->tmp_keywords); + array_free(&ctx->module_contexts); i_free(ctx); return ret; }