From: Timo Sirainen Date: Fri, 19 May 2017 13:34:29 +0000 (+0300) Subject: imap: Allow plugins to replace existing FETCH handlers X-Git-Tag: 2.3.0.rc1~1584 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=67c25cb4af273aff7384d5028d459cc9afdf8712;p=thirdparty%2Fdovecot%2Fcore.git 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. --- diff --git a/src/imap/imap-fetch.c b/src/imap/imap-fetch.c index 901cf82a27..1c09b3d47e 100644 --- a/src/imap/imap-fetch.c +++ b/src/imap/imap-fetch.c @@ -37,12 +37,27 @@ void imap_fetch_handlers_register(const struct imap_fetch_handler *handlers, 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; diff --git a/src/imap/imap-fetch.h b/src/imap/imap-fetch.h index 33b06ed3fd..8f5fd5c386 100644 --- a/src/imap/imap-fetch.h +++ b/src/imap/imap-fetch.h @@ -103,6 +103,7 @@ struct imap_fetch_context { 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 @@ void imap_fetch_free(struct imap_fetch_context **ctx); 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);