From 37aab05f158bf50d04a1d6d402814dd0f3cb55ba Mon Sep 17 00:00:00 2001
From: Stephan Bosch <stephan@rename-it.nl>
Date: Thu, 14 Jan 2010 10:21:34 +0100
Subject: [PATCH] Fixed bug in the logging of action results. The new varexpand
 error handler was not properly tested.

---
 src/lib-sieve/sieve-error.c  | 22 +++++++++++++++++++---
 src/lib-sieve/sieve-result.c | 15 +++++++++++++--
 2 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/src/lib-sieve/sieve-error.c b/src/lib-sieve/sieve-error.c
index 08af50430..2c5512cfd 100644
--- a/src/lib-sieve/sieve-error.c
+++ b/src/lib-sieve/sieve-error.c
@@ -872,6 +872,9 @@ struct sieve_error_handler *sieve_prefix_ehandler_create
 	pool_t pool;
 	struct sieve_prefix_ehandler *ehandler;
 
+	if ( parent == NULL )
+		return NULL;
+
 	pool = pool_alloconly_create("sieve_prefix_error_handler", 256);	
 	ehandler = p_new(pool, struct sieve_prefix_ehandler, 1);
 	ehandler->parent = parent;
@@ -879,6 +882,8 @@ struct sieve_error_handler *sieve_prefix_ehandler_create
 	ehandler->prefix = p_strdup(pool, prefix);
 
 	sieve_error_handler_init(&ehandler->handler, pool, parent->max_errors);
+    ehandler->handler.log_info = parent->log_info;
+    ehandler->handler.log_debug = parent->log_debug;
 
 	ehandler->handler.verror = sieve_prefix_verror;
 	ehandler->handler.vwarning = sieve_prefix_vwarning;
@@ -908,12 +913,13 @@ static const char *_expand_message
 (struct sieve_varexpand_ehandler *ehandler,
 	const char *location, const char *fmt, va_list args) 
 {
-	struct var_expand_table *table = array_get_modifiable(&ehandler->table, NULL);
+	unsigned int count;
+	struct var_expand_table *table = array_get_modifiable(&ehandler->table, &count);
 	string_t *str = t_str_new(256);
 
 	/* Fill in substitution items */
-	table[0].value = location;
-	table[1].value = t_strdup_vprintf(fmt, args);
+	table[0].value = t_strdup_vprintf(fmt, args);
+	table[1].value = location;
 
 	/* Expand variables */
 	var_expand(str, ehandler->format, table);
@@ -982,6 +988,14 @@ struct sieve_error_handler *sieve_varexpand_ehandler_create
 	struct var_expand_table *entry;
 	int i;
 
+	if ( parent == NULL )
+		return NULL;
+
+	if ( format == NULL ) {
+		sieve_error_handler_ref(parent);
+		return parent;
+	}
+
 	pool = pool_alloconly_create("sieve_varexpand_error_handler", 256);	
 	ehandler = p_new(pool, struct sieve_varexpand_ehandler, 1);
 	ehandler->parent = parent;
@@ -989,6 +1003,8 @@ struct sieve_error_handler *sieve_varexpand_ehandler_create
 	p_array_init(&ehandler->table, pool, 10);
 
 	sieve_error_handler_init(&ehandler->handler, pool, parent->max_errors);
+	ehandler->handler.log_info = parent->log_info;
+	ehandler->handler.log_debug = parent->log_debug;
 
 	entry = array_append_space(&ehandler->table);
 	entry->key = '$';
diff --git a/src/lib-sieve/sieve-result.c b/src/lib-sieve/sieve-result.c
index 8214deb1a..38ffd1717 100644
--- a/src/lib-sieve/sieve-result.c
+++ b/src/lib-sieve/sieve-result.c
@@ -23,6 +23,12 @@
 
 #include <stdio.h>
 
+/*
+ * Defaults
+ */
+
+#define DEFAULT_ACTION_LOG_FORMAT "msgid=%m: %$"
+
 /*
  * Types
  */
@@ -893,8 +899,13 @@ static void _sieve_result_prepare_execution(struct sieve_result *result)
 	if ( result->action_env.ehandler != NULL ) 
 		sieve_error_handler_unref(&result->action_env.ehandler);
 
-	result->action_env.ehandler = sieve_varexpand_ehandler_create
-		(result->ehandler, senv->action_log_format, tab);
+	if ( senv->action_log_format != NULL ) {
+		result->action_env.ehandler = sieve_varexpand_ehandler_create
+			(result->ehandler, senv->action_log_format, tab);
+	} else {
+		result->action_env.ehandler = sieve_varexpand_ehandler_create
+            (result->ehandler, DEFAULT_ACTION_LOG_FORMAT, tab);
+	}
 }
 
 static bool _sieve_result_implicit_keep
-- 
GitLab