dovecot-2.0: Moved pop3_uidl_format checking to mail-storage-set...

dovecot at dovecot.org dovecot at dovecot.org
Thu Apr 30 22:02:53 EEST 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/e4cc93190ec3
changeset: 9177:e4cc93190ec3
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Apr 30 14:48:00 2009 -0400
description:
Moved pop3_uidl_format checking to mail-storage-settings.

diffstat:

8 files changed, 100 insertions(+), 69 deletions(-)
src/config/settings-get.pl              |    1 
src/lib-storage/mail-storage-settings.c |   31 ++++++++++++++
src/pop3/client.c                       |   65 +++++++++++++++++++++++++++++++
src/pop3/client.h                       |    1 
src/pop3/commands.c                     |    2 
src/pop3/main.c                         |   64 ------------------------------
src/pop3/pop3-settings.c                |    4 -
src/pop3/pop3-settings.h                |    1 

diffs (truncated from 305 to 300 lines):

diff -r cf026a9180f1 -r e4cc93190ec3 src/config/settings-get.pl
--- a/src/config/settings-get.pl	Wed Apr 29 15:34:34 2009 -0400
+++ b/src/config/settings-get.pl	Thu Apr 30 14:48:00 2009 -0400
@@ -3,6 +3,7 @@ use strict;
 
 print '#include "lib.h"'."\n";
 print '#include "array.h"'."\n";
+print '#include "var-expand.h"'."\n";
 print '#include "settings-parser.h"'."\n";
 print '#include "all-settings.h"'."\n";
 print '#include <stddef.h>'."\n";
diff -r cf026a9180f1 -r e4cc93190ec3 src/lib-storage/mail-storage-settings.c
--- a/src/lib-storage/mail-storage-settings.c	Wed Apr 29 15:34:34 2009 -0400
+++ b/src/lib-storage/mail-storage-settings.c	Thu Apr 30 14:48:00 2009 -0400
@@ -2,6 +2,7 @@
 
 #include "lib.h"
 #include "array.h"
+#include "var-expand.h"
 #include "settings-parser.h"
 #include "mail-index.h"
 #include "mail-user.h"
@@ -279,6 +280,9 @@ static bool mail_storage_settings_check(
 					const char **error_r)
 {
 	const struct mail_storage_settings *set = _set;
+	const char *p;
+	bool uidl_format_ok;
+	char c;
 
 	if (set->mail_nfs_index && !set->mmap_disable) {
 		*error_r = "mail_nfs_index=yes requires mmap_disable=yes";
@@ -286,6 +290,33 @@ static bool mail_storage_settings_check(
 	}
 	if (set->mail_nfs_index && set->fsync_disable) {
 		*error_r = "mail_nfs_index=yes requires fsync_disable=no";
+		return FALSE;
+	}
+
+	uidl_format_ok = FALSE;
+	for (p = set->pop3_uidl_format; *p != '\0'; p++) {
+		if (p[0] != '%' || p[1] == '\0')
+			continue;
+
+		c = var_get_key(++p);
+		switch (c) {
+		case 'v':
+		case 'u':
+		case 'm':
+		case 'f':
+			uidl_format_ok = TRUE;
+			break;
+		case '%':
+			break;
+		default:
+			*error_r = t_strdup_printf(
+				"Unknown pop3_uidl_format variable: %%%c", c);
+			return FALSE;
+		}
+	}
+	if (!uidl_format_ok) {
+		*error_r = "pop3_uidl_format setting doesn't contain any "
+			"%% variables.";
 		return FALSE;
 	}
 	return TRUE;
diff -r cf026a9180f1 -r e4cc93190ec3 src/pop3/client.c
--- a/src/pop3/client.c	Wed Apr 29 15:34:34 2009 -0400
+++ b/src/pop3/client.c	Thu Apr 30 14:48:00 2009 -0400
@@ -33,6 +33,17 @@
    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 *my_client; /* we don't need more than one currently */
 
 static void client_input(struct client *client);
@@ -153,6 +164,53 @@ static bool init_mailbox(struct client *
 	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)
+{
+	enum uidl_keys mask = 0;
+
+	for (; *format != '\0'; format++) {
+		if (format[0] == '%' && format[1] != '\0') {
+			switch (var_get_key(++format)) {
+			case 'v':
+				mask |= UIDL_UIDVALIDITY;
+				break;
+			case 'u':
+				mask |= UIDL_UID;
+				break;
+			case 'm':
+				mask |= UIDL_MD5;
+				break;
+			case 'f':
+				mask |= UIDL_FILE_NAME;
+				break;
+			}
+		}
+	}
+	return mask;
+}
+
 struct client *client_create(int fd_in, int fd_out, struct mail_user *user,
 			     const struct pop3_settings *set)
 {
@@ -196,6 +254,7 @@ struct client *client_create(int fd_in, 
 
 	storage = client->inbox_ns->storage;
 
+	client->mail_set = mail_storage_get_settings(storage);
 	flags = MAILBOX_OPEN_POP3_SESSION;
 	if (set->pop3_no_flag_updates)
 		flags |= MAILBOX_OPEN_KEEP_RECENT;
@@ -217,6 +276,12 @@ struct client *client_create(int fd_in, 
 		client_destroy(client, "Mailbox init failed");
 		return NULL;
 	}
+
+	client->workarounds = parse_workarounds(set);
+	client->uidl_keymask =
+		parse_uidl_keymask(client->mail_set->pop3_uidl_format);
+	if (client->uidl_keymask == 0)
+		i_fatal("Invalid pop3_uidl_format");
 
 	if (!set->pop3_no_flag_updates && client->messages_count > 0)
 		client->seen_bitmask = i_malloc(MSGS_BITMASK_SIZE(client));
diff -r cf026a9180f1 -r e4cc93190ec3 src/pop3/client.h
--- a/src/pop3/client.h	Wed Apr 29 15:34:34 2009 -0400
+++ b/src/pop3/client.h	Thu Apr 30 14:48:00 2009 -0400
@@ -49,6 +49,7 @@ struct client {
 
 	/* settings: */
 	const struct pop3_settings *set;
+	const struct mail_storage_settings *mail_set;
 	enum client_workarounds workarounds;
 	enum uidl_keys uidl_keymask;
 
diff -r cf026a9180f1 -r e4cc93190ec3 src/pop3/commands.c
--- a/src/pop3/commands.c	Wed Apr 29 15:34:34 2009 -0400
+++ b/src/pop3/commands.c	Thu Apr 30 14:48:00 2009 -0400
@@ -561,7 +561,7 @@ static void pop3_get_uid(struct client *
 			i_fatal("UIDL: File name not found");
 		}
 	}
-	var_expand(str, client->set->pop3_uidl_format, tab);
+	var_expand(str, client->mail_set->pop3_uidl_format, tab);
 }
 
 static bool list_uids_iter(struct client *client, struct cmd_uidl_context *ctx)
diff -r cf026a9180f1 -r e4cc93190ec3 src/pop3/main.c
--- a/src/pop3/main.c	Wed Apr 29 15:34:34 2009 -0400
+++ b/src/pop3/main.c	Thu Apr 30 14:48:00 2009 -0400
@@ -19,17 +19,6 @@
 #define IS_STANDALONE() \
         (getenv("LOGGED_IN") == NULL)
 
-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 }
-};
-
 struct master_service *service;
 void (*hook_client_created)(struct client **client) = NULL;
 
@@ -41,53 +30,6 @@ static void log_error_callback(void *con
 	i_set_failure_ignore_errors(TRUE);
 
 	master_service_stop(service);
-}
-
-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)
-{
-	enum uidl_keys mask = 0;
-
-	for (; *format != '\0'; format++) {
-		if (format[0] == '%' && format[1] != '\0') {
-			switch (var_get_key(++format)) {
-			case 'v':
-				mask |= UIDL_UIDVALIDITY;
-				break;
-			case 'u':
-				mask |= UIDL_UID;
-				break;
-			case 'm':
-				mask |= UIDL_MD5;
-				break;
-			case 'f':
-				mask |= UIDL_FILE_NAME;
-				break;
-			}
-		}
-	}
-	return mask;
 }
 
 static bool main_init(const struct pop3_settings *set, struct mail_user *user)
