Skip to content

Commit

Permalink
Fixed bugs on dropdown and refactored js
Browse files Browse the repository at this point in the history
  • Loading branch information
josaphatim committed Jul 31, 2023
1 parent f4c0fd9 commit 304870e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
16 changes: 11 additions & 5 deletions modules/sievefilters/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1259,10 +1265,10 @@ protected function output() {
$res .= '<tr><th style="width: 20px;">Sender</th><th style="width: 40%;">Behavior</th><th style="width: 15%;">Actions</th></tr>';
$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 .= '</tbody></table>';
$res .= block_filter_dropdown($this, false, 'edit_blocked_behavior', 'Edit');
$res .= '</div></div></div>';
}
}
$res .= block_filter_dropdown($this, false, 'edit_blocked_behavior', 'Edit');
return $res;
}
}
Expand Down
5 changes: 3 additions & 2 deletions modules/sievefilters/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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'));
}
Expand Down

0 comments on commit 304870e

Please sign in to comment.