dovecot-2.0: lib-storage: Allow appending to existing settings v...

dovecot at dovecot.org dovecot at dovecot.org
Wed Jun 8 16:05:39 EEST 2011


details:   http://hg.dovecot.org/dovecot-2.0/rev/778067e9ccc2
changeset: 12847:778067e9ccc2
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Jun 08 16:05:32 2011 +0300
description:
lib-storage: Allow appending to existing settings via userdb extra fields.
"foo=bar" replaces the setting, while "+foo=bar" appends to the setting.

diffstat:

 src/lib-storage/mail-storage-service.c |  23 +++++++++++++++++++++--
 1 files changed, 21 insertions(+), 2 deletions(-)

diffs (46 lines):

diff -r 8e5d8c4b103d -r 778067e9ccc2 src/lib-storage/mail-storage-service.c
--- a/src/lib-storage/mail-storage-service.c	Wed Jun 08 16:04:35 2011 +0300
+++ b/src/lib-storage/mail-storage-service.c	Wed Jun 08 16:05:32 2011 +0300
@@ -107,14 +107,20 @@
 {
 	struct setting_parser_context *set_parser = user->set_parser;
 	bool mail_debug;
-	const char *key;
+	const char *key, *orig_key;
+	bool append = FALSE;
 	int ret;
 
 	mail_debug = mail_user_set_get_mail_debug(user->user_info,
 						  user->user_set);
 	if (strchr(line, '=') == NULL)
 		line = t_strconcat(line, "=yes", NULL);
-	key = t_strcut(line, '=');
+	orig_key = key = t_strcut(line, '=');
+
+	if (*key == '+') {
+		key++;
+		append = TRUE;
+	}
 
 	if (!settings_parse_is_valid_key(set_parser, key)) {
 		/* assume it's a plugin setting */
@@ -131,6 +137,19 @@
 		return 1;
 	}
 
+	if (append) {
+		const void *value;
+		enum setting_type type;
+
+		value = settings_parse_get_value(set_parser, key, &type);
+		if (type == SET_STR)
+			line = t_strconcat(line, value, NULL);
+		else {
+			i_error("Ignoring %s userdb setting. "
+				"'+' can only be used for strings.", orig_key);
+		}
+	}
+
 	ret = settings_parse_line(set_parser, line);
 	if (mail_debug && ret >= 0) {
 		i_debug(ret == 0 ?


More information about the dovecot-cvs mailing list