]> 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)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Mon, 22 May 2017 12:12:52 +0000 (15:12 +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 a009e0ecb83f1a30a6d7241669f619496351c846..8a8dffcbae82b7587b74c2a91baec06762339517 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 ac5985b3468ea963bfb02ae99c20e9a7f00030d4..0bd6b3a4ec8f9adf0a3891aca0c7312435d13df4 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);