changeset 9177:e4cc93190ec3 HEAD

Moved pop3_uidl_format checking to mail-storage-settings.
author Timo Sirainen <tss@iki.fi>
date Thu, 30 Apr 2009 14:48:00 -0400
parents cf026a9180f1
children 13bbdd7b15b8
files src/config/settings-get.pl src/lib-storage/mail-storage-settings.c src/pop3/client.c src/pop3/client.h src/pop3/commands.c src/pop3/main.c src/pop3/pop3-settings.c src/pop3/pop3-settings.h
diffstat 8 files changed, 100 insertions(+), 69 deletions(-) [+]
line wrap: on
line diff
--- 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 @@
 
 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";
--- 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 @@
 					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";
@@ -288,6 +292,33 @@
 		*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;
 }
 
--- 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 @@
 	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 @@
 
 	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;
@@ -218,6 +277,12 @@
 		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));
 
--- 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 @@
 
 	/* settings: */
 	const struct pop3_settings *set;
+	const struct mail_storage_settings *mail_set;
 	enum client_workarounds workarounds;
 	enum uidl_keys uidl_keymask;
 
--- 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 @@
 			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)
--- 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;
 
@@ -43,53 +32,6 @@
 	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)
 {
 	struct client *client;
@@ -107,12 +49,6 @@
 	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.");
--- 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 @@
 	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 @@
 	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 = {
--- 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 @@
 	bool pop3_lock_session;
 	const char *pop3_client_workarounds;
 	const char *pop3_logout_format;
-	const char *pop3_uidl_format;
 };
 
 extern struct setting_parser_info pop3_setting_parser_info;