diff --git a/src/lib-sieve/cmd-keep.c b/src/lib-sieve/cmd-keep.c
index e7f243c52288023d2bf8270fca32d14da4228791..1031be7db32fa1550f13f3a1b4d54fcd8ab5102d 100644
--- a/src/lib-sieve/cmd-keep.c
+++ b/src/lib-sieve/cmd-keep.c
@@ -73,10 +73,10 @@ static bool opc_keep_execute
 	if ( !sieve_interpreter_handle_optional_operands(renv, address, &slist) )
 		return FALSE;
 	
-	if ( renv->mailenv != NULL && renv->mailenv->inbox != NULL )
-		ret = sieve_act_store_add_to_result(renv,	slist, renv->mailenv->inbox);
+	if ( renv->scriptenv != NULL && renv->scriptenv->inbox != NULL )
+		ret = sieve_act_store_add_to_result(renv, slist, renv->scriptenv->inbox);
 	else
-		ret = sieve_act_store_add_to_result(renv,	slist, "INBOX");
+		ret = sieve_act_store_add_to_result(renv, slist, "INBOX");
 	
 	return ret >= 0;
 }
diff --git a/src/lib-sieve/cmd-redirect.c b/src/lib-sieve/cmd-redirect.c
index 93e39bf88197b2ead6de3dd8eaeb49f79bccbe42..4671c4d9f9fafad4b6e3f9ebdbb7a566db00dc1d 100644
--- a/src/lib-sieve/cmd-redirect.c
+++ b/src/lib-sieve/cmd-redirect.c
@@ -205,7 +205,7 @@ static bool act_redirect_send
 	(const struct sieve_action_exec_env *aenv, struct act_redirect_context *ctx)
 {
 	const struct sieve_message_data *msgdata = aenv->msgdata;
-	const struct sieve_mail_environment *mailenv = aenv->mailenv;
+	const struct sieve_script_env *senv = aenv->scriptenv;
 	struct istream *input;
 	static const char *hide_headers[] = { "Return-Path" };
 	void *smtp_handle;
@@ -215,7 +215,7 @@ static bool act_redirect_send
 	int ret;
 	
 	/* Just to be sure */
-	if ( mailenv->smtp_open == NULL || mailenv->smtp_close == NULL ) {
+	if ( senv->smtp_open == NULL || senv->smtp_close == NULL ) {
 		sieve_result_error(aenv, "redirect action has no means to send mail.");
 		return FALSE;
 	}
@@ -223,7 +223,7 @@ static bool act_redirect_send
 	if (mail_get_stream(msgdata->mail, NULL, NULL, &input) < 0)
 		return -1;
 		
-  smtp_handle = mailenv->smtp_open(ctx->to_address, msgdata->return_path, &f);
+  smtp_handle = senv->smtp_open(ctx->to_address, msgdata->return_path, &f);
 
   input = i_stream_create_header_filter
   	(input, HEADER_FILTER_EXCLUDE | HEADER_FILTER_NO_CR, hide_headers,
@@ -235,7 +235,7 @@ static bool act_redirect_send
 		i_stream_skip(input, size);
 	}
 
-	return mailenv->smtp_close(smtp_handle);
+	return senv->smtp_close(smtp_handle);
 }
 
 static bool act_redirect_commit
@@ -244,27 +244,27 @@ static bool act_redirect_commit
 {
 	struct act_redirect_context *ctx = (struct act_redirect_context *) tr_context;
 	const struct sieve_message_data *msgdata = aenv->msgdata;
-	const struct sieve_mail_environment *mailenv = aenv->mailenv;
+	const struct sieve_script_env *senv = aenv->scriptenv;
 	const char *dupeid;
 	
 	/* Prevent mail loops if possible */
-  dupeid = msgdata->id == NULL ? 
-  	NULL : t_strdup_printf("%s-%s", msgdata->id, ctx->to_address);
+	dupeid = msgdata->id == NULL ? 
+  		NULL : t_strdup_printf("%s-%s", msgdata->id, ctx->to_address);
 	if (dupeid != NULL) {
-	  /* Check whether we've seen this message before */
-  	if (mailenv->duplicate_check(dupeid, strlen(dupeid), mailenv->username)) {
-      sieve_result_log(aenv, "discarded duplicate forward to <%s>",
+		/* Check whether we've seen this message before */
+  		if (senv->duplicate_check(dupeid, strlen(dupeid), senv->username)) {
+			sieve_result_log(aenv, "discarded duplicate forward to <%s>",
 				str_sanitize(ctx->to_address, 80));
 			return TRUE;
-  	}
-  }
+		}
+	}
 	
 	/* Try to forward the message */
 	if ( act_redirect_send(aenv, ctx) ) {
 	
 		/* Mark this message id as forwarded to the specified destination */
 		if (dupeid != NULL) {
-			mailenv->duplicate_mark(dupeid, strlen(dupeid), mailenv->username,
+			senv->duplicate_mark(dupeid, strlen(dupeid), senv->username,
 				ioloop_time + CMD_REDIRECT_DUPLICATE_KEEP);
 		}
 	
@@ -272,8 +272,8 @@ static bool act_redirect_commit
 			str_sanitize(ctx->to_address, 80));	
 
 		*keep = FALSE;
-  	return TRUE;
-  }
+  		return TRUE;
+  	}
   
 	return FALSE;
 }
