Skip to content

Commit

Permalink
Merge pull request #1079 from christer77/Cypht-edit-a-block
Browse files Browse the repository at this point in the history
[FIX]Blocklist:can not edit a block
  • Loading branch information
Shadow243 authored Oct 4, 2024
2 parents 23e5fc6 + 112a5fa commit 4f9255e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
25 changes: 15 additions & 10 deletions modules/sievefilters/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ function save_main_script($client, $main_script, $scripts)
$script
);
}
$main_script .= $script . "\n";
$main_script .= $script . "\n";
}
$main_script = format_main_script($main_script);
$ret = $client->putScript(
Expand Down Expand Up @@ -366,9 +366,9 @@ function block_filter($filter, $user_config, $action, $imap_server_id, $sender,
}

if (!hm_exists('block_filter_dropdown')) {
function block_filter_dropdown($mod, $with_scope = true, $submit_id = 'block_sender', $submit_title = 'Block') {
$ret = '<div class="dropdown-menu p-3" id="dropdownMenuBlockSender">'
.'<form id="block_sender_form">';
function block_filter_dropdown ($mod, $mailbox_id = null, $with_scope = true, $submit_id = 'block_sender', $submit_title = 'Block', $increment = "") {
$ret = '<div class="dropdown-menu p-3" id="dropdownMenuBlockSender' .$increment. '">'
.'<form id="block_sender_form' .$increment. '" >';
if ($with_scope) {
$ret .= '<div class="mb-2">'
. '<label for="blockSenderScope" class="form-label">'.$mod->trans('Who Is Blocked').'</label>'
Expand All @@ -379,7 +379,7 @@ function block_filter_dropdown($mod, $with_scope = true, $submit_id = 'block_sen
}
$ret .= '<div class="mb-2">'
. '<label for="block_action" class="form-label">'.$mod->trans('Action').'</label>'
. '<select class="form-select form-select-sm" name="block_action" id="block_action">'
. '<select class="form-select form-select-sm block_action" name="block_action" id="block_action' .$increment. '">'
. '<option value="default">'.$mod->trans('Default action').'</option>'
. '<option value="discard">'.$mod->trans('Discard').'</option>'
. '<option value="blocked">'.$mod->trans('Move To Blocked Folder').'</option>'
Expand All @@ -388,7 +388,7 @@ function block_filter_dropdown($mod, $with_scope = true, $submit_id = 'block_sen
. '</select>'
.'</div>'
.'<div class="d-grid gap-1">'
. '<button class="btn btn-danger btn-sm mt-2" type="submit" id="'.$submit_id.'">'
. '<button class="btn btn-danger btn-sm mt-2 '.$submit_id.'" type="submit" id="'.$submit_id.$increment. '" mailbox_id="'.$mailbox_id.'">'
. $mod->trans($submit_title)
. '</button>'
.'</div>'
Expand Down Expand Up @@ -419,8 +419,10 @@ function get_blocked_senders_array($mailbox, $site_config, $user_config)
return [];
}
foreach ($blocked_list as $blocked_sender) {
if (explode('@', $blocked_sender)[0] == '') {
$blocked_sender = '*' . $blocked_sender;
if ($blocked_sender) {
if (explode('@', $blocked_sender)[0] == '') {
$blocked_sender = '*' . $blocked_sender;
}
}
$blocked_senders[] = $blocked_sender;
}
Expand All @@ -444,6 +446,7 @@ function get_blocked_senders($mailbox, $mailbox_id, $icon_svg, $icon_block_domai
}
$current_script = $client->getScript('blocked_senders');
$blocked_list_actions = [];
$blocked_senders = [];
if ($current_script != '') {
$script_split = preg_split('#\r?\n#', $current_script, 0);
if (!isset($script_split[1])) {
Expand Down Expand Up @@ -474,7 +477,7 @@ function get_blocked_senders($mailbox, $mailbox_id, $icon_svg, $icon_block_domai
'default' => $module->trans('Default'),
];
$ret = '';
foreach ($blocked_senders as $sender) {
foreach ($blocked_senders as $k => $sender) {
$reject_message = $blocked_list_actions[$sender]['reject_message'];
$ret .= '<tr><td>'.$sender.'</td><td>';
if (is_array($blocked_list_actions) && array_key_exists($sender, $blocked_list_actions)) {
Expand All @@ -487,7 +490,9 @@ function get_blocked_senders($mailbox, $mailbox_id, $icon_svg, $icon_block_domai
$action = 'default';
$ret .= 'Default';
}
$ret .= '<a href="#" mailbox_id="'.$mailbox_id.'" data-action="'.$action.'" data-reject-message="'.$reject_message.'" title="'.$module->trans('Change Behavior').'" class="block_sender_link toggle-behavior-dropdown"> <i class="bi bi-pencil-fill ms-3"></i></a>';
$ret .= '<a href="#" mailbox_id="'.$mailbox_id.'" data-action="'.$action.'" data-reject-message="'.$reject_message.'" title="'.$module->trans('Change Behavior').'" class="block_sender_link toggle-behavior-dropdown" aria-labelledby="dropdownMenuBlockSender'.$k.'" data-bs-toggle="dropdown" aria-expanded="false"> <i class="bi bi-pencil-fill ms-3"></i></a>';
$ret .= block_filter_dropdown($module, $mailbox_id, false, 'edit_blocked_behavior', 'Edit', $k);

$ret .= '</td><td><i class="bi bi-'.$icon_svg.' unblock_button" mailbox_id="'.$mailbox_id.'"></i>';
if (!mb_strstr($sender, '*')) {
$ret .= ' <i class="bi bi-'.$icon_block_domain_svg.' block_domain_button" mailbox_id="'.$mailbox_id.'"></i>';
Expand Down
5 changes: 2 additions & 3 deletions modules/sievefilters/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,7 @@ public function process() {
*/
class Hm_Handler_sieve_block_unblock_script extends Hm_Handler_Module {
public function process() {
list($success, $form) = $this->process_form(array('imap_server_id', 'block_action', 'scope', 'imap_msg_uid'));

list($success, $form) = $this->process_form(array('imap_server_id', 'block_action', 'scope'));
if (!$success) {
return;
}
Expand All @@ -452,6 +451,7 @@ public function process() {
}

if (isset($this->request->post['imap_msg_uid'])) {
$form['imap_msg_uid'] = $this->request->post['imap_msg_uid'];
$imap = Hm_IMAP_List::connect($this->request->post['imap_server_id']);

if (!imap_authed($imap)) {
Expand Down Expand Up @@ -1214,7 +1214,6 @@ protected function output() {
$res .= '</tbody></table>';
$res .= '</div></div></div>';
}
$res .= block_filter_dropdown($this, false, 'edit_blocked_behavior', 'Edit');
$res .= '</div></div>';
return $res;
}
Expand Down
8 changes: 4 additions & 4 deletions modules/sievefilters/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,17 +233,17 @@ $(function () {
);
});

$(document).on('click', '#edit_blocked_behavior', function(e) {
$(document).on('click', '.edit_blocked_behavior', function(e) {
e.preventDefault();
let parent = $(this).closest('tr');
let elem = parent.find('#block_action');
let elem = parent.find('.block_action');
let sender = $(this).closest('tr').children().first().html();
let scope = sender.startsWith('*@') ? 'domain': 'sender';

Hm_Ajax.request(
[
{'name': 'hm_ajax_hook', 'value': 'ajax_sieve_block_unblock'},
{'name': 'imap_server_id', 'value': $(this).data('mailbox-id')},
{'name': 'imap_server_id', 'value': $(this).attr('mailbox_id')},
{'name': 'block_action', 'value': elem.val()},
{'name': 'scope', 'value': scope},
{'name': 'sender', 'value': sender},
Expand Down Expand Up @@ -276,7 +276,7 @@ $(function () {
let elem = $(this);
Hm_Ajax.request(
[ {'name': 'hm_ajax_hook', 'value': 'ajax_sieve_block_domain'},
{'name': 'imap_server_id', 'value': $(this).attr('mailbox_id')},
{'name': 'imap_server_id', 'value': $(this).attr('data-mailbox_id')},
{'name': 'sender', 'value': sender}
],
function(res) {
Expand Down

0 comments on commit 4f9255e

Please sign in to comment.