From 304870ea1cf39999c043931e14cee4e05427fadf Mon Sep 17 00:00:00 2001 From: Josaphat Imani Date: Mon, 31 Jul 2023 11:23:34 +0200 Subject: [PATCH] Fixed bugs on dropdown and refactored js --- modules/sievefilters/modules.php | 16 +++++++++++----- modules/sievefilters/site.js | 5 +++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/modules/sievefilters/modules.php b/modules/sievefilters/modules.php index 72c1a15980..482a2c4432 100644 --- a/modules/sievefilters/modules.php +++ b/modules/sievefilters/modules.php @@ -196,13 +196,19 @@ function get_blocked_senders($mailbox, $mailbox_id, $icon_svg, $icon_block_domai $current_script = $client->getScript('blocked_senders'); $blocked_list_actions = []; if ($current_script != '') { - $base64_obj = str_replace("# ", "", preg_split('#\r?\n#', $current_script, 0)[1]); - $blocked_list = json_decode(base64_decode($base64_obj)); - $base64_obj_actions = str_replace("# ", "", preg_split('#\r?\n#', $current_script, 0)[2]); - $blocked_list_actions = json_decode(base64_decode($base64_obj_actions), true); + $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_list[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; @@ -1259,10 +1265,10 @@ protected function output() { $res .= 'SenderBehaviorActions'; $res .= get_blocked_senders($mailbox, $idx, $this->html_safe(Hm_Image_Sources::close('#d80f0f')), $this->html_safe(Hm_Image_Sources::$globe), $this->get('site_config'), $this->get('user_config'), $this); $res .= ''; - $res .= block_filter_dropdown($this, false, 'edit_blocked_behavior', 'Edit'); $res .= ''; } } + $res .= block_filter_dropdown($this, false, 'edit_blocked_behavior', 'Edit'); return $res; } } diff --git a/modules/sievefilters/site.js b/modules/sievefilters/site.js index 54439bc926..9c11b18f76 100644 --- a/modules/sievefilters/site.js +++ b/modules/sievefilters/site.js @@ -236,14 +236,14 @@ $(function () { e.preventDefault(); let parent = $(this).closest('tr'); let elem = parent.find('#block_action'); - let sender = $(this).closest('tr').children().html(); + let sender = $(this).closest('tr').children().first().html(); let scope = sender.startsWith('*@') ? 'domain': 'sender'; $('.dropdown').toggle(); Hm_Ajax.request( [ {'name': 'hm_ajax_hook', 'value': 'ajax_sieve_block_unblock'}, - {'name': 'imap_server_id', 'value': $(this).closest('.dropdown').prev().attr('mailbox_id')}, + {'name': 'imap_server_id', 'value': $(this).data('mailbox-id')}, {'name': 'block_action', 'value': elem.val()}, {'name': 'scope', 'value': scope}, {'name': 'sender', 'value': sender}, @@ -265,6 +265,7 @@ $(function () { $('#block_sender_form').trigger('reset'); $('#reject_message').remove(); $('#block_action').val(default_val).trigger('change'); + $('#edit_blocked_behavior').attr('data-mailbox-id', $(this).attr('mailbox_id')); if (default_val == 'reject_with_message') { $('#reject_message_textarea').val($(this).data('reject-message')); }