@@ -107,12 +49,6 @@ static bool main_init(const struct pop3_
 	client = client_create(0, 1, user, set);
 	if (client == NULL)
 		return FALSE;
-	client->workarounds = parse_workarounds(set);
-	client->uidl_keymask = parse_uidl_keymask(set->pop3_uidl_format);
-	if (client->uidl_keymask == 0) {
-		i_fatal("pop3_uidl_format setting doesn't contain any "
-			"%% variables.");
-	}
 
 	if (!IS_STANDALONE())
 		client_send_line(client, "+OK Logged in.");
diff -r cf026a9180f1 -r e4cc93190ec3 src/pop3/pop3-settings.c
--- a/src/pop3/pop3-settings.c	Wed Apr 29 15:34:34 2009 -0400
+++ b/src/pop3/pop3-settings.c	Thu Apr 30 14:48:00 2009 -0400
@@ -27,7 +27,6 @@ static struct setting_define pop3_settin
 	DEF(SET_BOOL, pop3_lock_session),
 	DEF(SET_STR, pop3_client_workarounds),
 	DEF(SET_STR, pop3_logout_format),
-	DEF(SET_STR, pop3_uidl_format),
 
 	SETTING_DEFINE_LIST_END
 };
@@ -42,8 +41,7 @@ static struct pop3_settings pop3_default
 	MEMBER(pop3_reuse_xuidl) FALSE,
 	MEMBER(pop3_lock_session) FALSE,
 	MEMBER(pop3_client_workarounds) "",
-	MEMBER(pop3_logout_format) "top=%t/%p, retr=%r/%b, del=%d/%m, size=%s",
-	MEMBER(pop3_uidl_format) "%08Xu%08Xv"
+	MEMBER(pop3_logout_format) "top=%t/%p, retr=%r/%b, del=%d/%m, size=%s"
 };
 
 struct setting_parser_info pop3_setting_parser_info = {
diff -r cf026a9180f1 -r e4cc93190ec3 src/pop3/pop3-settings.h
--- a/src/pop3/pop3-settings.h	Wed Apr 29 15:34:34 2009 -0400
+++ b/src/pop3/pop3-settings.h	Thu Apr 30 14:48:00 2009 -0400
@@ -15,7 +15,6 @@ struct pop3_settings {
 	bool pop3_lock_session;
 	const char *pop3_client_workarounds;


More information about the dovecot-cvs mailing list