Skip to content

Commit

Permalink
imap: Allow plugins to hook into syncing.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sirainen authored and GitLab committed Apr 27, 2017
1 parent 55d35a8 commit d64280b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/imap/imap-client.c
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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,
};
4 changes: 4 additions & 0 deletions src/imap/imap-client.h
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions src/imap/imap-sync-private.h
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/imap/imap-sync.c
Expand Up @@ -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. */
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}
Expand Down

0 comments on commit d64280b

Please sign in to comment.