dovecot-2.0-sslstream: imap, pop3: Moved imap/pop3_client_workar...

dovecot at dovecot.org dovecot at dovecot.org
Sat Feb 13 02:55:11 EET 2010


details:   http://hg.dovecot.org/dovecot-2.0-sslstream/rev/fdfe0236d50a
changeset: 10094:fdfe0236d50a
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Oct 16 17:46:31 2009 -0400
description:
imap, pop3: Moved imap/pop3_client_workarounds setting parsing to config checking.

diffstat:

15 files changed, 138 insertions(+), 92 deletions(-)
src/imap/cmd-subscribe.c      |    3 +-
src/imap/imap-client.h        |    1 
src/imap/imap-commands-util.c |    3 +-
src/imap/imap-common.h        |    6 ----
src/imap/imap-fetch-body.c    |    2 -
src/imap/imap-settings.c      |   58 ++++++++++++++++++++++++++++++++++++++++-
src/imap/imap-settings.h      |   10 +++++++
src/imap/imap-sync.c          |    2 -
src/imap/main.c               |   37 --------------------------
src/pop3/pop3-client.c        |   34 ------------------------
src/pop3/pop3-client.h        |    1 
src/pop3/pop3-commands.c      |    4 +-
src/pop3/pop3-common.h        |    5 ---
src/pop3/pop3-settings.c      |   55 ++++++++++++++++++++++++++++++++++++++
src/pop3/pop3-settings.h      |    9 ++++++

diffs (truncated from 434 to 300 lines):

diff -r 4d21bb0fff3a -r fdfe0236d50a src/imap/cmd-subscribe.c
--- a/src/imap/cmd-subscribe.c	Sun Oct 18 15:33:13 2009 -0400
+++ b/src/imap/cmd-subscribe.c	Fri Oct 16 17:46:31 2009 -0400
@@ -60,7 +60,8 @@ bool cmd_subscribe_full(struct client_co
 		mailbox += strlen(ns->prefix);
 	}
 
