diff --git a/src/lib-sieve/sieve-error.c b/src/lib-sieve/sieve-error.c
index 08af504302dc2679dde00118b36d03aa31de90d2..2c5512cfda9a71138b3c5b5f2cb299879f132e64 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 8214deb1aa5864a4b6ae376ba94079a06815b231..38ffd1717c0c5e107f6973a869ce48fcfbafe71e 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