]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
IMAP: Register FETCH handlers at startup so we don't break if plugins add them.
authorTimo Sirainen <tss@iki.fi>
Thu, 21 May 2009 16:55:57 +0000 (12:55 -0400)
committerTimo Sirainen <tss@iki.fi>
Thu, 21 May 2009 16:55:57 +0000 (12:55 -0400)
--HG--
branch : HEAD

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

index 2a386265e183fccaf180b7646e22636018f23d79..58283e1044c38cb14f5fa141a6dbd22a01e4183f 100644 (file)
 #define ENVELOPE_NIL_REPLY \
        "(NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL)"
 
-#define IMAP_FETCH_HANDLER_COUNT 11
-extern const struct imap_fetch_handler
-       imap_fetch_default_handlers[IMAP_FETCH_HANDLER_COUNT];
-static buffer_t *fetch_handlers = NULL;
+static buffer_t *fetch_handlers;
 
 static int imap_fetch_handler_cmp(const void *p1, const void *p2)
 {
@@ -40,8 +37,6 @@ void imap_fetch_handlers_register(const struct imap_fetch_handler *handlers,
        void *data;
        size_t size;
 
-       if (fetch_handlers == NULL)
-               fetch_handlers = buffer_create_dynamic(default_pool, 128);
        buffer_append(fetch_handlers, handlers, sizeof(*handlers) * count);
 
        data = buffer_get_modifiable_data(fetch_handlers, &size);
@@ -91,11 +86,6 @@ imap_fetch_init(struct client_command_context *cmd, struct mailbox *box)
        struct client *client = cmd->client;
        struct imap_fetch_context *ctx;
 
-       if (fetch_handlers == NULL) {
-               imap_fetch_handlers_register(imap_fetch_default_handlers,
-                       N_ELEMENTS(imap_fetch_default_handlers));
-       }
-
        ctx = p_new(cmd->pool, struct imap_fetch_context, 1);
        ctx->client = client;
        ctx->cmd = cmd;
@@ -845,8 +835,8 @@ fetch_x_savedate_init(struct imap_fetch_context *ctx, const char *name,
        return TRUE;
 }
 
-const struct imap_fetch_handler
-imap_fetch_default_handlers[IMAP_FETCH_HANDLER_COUNT] = {
+static const struct imap_fetch_handler
+imap_fetch_default_handlers[] = {
        { "BODY", fetch_body_init },
        { "BODYSTRUCTURE", fetch_bodystructure_init },
        { "ENVELOPE", fetch_envelope_init },
@@ -859,3 +849,15 @@ imap_fetch_default_handlers[IMAP_FETCH_HANDLER_COUNT] = {
        { "X-MAILBOX", fetch_x_mailbox_init },
        { "X-SAVEDATE", fetch_x_savedate_init }
 };
+
+void imap_fetch_handlers_init(void)
+{
+       fetch_handlers = buffer_create_dynamic(default_pool, 128);
+       imap_fetch_handlers_register(imap_fetch_default_handlers,
+                                    N_ELEMENTS(imap_fetch_default_handlers));
+}
+
+void imap_fetch_handlers_deinit(void)
+{
+       buffer_free(&fetch_handlers);
+}
index b041dc6f435b3a73ef5418ac1c10f2c37f03a721..6a5228e308f6a811ad24d8d21cfbaa97cfab2ceb 100644 (file)
@@ -113,4 +113,7 @@ bool fetch_body_section_init(struct imap_fetch_context *ctx, const char *name,
 bool fetch_rfc822_init(struct imap_fetch_context *ctx, const char *name,
                       const struct imap_arg **args);
 
+void imap_fetch_handlers_init(void);
+void imap_fetch_handlers_deinit(void);
+
 #endif
index 69246c660de33d1dec6e281d828a09f6e23f3957..af903284515f4a9f4db12917d1780dcca349b37e 100644 (file)
@@ -13,6 +13,7 @@
 #include "mail-user.h"
 #include "mail-storage-service.h"
 #include "imap-commands.h"
+#include "imap-fetch.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -202,6 +203,7 @@ int main(int argc, char *argv[], char *envp[])
 
        /* plugins may want to add commands, so this needs to be called early */
        commands_init();
+       imap_fetch_handlers_init();
 
        mail_user = mail_storage_service_init_user(service, &input, set_roots,
                                                   storage_service_flags);
@@ -222,6 +224,7 @@ int main(int argc, char *argv[], char *envp[])
 
        main_deinit();
        mail_storage_service_deinit_user();
+       imap_fetch_handlers_deinit();
        commands_deinit();
 
        master_service_deinit(&service);