diff --git a/src/lib-sieve/ext-reject.c b/src/lib-sieve/ext-reject.c
index e4f9db3cd4c62e2b73ed85ee0cc464e1d61226f6..2e839fac5d0e9dd0731a085f3e5c6b48c65667a6 100644
--- a/src/lib-sieve/ext-reject.c
+++ b/src/lib-sieve/ext-reject.c
@@ -265,7 +265,7 @@ static bool act_reject_send
 	(const struct sieve_action_exec_env *aenv, struct act_reject_context *ctx)
 {
 	const struct sieve_message_data *msgdata = aenv->msgdata;
-	const struct sieve_mail_environment *mailenv = aenv->mailenv;
+	const struct sieve_script_env *senv = aenv->scriptenv;
 	struct istream *input;
 	void *smtp_handle;
 	struct message_size hdr_size;
@@ -277,20 +277,20 @@ static bool act_reject_send
 	int ret;
 
 	/* Just to be sure */
-	if ( mailenv->smtp_open == NULL || mailenv->smtp_close == NULL ) {
+	if ( senv->smtp_open == NULL || senv->smtp_close == NULL ) {
 		sieve_result_error(aenv, "reject action has no means to send mail.");
 		return FALSE;
 	}
 
-	smtp_handle = mailenv->smtp_open(msgdata->return_path, NULL, &f);
+	smtp_handle = senv->smtp_open(msgdata->return_path, NULL, &f);
 
-	new_msgid = sieve_get_new_message_id(mailenv);
-	boundary = t_strdup_printf("%s/%s", my_pid, mailenv->hostname);
+	new_msgid = sieve_get_new_message_id(senv);
+	boundary = t_strdup_printf("%s/%s", my_pid, senv->hostname);
 
 	fprintf(f, "Message-ID: %s\r\n", new_msgid);
 	fprintf(f, "Date: %s\r\n", message_date_create(ioloop_time));
 	fprintf(f, "From: Mail Delivery Subsystem <%s>\r\n",
-		mailenv->postmaster_address);
+		senv->postmaster_address);
 	fprintf(f, "To: <%s>\r\n", msgdata->return_path);
 	fprintf(f, "MIME-Version: 1.0\r\n");
 	fprintf(f, "Content-Type: "
@@ -315,7 +315,7 @@ static bool act_reject_send
 	fprintf(f, "--%s\r\n"
 		"Content-Type: message/disposition-notification\r\n\r\n", boundary);
 	fprintf(f, "Reporting-UA: %s; Dovecot Mail Delivery Agent\r\n",
-		mailenv->hostname);
+		senv->hostname);
 	if (mail_get_first_header(msgdata->mail, "Original-Recipient", &header) > 0)
 		fprintf(f, "Original-Recipient: rfc822; %s\r\n", header);
 	fprintf(f, "Final-Recipient: rfc822; %s\r\n",	msgdata->to_address);
@@ -355,7 +355,7 @@ static bool act_reject_send
 
 	fprintf(f, "\r\n\r\n--%s--\r\n", boundary);
 
-	return mailenv->smtp_close(smtp_handle);
+	return senv->smtp_close(smtp_handle);
 }
 
 static bool act_reject_commit
