diff --git a/modules/imap/functions.php b/modules/imap/functions.php index 24d6048a1..d3102c35e 100644 --- a/modules/imap/functions.php +++ b/modules/imap/functions.php @@ -1581,7 +1581,7 @@ function connect_to_imap_server($address, $name, $port, $user, $pass, $tls, $ima include_once APP_PATH.'modules/sievefilters/hm-sieve.php'; $sieveClientFactory = new Hm_Sieve_Client_Factory(); - $client = $sieveClientFactory->init(null, $server); + $client = $sieveClientFactory->init(null, $server, $context->module_is_supported('nux')); if (!$client && $show_errors) { Hm_Msgs::add("ERRFailed to authenticate to the Sieve host"); diff --git a/modules/nux/modules.php b/modules/nux/modules.php index 0815d9280..a1bad55a5 100644 --- a/modules/nux/modules.php +++ b/modules/nux/modules.php @@ -709,4 +709,8 @@ static public function details($id) { } return array(); } + + static public function get() { + return self::$services; + } } diff --git a/modules/sievefilters/functions.php b/modules/sievefilters/functions.php index 767ecadd6..ed3d3cb65 100644 --- a/modules/sievefilters/functions.php +++ b/modules/sievefilters/functions.php @@ -106,7 +106,7 @@ function get_mailbox_filters($mailbox, $site_config, $user_config) { $factory = get_sieve_client_factory($site_config); try { - $client = $factory->init($user_config, $mailbox); + $client = $factory->init($user_config, $mailbox, in_array(mb_strtolower('nux'), $site_config->get_modules(true), true)); $scripts = []; foreach ($client->listScripts() as $script) { if (mb_strstr($script, 'cypht')) { @@ -414,7 +414,7 @@ function get_blocked_senders_array($mailbox, $site_config, $user_config) { $factory = get_sieve_client_factory($site_config); try { - $client = $factory->init($user_config, $mailbox); + $client = $factory->init($user_config, $mailbox, in_array(mb_strtolower('nux'), $site_config->get_modules(true), true)); $scripts = $client->listScripts(); if (array_search('blocked_senders', $scripts, true) === false) { @@ -450,7 +450,7 @@ function get_blocked_senders_array($mailbox, $site_config, $user_config) function get_blocked_senders($mailbox, $mailbox_id, $icon_svg, $icon_block_domain_svg, $site_config, $user_config, $module) { $factory = get_sieve_client_factory($site_config); try { - $client = $factory->init($user_config, $mailbox); + $client = $factory->init($user_config, $mailbox, in_array(mb_strtolower('nux'), $site_config->get_modules(true), true)); $scripts = $client->listScripts(); if (array_search('blocked_senders', $scripts, true) === false) { return ''; @@ -521,6 +521,22 @@ function get_blocked_senders($mailbox, $mailbox_id, $icon_svg, $icon_block_domai if (!hm_exists('initialize_sieve_client_factory')) { function initialize_sieve_client_factory($site_config, $user_config, $imapServer) { $factory = get_sieve_client_factory($site_config); - return $factory->init($user_config, $imapServer); + return $factory->init($user_config, $imapServer, in_array(mb_strtolower('nux'), $site_config->get_modules(true), true)); + } +} + +if (!hm_exists('get_sieve_host_from_services')) { + require_once APP_PATH.'modules/nux/modules.php'; + function get_sieve_host_from_services($imap_host) { + $services = Nux_Quick_Services::get(); + foreach ($services as $service) { + if (isset($service['server']) && $service['server'] === $imap_host && isset($service['sieve'])) { + return [ + 'host' => $service['sieve']['host'], + 'port' => $service['sieve']['port'] ?? 4190, + ]; + } + } + return null; } } diff --git a/modules/sievefilters/hm-sieve.php b/modules/sievefilters/hm-sieve.php index 21bbd578a..c555941ff 100644 --- a/modules/sievefilters/hm-sieve.php +++ b/modules/sievefilters/hm-sieve.php @@ -2,10 +2,16 @@ connect($imap_account['user'], $imap_account['pass'], $imap_account['sieve_tls'], "", "PLAIN"); return $client; diff --git a/modules/sievefilters/modules.php b/modules/sievefilters/modules.php index 8949e994d..35b157931 100644 --- a/modules/sievefilters/modules.php +++ b/modules/sievefilters/modules.php @@ -28,7 +28,7 @@ public function process() { $factory = get_sieve_client_factory($this->config); try { - $client = $factory->init($this->user_config, $imap_account); + $client = $factory->init($this->user_config, $imap_account, $this->module_is_supported('nux')); $script = $client->getScript($this->request->post['sieve_script_name']); $base64_obj = str_replace("# ", "", preg_split('#\r?\n#', $script, 0)[1]); $this->out('conditions', json_encode(base64_decode($base64_obj))); @@ -66,7 +66,7 @@ public function process() { if ($sieve_filters_enabled && !empty($server['sieve_config_host'])) { $factory = get_sieve_client_factory($this->config); try { - $client = $factory->init($this->user_config, $server); + $client = $factory->init($this->user_config, $server, $this->module_is_supported('nux')); $sieve_filters_enabled = true; $this->out('sieve_filters_client', $client); } catch (Exception $e) { @@ -103,7 +103,7 @@ public function process() { } $factory = get_sieve_client_factory($this->config); try { - $client = $factory->init($this->user_config, $imap_account); + $client = $factory->init($this->user_config, $imap_account, $this->module_is_supported('nux')); $script = $client->getScript($this->request->post['sieve_script_name']); $client->close(); $this->out('script', $script); @@ -136,7 +136,7 @@ public function process() { } $factory = get_sieve_client_factory($this->config); try { - $client = $factory->init($this->user_config, $imap_account); + $client = $factory->init($this->user_config, $imap_account, $this->module_is_supported('nux')); $scripts = $client->listScripts(); foreach ($scripts as $script) { @@ -173,7 +173,7 @@ public function process() { } $factory = get_sieve_client_factory($this->config); try { - $client = $factory->init($this->user_config, $imap_account); + $client = $factory->init($this->user_config, $imap_account, $this->module_is_supported('nux')); $scripts = $client->listScripts(); foreach ($scripts as $script) { @@ -212,7 +212,7 @@ public function process() { $email_sender = $this->request->post['sender']; $factory = get_sieve_client_factory($this->config); try { - $client = $factory->init($this->user_config, $imap_account); + $client = $factory->init($this->user_config, $imap_account, $this->module_is_supported('nux')); $scripts = $client->listScripts(); $current_script = $client->getScript('blocked_senders'); @@ -344,7 +344,7 @@ public function process() { $factory = get_sieve_client_factory($this->config); try { - $client = $factory->init($this->user_config, $imap_account); + $client = $factory->init($this->user_config, $imap_account, $this->module_is_supported('nux')); $scripts = $client->listScripts(); if(array_search('blocked_senders', $scripts, true) === false) { @@ -482,7 +482,7 @@ public function process() { $factory = get_sieve_client_factory($this->config); try { - $client = $factory->init($this->user_config, $imap_account); + $client = $factory->init($this->user_config, $imap_account, $this->module_is_supported('nux')); $scripts = $client->listScripts(); if(array_search('blocked_senders', $scripts, true) === false) { @@ -978,7 +978,7 @@ public function process() { $factory = get_sieve_client_factory($this->config); try { - $client = $factory->init($this->user_config, $imap_account); + $client = $factory->init($this->user_config, $imap_account, $this->module_is_supported('nux')); $scripts = $client->listScripts(); foreach ($scripts as $script) { if ($script == 'main_script') { @@ -1024,7 +1024,7 @@ public function process() { } $factory = get_sieve_client_factory($this->config); try { - $client = $factory->init($this->user_config, $imap_account); + $client = $factory->init($this->user_config, $imap_account, $this->module_is_supported('nux')); $scripts = $client->listScripts(); foreach ($scripts as $script) { if ($script == $this->request->post['current_editing_script']) { @@ -1359,7 +1359,7 @@ public function process() { $factory = get_sieve_client_factory($this->config); $success = false; try { - $client = $factory->init($this->user_config, $imap_account); + $client = $factory->init($this->user_config, $imap_account, $this->module_is_supported('nux')); $state = $form['script_state'] ? 'enabled': 'disabled'; $scripts = $client->listScripts(); foreach ($scripts as $key => $script) {