Mercurial > dovecot > core-2.2
changeset 22064:dd22be453dea
imap: Allow plugins to replace existing FETCH handlers
They can use imap_fetch_handler_lookup() to get the old init() function.
Then they can imap_fetch_handler_unregister() the existing handler and
register a new handler, which can do its own work and call the old init()
if needed.
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Fri, 19 May 2017 16:34:29 +0300 |
parents | de0cf622817b |
children | 03842e0c632f |
files | src/imap/imap-fetch.c src/imap/imap-fetch.h |
diffstat | 2 files changed, 17 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/imap/imap-fetch.c Wed May 17 16:47:43 2017 +0300 +++ b/src/imap/imap-fetch.c Fri May 19 16:34:29 2017 +0300 @@ -37,12 +37,27 @@ array_sort(&fetch_handlers, imap_fetch_handler_cmp); } +void imap_fetch_handler_unregister(const char *name) +{ + const struct imap_fetch_handler *handler, *first_handler; + + first_handler = array_idx(&fetch_handlers, 0); + handler = imap_fetch_handler_lookup(name); + i_assert(handler != NULL); + array_delete(&fetch_handlers, handler - first_handler, 1); +} + static int imap_fetch_handler_bsearch(const char *name, const struct imap_fetch_handler *h) { return strcmp(name, h->name); } +const struct imap_fetch_handler *imap_fetch_handler_lookup(const char *name) +{ + return array_bsearch(&fetch_handlers, name, imap_fetch_handler_bsearch); +} + bool imap_fetch_init_handler(struct imap_fetch_init_context *init_ctx) { const struct imap_fetch_handler *handler;
--- a/src/imap/imap-fetch.h Wed May 17 16:47:43 2017 +0300 +++ b/src/imap/imap-fetch.h Fri May 19 16:34:29 2017 +0300 @@ -103,6 +103,7 @@ void imap_fetch_handlers_register(const struct imap_fetch_handler *handlers, size_t count); +void imap_fetch_handler_unregister(const char *name); void imap_fetch_add_handler(struct imap_fetch_init_context *ctx, enum imap_fetch_handler_flags flags, @@ -127,6 +128,7 @@ bool imap_fetch_init_handler(struct imap_fetch_init_context *init_ctx); void imap_fetch_init_nofail_handler(struct imap_fetch_context *ctx, bool (*init)(struct imap_fetch_init_context *)); +const struct imap_fetch_handler *imap_fetch_handler_lookup(const char *name); void imap_fetch_begin(struct imap_fetch_context *ctx, struct mailbox *box, struct mail_search_args *search_args);