-	if ((cmd->client->workarounds & WORKAROUND_TB_EXTRA_MAILBOX_SEP) != 0 &&
+	if ((cmd->client->set->parsed_workarounds &
+	     		WORKAROUND_TB_EXTRA_MAILBOX_SEP) != 0 &&
 	    *mailbox != '\0' && mailbox[strlen(mailbox)-1] ==
 	    mailbox_list_get_hierarchy_sep(ns->list)) {
 		/* verify the validity without the trailing '/' */
diff -r 4d21bb0fff3a -r fdfe0236d50a src/imap/imap-client.h
--- a/src/imap/imap-client.h	Sun Oct 18 15:33:13 2009 -0400
+++ b/src/imap/imap-client.h	Fri Oct 16 17:46:31 2009 -0400
@@ -95,7 +95,6 @@ struct client {
 	struct timeout *to_idle, *to_idle_output;
 
         const struct imap_settings *set;
-	enum client_workarounds workarounds;
 	string_t *capability_string;
 
         struct mail_user *user;
diff -r 4d21bb0fff3a -r fdfe0236d50a src/imap/imap-commands-util.c
--- a/src/imap/imap-commands-util.c	Sun Oct 18 15:33:13 2009 -0400
+++ b/src/imap/imap-commands-util.c	Fri Oct 16 17:46:31 2009 -0400
@@ -46,7 +46,8 @@ client_find_namespace(struct client_comm
 	}
 
 	mailbox_len = strlen(mailbox);
-	if ((cmd->client->workarounds & WORKAROUND_TB_EXTRA_MAILBOX_SEP) != 0 &&
+	if ((cmd->client->set->parsed_workarounds &
+	     		WORKAROUND_TB_EXTRA_MAILBOX_SEP) != 0 &&
 	    mailbox[mailbox_len-1] == mailbox_list_get_hierarchy_sep(ns->list)) {
 		/* drop the extra trailing hierarchy separator */
 		mailbox = t_strndup(mailbox, mailbox_len-1);
diff -r 4d21bb0fff3a -r fdfe0236d50a src/imap/imap-common.h
--- a/src/imap/imap-common.h	Sun Oct 18 15:33:13 2009 -0400
+++ b/src/imap/imap-common.h	Fri Oct 16 17:46:31 2009 -0400
@@ -13,12 +13,6 @@
 /* Disconnect client when it sends too many bad commands in a row */
 #define CLIENT_MAX_BAD_COMMANDS 20
 
-enum client_workarounds {
-	WORKAROUND_DELAY_NEWMAIL		= 0x01,
-	WORKAROUND_NETSCAPE_EOH			= 0x04,
-	WORKAROUND_TB_EXTRA_MAILBOX_SEP		= 0x08
-};
-
 #include "lib.h"
 #include "imap-client.h"
 #include "imap-settings.h"
diff -r 4d21bb0fff3a -r fdfe0236d50a src/imap/imap-fetch-body.c
--- a/src/imap/imap-fetch-body.c	Sun Oct 18 15:33:13 2009 -0400
+++ b/src/imap/imap-fetch-body.c	Fri Oct 16 17:46:31 2009 -0400
@@ -433,7 +433,7 @@ static int fetch_header_partial_from(str
 	i_stream_seek(ctx->cur_input, old_offset);
 
 	if (!ctx->cur_have_eoh &&
-	    (ctx->client->workarounds & WORKAROUND_NETSCAPE_EOH) != 0) {
+	    (ctx->client->set->parsed_workarounds & WORKAROUND_NETSCAPE_EOH) != 0) {
 		/* Netscape 4.x doesn't like if end of headers line is
 		   missing. */
 		msg_size.virtual_size += 2;
diff -r 4d21bb0fff3a -r fdfe0236d50a src/imap/imap-settings.c
--- a/src/imap/imap-settings.c	Sun Oct 18 15:33:13 2009 -0400
+++ b/src/imap/imap-settings.c	Fri Oct 16 17:46:31 2009 -0400
@@ -8,6 +8,9 @@
 #include <stddef.h>
 #include <stdlib.h>
 #include <unistd.h>
+
+static bool imap_settings_verify(void *_set, pool_t pool,
+				 const char **error_r);
 
 #undef DEF
 #undef DEFLIST
@@ -62,6 +65,59 @@ struct setting_parser_info imap_setting_
 	MEMBER(parent_offset) (size_t)-1,
 	MEMBER(type_offset) (size_t)-1,
 	MEMBER(struct_size) sizeof(struct imap_settings),
-	MEMBER(check_func) NULL,
+	MEMBER(check_func) imap_settings_verify,
 	MEMBER(dependencies) imap_setting_dependencies
 };
+
+/* <settings checks> */
+struct imap_client_workaround_list {
+	const char *name;
+	enum imap_client_workarounds num;
+};
+
+static struct imap_client_workaround_list imap_client_workaround_list[] = {
+	{ "delay-newmail", WORKAROUND_DELAY_NEWMAIL },
+	{ "outlook-idle", 0 }, /* only for backwards compatibility */
+	{ "netscape-eoh", WORKAROUND_NETSCAPE_EOH },
+	{ "tb-extra-mailbox-sep", WORKAROUND_TB_EXTRA_MAILBOX_SEP },
+	{ NULL, 0 }
+};
+
+static int
+imap_settings_parse_workarounds(struct imap_settings *set,
+				const char **error_r)
+{
+        enum imap_client_workarounds client_workarounds = 0;
+        struct imap_client_workaround_list *list;
+	const char *const *str;
+
+        str = t_strsplit_spaces(set->imap_client_workarounds, " ,");
+	for (; *str != NULL; str++) {
+		list = imap_client_workaround_list;
+		for (; list->name != NULL; list++) {
+			if (strcasecmp(*str, list->name) == 0) {
+				client_workarounds |= list->num;
+				break;
+			}
+		}
+		if (list->name == NULL) {
+			*error_r = t_strdup_printf("imap_client_workarounds: "
+				"Unknown workaround: %s", *str);
+			return -1;
+		}
+	}
+	set->parsed_workarounds = client_workarounds;
+	return 0;
+}
+
+
+static bool
+imap_settings_verify(void *_set, pool_t pool ATTR_UNUSED, const char **error_r)
+{
+	struct imap_settings *set = _set;
+
+	if (imap_settings_parse_workarounds(set, error_r) < 0)
+		return FALSE;
+	return TRUE;
+}
+/* </settings checks> */
diff -r 4d21bb0fff3a -r fdfe0236d50a src/imap/imap-settings.h
--- a/src/imap/imap-settings.h	Sun Oct 18 15:33:13 2009 -0400
+++ b/src/imap/imap-settings.h	Fri Oct 16 17:46:31 2009 -0400
@@ -2,6 +2,14 @@
 #define IMAP_SETTINGS_H
 
 struct mail_user_settings;
+
+/* <settings checks> */
+enum imap_client_workarounds {
+	WORKAROUND_DELAY_NEWMAIL		= 0x01,
+	WORKAROUND_NETSCAPE_EOH			= 0x04,
+	WORKAROUND_TB_EXTRA_MAILBOX_SEP		= 0x08
+};
+/* </settings checks> */
 
 struct imap_settings {
 	bool mail_debug;
@@ -15,6 +23,8 @@ struct imap_settings {
 	const char *imap_logout_format;
 	const char *imap_id_send;
 	const char *imap_id_log;
+
+	enum imap_client_workarounds parsed_workarounds;
 };
 
 extern struct setting_parser_info imap_setting_parser_info;
diff -r 4d21bb0fff3a -r fdfe0236d50a src/imap/imap-sync.c
--- a/src/imap/imap-sync.c	Sun Oct 18 15:33:13 2009 -0400
+++ b/src/imap/imap-sync.c	Fri Oct 16 17:46:31 2009 -0400
@@ -579,7 +579,7 @@ static bool cmd_sync_client(struct clien
 	get_common_sync_flags(client, &flags, &imap_flags);
 	client->sync_counter++;
 
-	no_newmail = (client->workarounds & WORKAROUND_DELAY_NEWMAIL) != 0 &&
+	no_newmail = (client->set->parsed_workarounds & WORKAROUND_DELAY_NEWMAIL) != 0 &&
 		(imap_flags & IMAP_SYNC_FLAG_SAFE) == 0;
 	if (no_newmail) {
 		/* expunges might break the client just as badly as new mail
diff -r 4d21bb0fff3a -r fdfe0236d50a src/imap/main.c
--- a/src/imap/main.c	Sun Oct 18 15:33:13 2009 -0400
+++ b/src/imap/main.c	Fri Oct 16 17:46:31 2009 -0400
@@ -23,43 +23,7 @@
 #define IS_STANDALONE() \
         (getenv("CLIENT_INPUT") == NULL)
 
-struct client_workaround_list {
-	const char *name;
-	enum client_workarounds num;
-};
-
-static struct client_workaround_list client_workaround_list[] = {
-	{ "delay-newmail", WORKAROUND_DELAY_NEWMAIL },
-	{ "outlook-idle", 0 }, /* only for backwards compatibility */
-	{ "netscape-eoh", WORKAROUND_NETSCAPE_EOH },
-	{ "tb-extra-mailbox-sep", WORKAROUND_TB_EXTRA_MAILBOX_SEP },
-	{ NULL, 0 }
-};
-
 void (*hook_client_created)(struct client **client) = NULL;
-
-static enum client_workarounds
-parse_workarounds(const struct imap_settings *set)
-{
-        enum client_workarounds client_workarounds = 0;
-        struct client_workaround_list *list;
-	const char *const *str;
-
-        str = t_strsplit_spaces(set->imap_client_workarounds, " ,");
-	for (; *str != NULL; str++) {
-		list = client_workaround_list;
-		for (; list->name != NULL; list++) {
-			if (strcasecmp(*str, list->name) == 0) {
-				client_workarounds |= list->num;
-				break;
-			}
-		}
-		if (list->name == NULL)
-			i_fatal("Unknown client workaround: %s", *str);
-	}
-
-	return client_workarounds;
-}
 
 static void client_add_input(struct client *client, const char *input)
 {
@@ -122,7 +86,6 @@ static void main_init(const struct imap_
 		master_service_set_die_with_master(master_service, TRUE);
 
 	client = client_create(0, 1, user, set);
-        client->workarounds = parse_workarounds(set);
 
 	if (dump_capability) {
 		printf("%s\n", str_c(client->capability_string));
diff -r 4d21bb0fff3a -r fdfe0236d50a src/pop3/pop3-client.c
--- a/src/pop3/pop3-client.c	Sun Oct 18 15:33:13 2009 -0400
+++ b/src/pop3/pop3-client.c	Fri Oct 16 17:46:31 2009 -0400
@@ -35,17 +35,6 @@
    transaction. This allows the mailbox to become unlocked. */
 #define CLIENT_COMMIT_TIMEOUT_MSECS (10*1000)
 
-struct client_workaround_list {
-	const char *name;
-	enum client_workarounds num;
-};
-
-static struct client_workaround_list client_workaround_list[] = {
-	{ "outlook-no-nuls", WORKAROUND_OUTLOOK_NO_NULS },
-	{ "oe-ns-eoh", WORKAROUND_OE_NS_EOH },
-	{ NULL, 0 }
-};
-
 static struct client *pop3_clients;
 
 static void client_input(struct client *client);
@@ -165,28 +154,6 @@ static bool init_mailbox(struct client *
 	}
 	buffer_free(&message_sizes_buf);
 	return FALSE;
-}
-
-static enum client_workarounds
-parse_workarounds(const struct pop3_settings *set)
-{
-        enum client_workarounds client_workarounds = 0;
-	struct client_workaround_list *list;
-	const char *const *str;
-
-        str = t_strsplit_spaces(set->pop3_client_workarounds, " ,");
-	for (; *str != NULL; str++) {
-		list = client_workaround_list;
-		for (; list->name != NULL; list++) {
-			if (strcasecmp(*str, list->name) == 0) {
-				client_workarounds |= list->num;
-				break;
-			}
-		}
-		if (list->name == NULL)
-			i_fatal("Unknown client workaround: %s", *str);
-	}
-	return client_workarounds;
 }
 
 static enum uidl_keys parse_uidl_keymask(const char *format)
@@ -281,7 +248,6 @@ struct client *client_create(int fd_in, 
 		return NULL;
 	}
 
-	client->workarounds = parse_workarounds(set);
 	client->uidl_keymask =
 		parse_uidl_keymask(client->mail_set->pop3_uidl_format);
 	if (client->uidl_keymask == 0)
diff -r 4d21bb0fff3a -r fdfe0236d50a src/pop3/pop3-client.h
--- a/src/pop3/pop3-client.h	Sun Oct 18 15:33:13 2009 -0400
+++ b/src/pop3/pop3-client.h	Fri Oct 16 17:46:31 2009 -0400
@@ -52,7 +52,6 @@ struct client {
 	/* settings: */
 	const struct pop3_settings *set;
 	const struct mail_storage_settings *mail_set;
-	enum client_workarounds workarounds;
 	enum uidl_keys uidl_keymask;


More information about the dovecot-cvs mailing list