]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap: Allow plugins to replace existing FETCH handlers
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 19 May 2017 13:34:29 +0000 (16:34 +0300)
committerGitLab <gitlab@git.dovecot.net>
Sat, 20 May 2017 18:22:59 +0000 (21:22 +0300)
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.

src/imap/imap-fetch.c
src/imap/imap-fetch.h

index 901cf82a276c5ab629523d84297380b7ba8c0b74..1c09b3d47e872604355628f9c6346e5ad54fc0ec 100644 (file)
@@ -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;
index 33b06ed3fd9c7a185561792c82b31f6af0edae9a..8f5fd5c3867255d62c7e5227acb36ee3d2841226 100644 (file)
@@ -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);