diff --git a/src/lib-sieve-tool/sieve-tool.c b/src/lib-sieve-tool/sieve-tool.c
index d546fed02b3a224ee91834072e861fa7db54ad2e..4b97e61867059325d2638eb38a04c7afd8a76eb5 100644
--- a/src/lib-sieve-tool/sieve-tool.c
+++ b/src/lib-sieve-tool/sieve-tool.c
@@ -375,13 +375,18 @@ void sieve_tool_init_mail_user(struct sieve_tool *tool,
 	ns->flags |= NAMESPACE_FLAG_NOQUOTA | NAMESPACE_FLAG_NOACL;
 }
 
-struct mail *
-sieve_tool_open_file_as_mail(struct sieve_tool *tool, const char *path)
+static void sieve_tool_init_mail_raw_user(struct sieve_tool *tool)
 {
 	if (tool->mail_raw_user == NULL) {
 		tool->mail_raw_user = mail_raw_user_create(
 			master_service, tool->mail_user_dovecot);
 	}
+}
+
+struct mail *
+sieve_tool_open_file_as_mail(struct sieve_tool *tool, const char *path)
+{
+	sieve_tool_init_mail_raw_user(tool);
 
 	if (tool->mail_raw != NULL)
 		mail_raw_close(&tool->mail_raw);
@@ -394,10 +399,7 @@ sieve_tool_open_file_as_mail(struct sieve_tool *tool, const char *path)
 struct mail *
 sieve_tool_open_data_as_mail(struct sieve_tool *tool, string_t *mail_data)
 {
-	if (tool->mail_raw_user == NULL) {
-		tool->mail_raw_user = mail_raw_user_create(
-			master_service, tool->mail_user_dovecot);
-	}
+	sieve_tool_init_mail_raw_user(tool);
 
 	if (tool->mail_raw != NULL)
 		mail_raw_close(&tool->mail_raw);
@@ -473,6 +475,12 @@ struct mail_user *sieve_tool_get_mail_user(struct sieve_tool *tool)
 		tool->mail_user_dovecot : tool->mail_user);
 }
 
+struct mail_user *sieve_tool_get_mail_raw_user(struct sieve_tool *tool)
+{
+	sieve_tool_init_mail_raw_user(tool);
+	return tool->mail_raw_user;
+}
+
 /*
  * Commonly needed functionality
  */
diff --git a/src/lib-sieve-tool/sieve-tool.h b/src/lib-sieve-tool/sieve-tool.h
index b253e34ecc62ea004f5de07f37cb6c00dba0866e..02f41984aae6a237d0f9e125517bdb970378b1f0 100644
--- a/src/lib-sieve-tool/sieve-tool.h
+++ b/src/lib-sieve-tool/sieve-tool.h
@@ -51,6 +51,7 @@ sieve_tool_open_data_as_mail(struct sieve_tool *tool, string_t *mail_data);
 const char *sieve_tool_get_username(struct sieve_tool *tool);
 const char *sieve_tool_get_homedir(struct sieve_tool *tool);
 struct mail_user *sieve_tool_get_mail_user(struct sieve_tool *tool);
+struct mail_user *sieve_tool_get_mail_raw_user(struct sieve_tool *tool);
 
 /*
  * Configuration