From 1ad9fb36b0f1a26aa0fc93cbae9f197b9bcb4904 Mon Sep 17 00:00:00 2001 From: Guillaume ARNOUX Date: Sun, 21 Jan 2024 23:24:16 +0100 Subject: [PATCH] suspend and unsuspend --- src/Mailcow.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/Mailcow.php b/src/Mailcow.php index d565a2d..a9a85fe 100644 --- a/src/Mailcow.php +++ b/src/Mailcow.php @@ -185,4 +185,48 @@ class Server_Manager_Mailcow extends Server_Manager return true; } + /** + * Suspend account on server. + */ + public function suspendAccount(Server_Account $a) + { + $domainData = [ + 'json' => [ + "attr" => [ + "active" => "0", + ], + "items" => $a->getDomain(), + ] + ] + // Make request and suspend user + $result = $this->_makeRequest('POST', 'edit/domain', $domainData); + if (!str_contains($result, 'success')) { + $placeholders = [':action:' => __trans('suspend account'), ':type:' => 'Mailcow']; + throw new Server_Exception('Failed to :action: on the :type: server, check the error logs for further details', $placeholders); + } + return true; + } + + /** + * Unsuspend account on server. + */ + public function unsuspendAccount(Server_Account $a) + { + $domainData = [ + 'json' => [ + "attr" => [ + "active" => "1", + ], + "items" => $a->getDomain(), + ] + ] + // Make request and suspend user + $result = $this->_makeRequest('POST', 'edit/domain', $domainData); + if (!str_contains($result, 'success')) { + $placeholders = [':action:' => __trans('unsuspend account'), ':type:' => 'Mailcow']; + throw new Server_Exception('Failed to :action: on the :type: server, check the error logs for further details', $placeholders); + } + return true; + } + }