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

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


details:   http://hg.dovecot.org/dovecot-2.0/rev/ba7a62453316
changeset: 10444:ba7a62453316
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Dec 09 19:46:16 2009 -0500
description:
expire: Settings now support spaces in mailbox names by using quoted strings.

diffstat:

1 file changed, 42 insertions(+), 6 deletions(-)
src/plugins/expire/expire-env.c |   48 ++++++++++++++++++++++++++++++++++-----

diffs (82 lines):

diff -r b7ce62749fd7 -r ba7a62453316 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:46:16 2009 -0500
@@ -2,6 +2,8 @@
 
 #include "lib.h"
 #include "array.h"
+#include "str.h"
+#include "strescape.h"
 #include "imap-match.h"
 #include "mail-namespace.h"
 #include "expire-env.h"
@@ -26,6 +28,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, struct mail_namespace *namespaces,
 		 const char *str, enum expire_type type)
@@ -43,14 +73,20 @@ expire_env_parse(struct expire_env *env,
 	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;
-		ns_name = *names;
+		ns_name = box.pattern;
 		ns = mail_namespace_find(namespaces, &ns_name);
 		if (ns == NULL && *box.pattern != '*') {
 			i_warning("expire: No namespace found for mailbox: %s",
@@ -60,7 +96,7 @@ expire_env_parse(struct expire_env *env,
 		box.glob = imap_match_init(env->pool, box.pattern, TRUE,
 					   ns == NULL ? '/' : ns->sep);
 		box.type = type;
-		box.expire_secs = strtoul(names[1], NULL, 10) * 3600 * 24;
+		box.expire_secs = strtoul(*names, NULL, 10) * 3600 * 24;
 
 		if (namespaces->user->mail_debug) {
 			i_debug("expire: pattern=%s type=%s secs=%u",


More information about the dovecot-cvs mailing list