--- /usr/local/src/dovecot-2.0.4.orig/src/auth/passdb-vpopmail.c	2010-10-17 21:19:18.000000000 +0200
+++ src/auth/passdb-vpopmail.c	2010-10-17 21:40:08.000000000 +0200
@@ -10,6 +10,10 @@
 #include "safe-memset.h"
 #include "password-scheme.h"
 #include "auth-cache.h"
+#include "auth-common.h"
+#include "array.h"
+#include "str.h"
+#include "var-expand.h"
 
 #include "userdb-vpopmail.h"
 
@@ -26,6 +30,7 @@
 	struct passdb_module module;
 
 	struct ip_addr webmail_ip;
+	ARRAY_TYPE(const_string) tmpl;
 };
 
 static bool vpopmail_is_disabled(struct auth_request *request,
@@ -95,12 +100,35 @@
 {
 	enum passdb_result result;
 	char *password;
+	struct vpopmail_passdb_module *module =
+		(struct vpopmail_passdb_module *)request->passdb->passdb;
+	const struct var_expand_table *table;
+	const char *const *args;
+	unsigned int i, count;
+	string_t *str = t_str_new(128);
+	const char *scheme;
 
 	password = vpopmail_password_lookup(request, TRUE, &result);
 	if (password == NULL) {
 		callback(result, NULL, 0, request);
 		return;
 	}
+	
+	scheme = request->passdb->passdb->default_pass_scheme;
+	
+	args = array_get(&module->tmpl, &count);
+	for (i = 0; i < count; i += 2) {
+		const char *key = args[i];
+		const char *value = args[i+1];
+
+		if (value != NULL) {
+			str_truncate(str, 0);
+			var_expand(str, args[i+1], table);
+			value = str_c(str);
+		}
+
+		auth_request_set_field(request, key, value, scheme);
+	}
 
 	passdb_handle_credentials(PASSDB_RESULT_OK, password, "CLEARTEXT",
 				  callback, request);
@@ -115,6 +143,12 @@
 	const char *scheme, *tmp_pass;
 	char *crypted_pass;
 	int ret;
+	struct vpopmail_passdb_module *module =
+		(struct vpopmail_passdb_module *)request->passdb->passdb;
+	const struct var_expand_table *table;
+	const char *const *args;
+	unsigned int i, count;
+	string_t *str = t_str_new(128);
 
 	crypted_pass = vpopmail_password_lookup(request, FALSE, &result);
 	if (crypted_pass == NULL) {
@@ -136,6 +170,20 @@
 		return;
 	}
 
+	args = array_get(&module->tmpl, &count);
+	for (i = 0; i < count; i += 2) {
+		const char *key = args[i];
+		const char *value = args[i+1];
+
+		if (value != NULL) {
+			str_truncate(str, 0);
+			var_expand(str, args[i+1], table);
+			value = str_c(str);
+		}
+
+		auth_request_set_field(request, key, value, scheme);
+	}
+
 #ifdef HAVE_VPOPMAIL_OPEN_SMTP_RELAY
 	if (strcmp(request->service, "POP3") == 0 ||
 	    strcmp(request->service, "IMAP") == 0) {
@@ -168,6 +216,8 @@
 	module = p_new(pool, struct vpopmail_passdb_module, 1);
 	module->module.default_pass_scheme = VPOPMAIL_DEFAULT_PASS_SCHEME;
 
+	p_array_init(&module->tmpl, pool, 16);
+
 	tmp = t_strsplit_spaces(args, " ");
 	for (; *tmp != NULL; tmp++) {
 		if (strncmp(*tmp, "cache_key=", 10) == 0) {
@@ -177,7 +227,18 @@
 			if (net_addr2ip(*tmp + 8, &module->webmail_ip) < 0)
 				i_fatal("vpopmail: Invalid webmail IP address");
 		} else {
-			i_fatal("passdb vpopmail: Unknown setting: %s", *tmp);
+			const char *key = *tmp;
+			const char *value = strchr(key, '=');
+
+			if (value == NULL)
+				value = "";
+			else
+				key = t_strdup_until(key, value++);
+
+			key = p_strdup(pool, key);
+			value = p_strdup(pool, value);
+			array_append(&module->tmpl, &key, 1);
+			array_append(&module->tmpl, &value, 1);
 		}
 	}
 	if (!vauth_load_initialized) {