diff --git a/src/lib-sieve/plugins/vacation/ext-vacation.c b/src/lib-sieve/plugins/vacation/ext-vacation.c
index b8b7e9d4fceacec4829e6f190114741e0aa211e5..f9d7274fbaee40cfe5f05dc79981403dbf9f6c43 100644
--- a/src/lib-sieve/plugins/vacation/ext-vacation.c
+++ b/src/lib-sieve/plugins/vacation/ext-vacation.c
@@ -572,19 +572,19 @@ static bool act_vacation_send
 	(const struct sieve_action_exec_env *aenv, struct act_vacation_context *ctx)
 {
 	const struct sieve_message_data *msgdata = aenv->msgdata;
-	const struct sieve_mail_environment *mailenv = aenv->mailenv;
+	const struct sieve_script_env *senv = aenv->scriptenv;
 	void *smtp_handle;
-  FILE *f;
+	FILE *f;
  	const char *outmsgid;
 
 	/* Just to be sure */
-	if ( mailenv->smtp_open == NULL || mailenv->smtp_close == NULL ) {
+	if ( senv->smtp_open == NULL || senv->smtp_close == NULL ) {
 		sieve_result_error(aenv, "vacation action has no means to send mail.");
 		return FALSE;
 	}
 
-  smtp_handle = mailenv->smtp_open(msgdata->return_path, NULL, &f);
-  outmsgid = sieve_get_new_message_id(mailenv);
+	smtp_handle = senv->smtp_open(msgdata->return_path, NULL, &f);
+	outmsgid = sieve_get_new_message_id(senv);
     
 	fprintf(f, "Message-ID: %s\r\n", outmsgid);
 	fprintf(f, "Date: %s\r\n", message_date_create(ioloop_time));
@@ -608,9 +608,9 @@ static bool act_vacation_send
     
 	if (	ctx->mime	) {
 		fprintf(f, "Content-Type: multipart/mixed;"
-			"\r\n\tboundary=\"%s/%s\"\r\n", my_pid, mailenv->hostname);
+			"\r\n\tboundary=\"%s/%s\"\r\n", my_pid, senv->hostname);
 		fprintf(f, "\r\nThis is a MIME-encapsulated message\r\n\r\n");
-		fprintf(f, "--%s/%s\r\n", my_pid, mailenv->hostname);
+		fprintf(f, "--%s/%s\r\n", my_pid, senv->hostname);
 	} else {
 		fprintf(f, "Content-Type: text/plain; charset=utf-8\r\n");
 		fprintf(f, "Content-Transfer-Encoding: 8bit\r\n");
@@ -620,11 +620,11 @@ static bool act_vacation_send
 	fprintf(f, "%s\r\n", ctx->reason);
     
 	if ( ctx->mime )
-		fprintf(f, "\r\n--%s/%s--\r\n", my_pid, mailenv->hostname);
+		fprintf(f, "\r\n--%s/%s--\r\n", my_pid, senv->hostname);
 
-	if ( mailenv->smtp_close(smtp_handle) ) {
-		/*mailenv->duplicate_mark(outmsgid, strlen(outmsgid),
-		  mailenv->username, ioloop_time + DUPLICATE_DEFAULT_KEEP);*/
+	if ( senv->smtp_close(smtp_handle) ) {
+		/*senv->duplicate_mark(outmsgid, strlen(outmsgid),
+		  senv->username, ioloop_time + DUPLICATE_DEFAULT_KEEP);*/
 		return TRUE;
 	}
 	
@@ -657,7 +657,7 @@ static bool act_vacation_commit
 {
 	const char *const *hdsp;
 	const struct sieve_message_data *msgdata = aenv->msgdata;
-	const struct sieve_mail_environment *mailenv = aenv->mailenv;
+	const struct sieve_script_env *senv = aenv->scriptenv;
 	struct act_vacation_context *ctx = (struct act_vacation_context *) tr_context;
 	unsigned char dupl_hash[MD5_RESULTLEN];
 	const char *const *headers;
@@ -680,7 +680,7 @@ static bool act_vacation_commit
 	
 	/* Did whe respond to this user before? */
 	act_vacation_hash(msgdata, ctx, dupl_hash);
-	if (mailenv->duplicate_check(dupl_hash, sizeof(dupl_hash), mailenv->username)) 
+	if (senv->duplicate_check(dupl_hash, sizeof(dupl_hash), senv->username)) 
 	{
 		sieve_result_log(aenv, "discarded duplicate vacation response to <%s>",
 			str_sanitize(msgdata->return_path, 80));
@@ -778,7 +778,7 @@ static bool act_vacation_commit
 		sieve_result_log(aenv, "sent vacation response to <%s>", 
 			str_sanitize(msgdata->return_path, 80));	
 
-		mailenv->duplicate_mark(dupl_hash, sizeof(dupl_hash), mailenv->username,
+		senv->duplicate_mark(dupl_hash, sizeof(dupl_hash), senv->username,
 			ioloop_time + ctx->days * (24 * 60 * 60));
 
   	return TRUE;
diff --git a/src/lib-sieve/sieve-actions.c b/src/lib-sieve/sieve-actions.c
index 53310cebf0bfa1998d49ca7f41aa7d1fddb12023..52e3311aae981432c1efa6da9a5653ab976f6e47 100644
--- a/src/lib-sieve/sieve-actions.c
+++ b/src/lib-sieve/sieve-actions.c
@@ -19,13 +19,13 @@
  */
  
 const char *sieve_get_new_message_id
-	(const struct sieve_mail_environment *mailenv)
+	(const struct sieve_script_env *senv)
 {
 	static int count = 0;
 	
 	return t_strdup_printf("<dovecot-sieve-%s-%s-%d@%s>",
 		dec2str(ioloop_timeval.tv_sec), dec2str(ioloop_timeval.tv_usec),
-    count++, mailenv->hostname);
+    count++, senv->hostname);
 }
 
 /* 
@@ -257,8 +257,8 @@ static bool act_store_start
 	struct mailbox *box = NULL;
 	pool_t pool;
 
-	if ( aenv->mailenv->namespaces != NULL ) {
-		ns = mail_namespace_find(aenv->mailenv->namespaces, &ctx->folder);
+	if ( aenv->scriptenv->namespaces != NULL ) {
+		ns = mail_namespace_find(aenv->scriptenv->namespaces, &ctx->folder);
 		if (ns == NULL) 
 			return FALSE;
 		
diff --git a/src/lib-sieve/sieve-actions.h b/src/lib-sieve/sieve-actions.h
index cc8fe93df9d675107eaf468662de8dfe55fb8bb6..eff494e7ca100a50f037af13c7bdbe98c5805e9e 100644
--- a/src/lib-sieve/sieve-actions.h
+++ b/src/lib-sieve/sieve-actions.h
@@ -11,7 +11,7 @@
 struct sieve_action_exec_env { 
 	struct sieve_result *result;
 	const struct sieve_message_data *msgdata;
-	const struct sieve_mail_environment *mailenv;
+	const struct sieve_script_env *scriptenv;
 };
 
 enum sieve_action_flags {
@@ -143,7 +143,7 @@ int sieve_act_store_add_to_result
 /* Message transmission */
 
 const char *sieve_get_new_message_id
-	(const struct sieve_mail_environment *mailenv);
+	(const struct sieve_script_env *senv);
 
 		
 #endif /* __SIEVE_ACTIONS_H */
diff --git a/src/lib-sieve/sieve-interpreter.c b/src/lib-sieve/sieve-interpreter.c
index 8266d541942c4c769d7b9e1e0172e52f1752165b..dd7d930fde64d6ca418c221aebdeaebf233d839b 100644
--- a/src/lib-sieve/sieve-interpreter.c
+++ b/src/lib-sieve/sieve-interpreter.c
@@ -276,7 +276,7 @@ bool sieve_interpreter_execute_operation
 
 int sieve_interpreter_run
 (struct sieve_interpreter *interp, const struct sieve_message_data *msgdata,
-	const struct sieve_mail_environment *menv, struct sieve_result **result) 
+	const struct sieve_script_env *senv, struct sieve_result **result) 
 {
 	bool is_topmost = ( *result == NULL );
 	int ret = 0;
@@ -289,7 +289,7 @@ int sieve_interpreter_run
 	}
 	interp->runenv.msgdata = msgdata;
 	interp->runenv.result = *result;		
-	interp->runenv.mailenv = menv;
+	interp->runenv.scriptenv = senv;
 	
 	while ( !interp->stopped && 
 		interp->pc < sieve_binary_get_code_size(interp->runenv.sbin) ) {
@@ -304,11 +304,11 @@ int sieve_interpreter_run
 	
 	interp->runenv.result = NULL;
 	interp->runenv.msgdata = NULL;
-	interp->runenv.mailenv = NULL;
+	interp->runenv.scriptenv = NULL;
 	
 	ret = 1;
 	if ( is_topmost ) {
-		ret = sieve_result_execute(*result, msgdata, menv);
+		ret = sieve_result_execute(*result, msgdata, senv);
 	}
 	
 	sieve_result_unref(result);
diff --git a/src/lib-sieve/sieve-interpreter.h b/src/lib-sieve/sieve-interpreter.h
index abd5018df936235ee0f3766f2fdd41d72bf6fc9f..9f04cc0abd9227b80f542dd81b0d1983cc5302d3 100644
--- a/src/lib-sieve/sieve-interpreter.h
+++ b/src/lib-sieve/sieve-interpreter.h
@@ -17,7 +17,7 @@ struct sieve_runtime_env {
 	struct sieve_interpreter *interp;
 	struct sieve_binary *sbin;
 	const struct sieve_message_data *msgdata;
-	const struct sieve_mail_environment *mailenv;
+	const struct sieve_script_env *scriptenv;
 	struct sieve_result *result;
 };
 
@@ -71,6 +71,6 @@ bool sieve_interpreter_execute_operation(struct sieve_interpreter *interp);
 
 int sieve_interpreter_run
 (struct sieve_interpreter *interp, const struct sieve_message_data *msgdata,
-	const struct sieve_mail_environment *menv, struct sieve_result **result);
+	const struct sieve_script_env *senv, struct sieve_result **result);
 
 #endif /* __SIEVE_INTERPRETER_H */
diff --git a/src/lib-sieve/sieve-result.c b/src/lib-sieve/sieve-result.c
index 8535402174c6c4a1a1dae1ed5496473b65fbe183..af78f5fccf806edc0d66a7368b8157d647cf0477 100644
--- a/src/lib-sieve/sieve-result.c
+++ b/src/lib-sieve/sieve-result.c
@@ -218,7 +218,7 @@ static bool sieve_result_implicit_keep(struct sieve_result *result)
 	struct act_store_context ctx;
 	void *tr_context;
 	
-	ctx.folder = result->action_env.mailenv->inbox;
+	ctx.folder = result->action_env.scriptenv->inbox;
 	
 	/* FIXME: Handle persistent side-effects for the (implicit) keep action */
 	
@@ -240,7 +240,7 @@ static bool sieve_result_implicit_keep(struct sieve_result *result)
 
 int sieve_result_execute
 	(struct sieve_result *result, const struct sieve_message_data *msgdata,
-		const struct sieve_mail_environment *menv)
+		const struct sieve_script_env *senv)
 { 
 	bool implicit_keep = TRUE;
 	bool success = TRUE, commit_ok;
@@ -248,7 +248,7 @@ int sieve_result_execute
 	struct sieve_result_action *last_attempted;
 
 	result->action_env.msgdata = msgdata;
-	result->action_env.mailenv = menv;
+	result->action_env.scriptenv = senv;
 	
 	/* Transaction start */
 	
diff --git a/src/lib-sieve/sieve-result.h b/src/lib-sieve/sieve-result.h
index f24ff09f3e5e24b2faab4a3b5f2e8687dd5ba101..80784e312ec3334015a95e6f6c5db83b4b7bcdaf 100644
--- a/src/lib-sieve/sieve-result.h
+++ b/src/lib-sieve/sieve-result.h
@@ -33,7 +33,7 @@ void sieve_result_cancel_implicit_keep(struct sieve_result *result);
 
 int sieve_result_execute
 	(struct sieve_result *result, const struct sieve_message_data *msgdata,
-		const struct sieve_mail_environment *menv);
+		const struct sieve_script_env *senv);
 		
 struct sieve_side_effects_list *sieve_side_effects_list_create
 	(struct sieve_result *result);
diff --git a/src/lib-sieve/sieve.c b/src/lib-sieve/sieve.c
index 9a9489bda721b86aaf880f71ef6834b1f171ccdd..8e9c560fd8cfe1cf3eb5a079b07d42bf0e56b7ce 100644
--- a/src/lib-sieve/sieve.c
+++ b/src/lib-sieve/sieve.c
@@ -153,7 +153,7 @@ void sieve_dump(struct sieve_binary *sbin, struct ostream *stream)
 
 int sieve_test
 	(struct sieve_binary *sbin, const struct sieve_message_data *msgdata,
-		const struct sieve_mail_environment *menv, 
+		const struct sieve_script_env *senv, 
 		struct sieve_error_handler *ehandler) 	
 {
 	struct sieve_result *sres = sieve_result_create(ehandler);
@@ -161,7 +161,7 @@ int sieve_test
 		sieve_interpreter_create(sbin, ehandler);			
 	int ret = 0;
 							
-	ret = sieve_interpreter_run(interp, msgdata, menv, &sres);
+	ret = sieve_interpreter_run(interp, msgdata, senv, &sres);
 	
 	if ( ret > 0 ) 
 		ret = sieve_result_print(sres);
@@ -173,7 +173,7 @@ int sieve_test
 
 int sieve_execute
 	(struct sieve_binary *sbin, const struct sieve_message_data *msgdata,
-		const struct sieve_mail_environment *menv,
+		const struct sieve_script_env *senv,
 		struct sieve_error_handler *ehandler) 	
 {
 	struct sieve_result *sres = NULL;
@@ -181,7 +181,7 @@ int sieve_execute
 		sieve_interpreter_create(sbin, ehandler);			
 	int ret = 0;
 							
-	ret = sieve_interpreter_run(interp, msgdata, menv, &sres);
+	ret = sieve_interpreter_run(interp, msgdata, senv, &sres);
 				
 	sieve_interpreter_free(interp);
 	sieve_result_unref(&sres);
diff --git a/src/lib-sieve/sieve.h b/src/lib-sieve/sieve.h
index d19c3edc7056ce4b493eca306f78a299d118ce34..aa9840e0e77bc5f08937936e036659cd6a24b3ba 100644
--- a/src/lib-sieve/sieve.h
+++ b/src/lib-sieve/sieve.h
@@ -23,7 +23,7 @@ struct sieve_message_data {
 	const char *id;
 };
 
-struct sieve_mail_environment {
+struct sieve_script_env {
 	const char *inbox;
 	struct mail_namespace *namespaces;
 	
@@ -53,12 +53,12 @@ struct sieve_binary *sieve_compile
 void sieve_dump(struct sieve_binary *sbin, struct ostream *stream);
 int sieve_test
 	(struct sieve_binary *sbin, const struct sieve_message_data *msgdata, 
-		const struct sieve_mail_environment *menv, 
+		const struct sieve_script_env *senv, 
 		struct sieve_error_handler *ehandler);
 
 int sieve_execute
 	(struct sieve_binary *sbin, const struct sieve_message_data *msgdata,
-		const struct sieve_mail_environment *menv,
+		const struct sieve_script_env *senv,
 		struct sieve_error_handler *ehandler);
 
 #endif
diff --git a/src/plugins/lda-sieve/lda-sieve-plugin.c b/src/plugins/lda-sieve/lda-sieve-plugin.c
index 5167b8a2744a8e8b847573503366c98dfe03d785..56d7cb0f32d1ea2d22e9791475803bae62a821ef 100644
--- a/src/plugins/lda-sieve/lda-sieve-plugin.c
+++ b/src/plugins/lda-sieve/lda-sieve-plugin.c
@@ -80,7 +80,7 @@ static int lda_sieve_run
 {
 	bool debug = ( getenv("DEBUG") != NULL );
 	struct sieve_message_data msgdata;
-	struct sieve_mail_environment mailenv;
+	struct sieve_script_env scriptenv;
 	struct sieve_error_handler *ehandler;
 	struct sieve_binary *sbin;
 	const char *scriptlog;
@@ -113,21 +113,21 @@ static int lda_sieve_run
 	msgdata.auth_user = username;
 	(void)mail_get_first_header(mail, "Message-ID", &msgdata.id);
 
-	memset(&mailenv, 0, sizeof(mailenv));
-	mailenv.inbox = mailbox;
-	mailenv.namespaces = namespaces;
-	mailenv.username = username;
-	mailenv.hostname = deliver_set->hostname;
-	mailenv.postmaster_address = deliver_set->postmaster_address;
-	mailenv.smtp_open = lda_sieve_smtp_open;
-	mailenv.smtp_close = lda_sieve_smtp_close;
-	mailenv.duplicate_mark = duplicate_mark;
-	mailenv.duplicate_check = duplicate_check;
+	memset(&scriptenv, 0, sizeof(scriptenv));
+	scriptenv.inbox = mailbox;
+	scriptenv.namespaces = namespaces;
+	scriptenv.username = username;
+	scriptenv.hostname = deliver_set->hostname;
+	scriptenv.postmaster_address = deliver_set->postmaster_address;
+	scriptenv.smtp_open = lda_sieve_smtp_open;
+	scriptenv.smtp_close = lda_sieve_smtp_close;
+	scriptenv.duplicate_mark = duplicate_mark;
+	scriptenv.duplicate_check = duplicate_check;
 
 	if ( debug )
 		i_info("sieve: Executing (in-memory) script %s", script_path);
 
-	ret = sieve_execute(sbin, &msgdata, &mailenv, ehandler);
+	ret = sieve_execute(sbin, &msgdata, &scriptenv, ehandler);
 
 	if ( ret < 0 )
 		i_error("sieve: Failed to execute script %s", script_path);
diff --git a/src/sieve-bin/sieve-exec.c b/src/sieve-bin/sieve-exec.c
index cce9edce71c6e2963b7d991976df327caee4f175..0d3fc8bfa0ca3dc121e6e9082d4c05bf341e166f 100644
--- a/src/sieve-bin/sieve-exec.c
+++ b/src/sieve-bin/sieve-exec.c
@@ -74,7 +74,7 @@ int main(int argc, char **argv)
 	struct mail_raw *mailr;
 	struct sieve_binary *sbin;
 	struct sieve_message_data msgdata;
-	struct sieve_mail_environment mailenv;
+	struct sieve_script_env scriptenv;
 	struct sieve_error_handler *ehandler;
 
 	bin_init();
@@ -174,22 +174,22 @@ int main(int argc, char **argv)
 	msgdata.auth_user = "nico";
 	(void)mail_get_first_header(mailr->mail, "Message-ID", &msgdata.id);
 	
-	memset(&mailenv, 0, sizeof(mailenv));
-	mailenv.inbox = "INBOX";
-	mailenv.namespaces = ns;
-	mailenv.username = user;
-	mailenv.hostname = "host.example.com";
-	mailenv.postmaster_address = "postmaster@example.com";
-	mailenv.smtp_open = sieve_smtp_open;
-	mailenv.smtp_close = sieve_smtp_close;
-	mailenv.duplicate_mark = duplicate_mark;
-	mailenv.duplicate_check = duplicate_check;
+	memset(&scriptenv, 0, sizeof(scriptenv));
+	scriptenv.inbox = "INBOX";
+	scriptenv.namespaces = ns;
+	scriptenv.username = user;
+	scriptenv.hostname = "host.example.com";
+	scriptenv.postmaster_address = "postmaster@example.com";
+	scriptenv.smtp_open = sieve_smtp_open;
+	scriptenv.smtp_close = sieve_smtp_close;
+	scriptenv.duplicate_mark = duplicate_mark;
+	scriptenv.duplicate_check = duplicate_check;
 	
 	ehandler = sieve_stderr_ehandler_create();
 	sieve_error_handler_accept_infolog(ehandler, TRUE);
 
 	/* Run */
-	if ( sieve_execute(sbin, &msgdata, &mailenv, ehandler) > 0 )
+	if ( sieve_execute(sbin, &msgdata, &scriptenv, ehandler) > 0 )
 		i_info("Final result: success\n");
 	else
 		i_info("Final result: failed (caller please handle implicit keep!)\n");
diff --git a/src/sieve-bin/sieve-test.c b/src/sieve-bin/sieve-test.c
index 8061c9cf2da8eaa1434e24fa437ee0842ddad6e7..6f38263be320304877b1e6b5c6b4e64642295de8 100644
--- a/src/sieve-bin/sieve-test.c
+++ b/src/sieve-bin/sieve-test.c
@@ -34,7 +34,7 @@ int main(int argc, char **argv)
 	struct mail_raw *mailr;
 	struct sieve_binary *sbin;
 	struct sieve_message_data msgdata;
-	struct sieve_mail_environment mailenv;
+	struct sieve_script_env scriptenv;
 	struct sieve_error_handler *ehandler;
 
 	bin_init();
@@ -114,14 +114,14 @@ int main(int argc, char **argv)
 	msgdata.auth_user = user;
 	(void)mail_get_first_header(mailr->mail, "Message-ID", &msgdata.id);
 
-	memset(&mailenv, 0, sizeof(mailenv));
-	mailenv.inbox = "INBOX";
-	mailenv.username = user;
+	memset(&scriptenv, 0, sizeof(scriptenv));
+	scriptenv.inbox = "INBOX";
+	scriptenv.username = user;
 
 	ehandler = sieve_stderr_ehandler_create();	
 	
 	/* Run the test */
-	(void) sieve_test(sbin, &msgdata, &mailenv, ehandler);
+	(void) sieve_test(sbin, &msgdata, &scriptenv, ehandler);
 
 	sieve_error_handler_free(&ehandler);