From a270da5ad1203d2337eb8332f5beb0cef276cb40 Mon Sep 17 00:00:00 2001
From: Stephane de Labrusse <stephdl@de-labrusse.fr>
Date: Mon, 29 Apr 2024 17:14:00 +0200
Subject: [PATCH] Add configure-module script to bind user domain in
 imageroot/actions

---
 .../configure-module/30Bind_user_domain       | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
 create mode 100755 imageroot/actions/configure-module/30Bind_user_domain

diff --git a/imageroot/actions/configure-module/30Bind_user_domain b/imageroot/actions/configure-module/30Bind_user_domain
new file mode 100755
index 0000000..e5769e2
--- /dev/null
+++ b/imageroot/actions/configure-module/30Bind_user_domain
@@ -0,0 +1,19 @@
+#!/usr/bin/env python3
+
+#
+# Copyright (C) 2024 Nethesis S.r.l.
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+
+import agent
+import os
+
+rdb = agent.redis_connect(use_replica=True)
+
+providers = agent.list_service_providers(rdb, 'imap', 'tcp', {
+    'module_uuid': os.environ['MAIL_SERVER']
+})
+
+if providers:
+    user_domain = providers[0]['user_domain']
+    agent.bind_user_domains([user_domain])