From d2c10f710e7c105797ac26d29281ff6d65dad428 Mon Sep 17 00:00:00 2001
From: Timo Sirainen <timo.sirainen@open-xchange.com>
Date: Thu, 12 Jan 2023 17:30:12 +0200
Subject: [PATCH] sieve-tool: Create a service_user

---
 src/lib-sieve-tool/sieve-tool.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/lib-sieve-tool/sieve-tool.c b/src/lib-sieve-tool/sieve-tool.c
index 80309d60e..b26aaa8b8 100644
--- a/src/lib-sieve-tool/sieve-tool.c
+++ b/src/lib-sieve-tool/sieve-tool.c
@@ -354,12 +354,20 @@ void sieve_tool_init_mail_user(struct sieve_tool *tool,
 			       const char *mail_location)
 {
 	struct mail_user *mail_user_dovecot = tool->mail_user_dovecot;
+	struct mail_storage_service_user *service_user;
 	const char *username = tool->username;
 	struct mail_namespace *ns = NULL;
 	const char *home = NULL, *errstr = NULL;
 
-	tool->mail_user = mail_user_alloc(NULL, username,
-					  mail_user_dovecot->unexpanded_set_parser);
+	struct mail_storage_service_input input = {
+		.username = username,
+		.unexpanded_set_parser = mail_user_dovecot->unexpanded_set_parser,
+		.no_userdb_lookup = TRUE,
+	};
+	if (mail_storage_service_lookup_next(tool->storage_service,
+					     &input, &service_user,
+					     &tool->mail_user, &errstr) < 0)
+		i_fatal("Test user lookup failed: %s", errstr);
 
 	if ((home = sieve_tool_get_homedir(sieve_tool)) != NULL)
 		mail_user_set_home(tool->mail_user, home);
-- 
GitLab