dovecot-1.2: expire: Settings now support spaces in mailbox name...

dovecot at dovecot.org dovecot at dovecot.org
Thu Dec 10 02:46:25 EET 2009


details:   http://hg.dovecot.org/dovecot-1.2/rev/91c6b067f464
changeset: 9502:91c6b067f464
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Dec 09 19:44:35 2009 -0500
description:
expire: Settings now support spaces in mailbox names by using quoted strings.

diffstat:

1 file changed, 41 insertions(+), 5 deletions(-)
src/plugins/expire/expire-env.c |   46 ++++++++++++++++++++++++++++++++++-----

diffs (76 lines):

diff -r f1c4c0c90da1 -r 91c6b067f464 src/plugins/expire/expire-env.c
--- a/src/plugins/expire/expire-env.c	Wed Dec 09 18:58:13 2009 -0500
+++ b/src/plugins/expire/expire-env.c	Wed Dec 09 19:44:35 2009 -0500
@@ -2,6 +2,8 @@
 
 #include "lib.h"
 #include "array.h"
+#include "str.h"
+#include "strescape.h"
 #include "imap-match.h"
 #include "expire-env.h"
 
@@ -25,6 +27,34 @@ struct expire_env {
 	ARRAY_DEFINE(expire_boxes, struct expire_box);
 };
 
+static const char *quoted_string_get(char *const **namesp)
+{
+	string_t *str = t_str_new(128);
+	char *const *names = *namesp;
+	const char *name;
+	unsigned int i;
+
+	name = (*names) + 1;
+	for (;;) {
+		for (i = 0; name[i] != '\0'; i++) {
+			if (name[i] == '\\' &&
+			    name[i+1] != '\0')
+				i++;
+			else if (name[i] == '"')
+				break;
+		}
+		str_append_unescaped(str, name, i);
+		names++;
+		if (name[i] == '"' || *names == NULL)
+			break;
+
+		str_append_c(str, ' ');
+		name = *names;
+	}
+	*namesp = names;
+	return str_c(str);
+}
+
 static void expire_env_parse(struct expire_env *env, const char *str,
 			     enum expire_type type)
 {
@@ -39,17 +69,23 @@ static void expire_env_parse(struct expi
 	len = str_array_length((const char *const *)names);
 
 	p_array_init(&env->expire_boxes, env->pool, len / 2);
-	for (; *names != NULL; names += 2) {
-		if (names[1] == NULL) {
+	for (; *names != NULL; names++) {
+		if (**names == '"') {
+			/* quoted string. */
+			box.pattern = quoted_string_get(&names);
+		} else {
+			box.pattern = *names;
+			names++;
+		}
+		if (*names == NULL) {
 			i_fatal("expire: Missing expire days for mailbox '%s'",
-				*names);
+				box.pattern);
 		}
 
-		box.pattern = *names;
 		/* FIXME: hardcoded separator isn't very good */
 		box.glob = imap_match_init(env->pool, box.pattern, TRUE, '/');
 		box.type = type;
-		box.expire_secs = strtoul(names[1], NULL, 10) * 3600 * 24;
+		box.expire_secs = strtoul(*names, NULL, 10) * 3600 * 24;
 
 		if (getenv("DEBUG") != NULL) {
 			i_info("expire: pattern=%s type=%s secs=%u",


More information about the dovecot-cvs mailing list