changeset 9071:106e4e3dccbc HEAD

IMAP: Register FETCH handlers at startup so we don't break if plugins add them.
author Timo Sirainen <tss@iki.fi>
date Thu, 21 May 2009 12:55:06 -0400
parents b57a14e489b3
children 43f15920dbaa
files src/imap/imap-fetch.c src/imap/imap-fetch.h src/imap/main.c
diffstat 3 files changed, 21 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/imap/imap-fetch.c	Thu May 21 12:46:17 2009 -0400
+++ b/src/imap/imap-fetch.c	Thu May 21 12:55:06 2009 -0400
@@ -22,10 +22,7 @@
 #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 *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 @@
 	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 @@
 	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 @@
 	{ "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);
+}
--- a/src/imap/imap-fetch.h	Thu May 21 12:46:17 2009 -0400
+++ b/src/imap/imap-fetch.h	Thu May 21 12:55:06 2009 -0400
@@ -113,4 +113,7 @@
 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
--- a/src/imap/main.c	Thu May 21 12:46:17 2009 -0400
+++ b/src/imap/main.c	Thu May 21 12:55:06 2009 -0400
@@ -15,6 +15,7 @@
 #include "dict.h"
 #include "mail-storage.h"
 #include "commands.h"
+#include "imap-fetch.h"
 #include "mail-namespace.h"
 
 #include <stdio.h>
@@ -208,6 +209,7 @@
 	mailbox_list_register_all();
 	clients_init();
 	commands_init();
+	imap_fetch_handlers_init();
 
 	module_dir_init(modules);
 
@@ -280,6 +282,7 @@
 	clients_deinit();
 
 	module_dir_unload(&modules);
+	imap_fetch_handlers_deinit();
 	commands_deinit();
 	mail_storage_deinit();
 	mail_users_deinit();