From bd9ae8999a4bd93990819e2bdc6e0c1f5ea37ec3 Mon Sep 17 00:00:00 2001 From: Josaphat Imani Date: Mon, 9 Oct 2023 09:02:28 +0200 Subject: [PATCH] Added try/catch on sieve manager getScript --- modules/sievefilters/modules.php | 106 +++++++++++++++---------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/modules/sievefilters/modules.php b/modules/sievefilters/modules.php index 7141264c44..3022e081ea 100644 --- a/modules/sievefilters/modules.php +++ b/modules/sievefilters/modules.php @@ -208,67 +208,67 @@ function get_blocked_senders($mailbox, $mailbox_id, $icon_svg, $icon_block_domai try { $client = $factory->init($user_config, $mailbox); $scripts = $client->listScripts(); - } catch (Exception $e) { - Hm_Msgs::add("ERRSieve: {$e->getMessage()}"); - return ''; - } - if (array_search('blocked_senders', $scripts, true) === false) { - return ''; - } - $current_script = $client->getScript('blocked_senders'); - $blocked_list_actions = []; - if ($current_script != '') { - $script_split = preg_split('#\r?\n#', $current_script, 0); - if (!isset($script_split[1])) { - return ''; - } - $base64_obj = str_replace("# ", "", $script_split[1]); - $blocked_list = json_decode(base64_decode($base64_obj)); - if (!$blocked_list) { + if (array_search('blocked_senders', $scripts, true) === false) { return ''; } - if (isset($script_split[2])) { - $base64_obj_actions = str_replace("# ", "", $script_split[2]); - $blocked_list_actions = json_decode(base64_decode($base64_obj_actions), true); - } - foreach ($blocked_list as $blocked_sender) { - if (explode('@', $blocked_sender)[0] == '') { - $blocked_sender = '*'.$blocked_sender; + $current_script = $client->getScript('blocked_senders'); + $blocked_list_actions = []; + if ($current_script != '') { + $script_split = preg_split('#\r?\n#', $current_script, 0); + if (!isset($script_split[1])) { + return ''; + } + $base64_obj = str_replace("# ", "", $script_split[1]); + $blocked_list = json_decode(base64_decode($base64_obj)); + if (!$blocked_list) { + return ''; + } + if (isset($script_split[2])) { + $base64_obj_actions = str_replace("# ", "", $script_split[2]); + $blocked_list_actions = json_decode(base64_decode($base64_obj_actions), true); + } + foreach ($blocked_list as $blocked_sender) { + if (explode('@', $blocked_sender)[0] == '') { + $blocked_sender = '*'.$blocked_sender; + } + $blocked_senders[] = $blocked_sender; } - $blocked_senders[] = $blocked_sender; } - } - $actions_map = [ - 'blocked' => $module->trans('Move To Blocked'), - 'reject_with_message' => $module->trans('Reject With Message'), - 'reject_default' => $module->trans('Reject'), - 'discard' => $module->trans('Discard'), - 'default' => $module->trans('Default'), - ]; - $ret = ''; - foreach ($blocked_senders as $sender) { - $reject_message = $blocked_list_actions[$sender]['reject_message']; - $ret .= ''.$sender.''; - if (is_array($blocked_list_actions) && array_key_exists($sender, $blocked_list_actions)) { - $action = $blocked_list_actions[$sender]['action'] ?: 'default'; - $ret .= $actions_map[$action]; - if ($action == 'reject_with_message') { - $ret .= ' - '.$reject_message; + $actions_map = [ + 'blocked' => $module->trans('Move To Blocked'), + 'reject_with_message' => $module->trans('Reject With Message'), + 'reject_default' => $module->trans('Reject'), + 'discard' => $module->trans('Discard'), + 'default' => $module->trans('Default'), + ]; + $ret = ''; + foreach ($blocked_senders as $sender) { + $reject_message = $blocked_list_actions[$sender]['reject_message']; + $ret .= ''.$sender.''; + if (is_array($blocked_list_actions) && array_key_exists($sender, $blocked_list_actions)) { + $action = $blocked_list_actions[$sender]['action'] ?: 'default'; + $ret .= $actions_map[$action]; + if ($action == 'reject_with_message') { + $ret .= ' - '.$reject_message; + } + } else { + $action = 'default'; + $ret .= 'Default'; } - } else { - $action = 'default'; - $ret .= 'Default'; - } - $ret .= ' '.
-            $module->trans('Change Behavior').''; - $ret .= ''; - if (!strstr($sender, '*')) { - $ret .= ' '; + $ret .= ' '.
+                $module->trans('Change Behavior').''; + $ret .= ''; + if (!strstr($sender, '*')) { + $ret .= ' '; + } + $ret .= ''; } - $ret .= ''; + return $ret; + } catch (Exception $e) { + Hm_Msgs::add("ERRSieve: {$e->getMessage()}"); + return ''; } - return $ret; }