Skip to content

Commit

Permalink
[FIX]Screen email: fix Adding to Trust Contact while the email is blo…
Browse files Browse the repository at this point in the history
…cked
  • Loading branch information
christer77 committed Jan 10, 2025
1 parent e4af09b commit f847402
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 23 deletions.
4 changes: 3 additions & 1 deletion modules/core/js_modules/route_handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ function applyMessaleListPageHandlers(routeParams) {
e.preventDefault();
Hm_Message_List.toggle_rows();
});


get_list_block_sieve();

if (routeParams.list_path === 'github_all') {
return applyGithubMessageListPageHandler(routeParams);
}
Expand Down
63 changes: 62 additions & 1 deletion modules/imap/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -1356,19 +1356,80 @@ var add_email_in_contact_trusted = function(list_email) {
}
};


function get_list_block_sieve() {
sessionStorage.removeItem('list_blocked');
var detail = Hm_Utils.parse_folder_path(hm_list_path());
var list_blocked_senders = [];
var page = hm_page_name();
if (page == 'message_list') {
Hm_Ajax.request(
[
{ name: 'hm_ajax_hook', value: 'ajax_list_block_sieve' },
{ name: 'imap_server_id', 'value': detail.server_id},
],
function (res) {
if (res.ajax_list_block_sieve) {
sessionStorage.setItem('list_blocked', res.ajax_list_block_sieve);
}
}
);
}
};

$('.screen-email-unlike').on("click", function() { imap_screen_email(); return false; });

$('.screen-email-like').on("click", function() {
var list_blocked_senders = (sessionStorage.getItem('list_blocked') !== null) ? JSON.parse(sessionStorage.getItem('list_blocked')) : [];
var list_email = [];
var list_msg_uid = [];
var email_existing_in_blocked_senders = [];
$('input[type=checkbox]').each(function() {
if (this.checked && this.id.search('imap') != -1) {
let email = $('.'+ this.id +' .from').attr("data-title")
if (email = email.trim()) {
list_email.push(email);
if (list_blocked_senders.length > 0) {
list_blocked_senders.forEach((sender, index) => {
if (sender === email) {
email_existing_in_blocked_senders.push(email);
list_msg_uid.push($(this).parent().parent().attr("data-uid"));
delete list_blocked_senders[index];
}
});
}
}
}
});
add_email_in_contact_trusted(list_email); return false;

if (email_existing_in_blocked_senders) {
var list_html = "<ol>";
email_existing_in_blocked_senders.forEach(sender => {
sender = sender.trim();
list_html += `<li>${sender}</li>`;
});
list_html += "</ol>";
const modal = new Hm_Modal({
modalId: 'emptySubjectBodyModal',
title: 'Warning',
btnSize: 'sm'
});

var modalContentHeadline = "Adress mail exist in your Block list";
modal.addFooterBtn(hm_trans('Add Emails to Trust contact'), 'btn-warning', handleAddEmail);
modal.setContent(modalContentHeadline + list_html + `<p>${hm_trans('If you add these, all will be unblocked.<br>Are you sure you want to add this in your Trust contact?')}</p>`);
modal.open();
function handleAddEmail() {
list_msg_uid.forEach(function(msg_uid) {
block_unblock_sender(msg_uid, Hm_Utils.parse_folder_path(hm_list_path()), 'sender', 'unblocked');
});
modal.hide();
add_email_in_contact_trusted(list_email);
};
} else {
add_email_in_contact_trusted(list_email);
}
return false;
});

$(document).on('click', '[data-bs-dismiss="modal"]', function() {
Expand Down
19 changes: 17 additions & 2 deletions modules/sievefilters/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,22 @@ function get_sieve_client_factory($site_config)
}
}

if (!hm_exists('encode_or_decode_blocked_senders_script')) {
function encode_or_decode_blocked_senders_script($script, $index = 1, $action = "decode")
{
$blocked_list = [];
if ($script != '') {
$base64_obj = str_replace("# ", "", preg_split('#\r?\n#', $script, 0)[$index]);
if ($action == "decode") {
$blocked_list = json_decode(str_replace("*", "", base64_decode($base64_obj)));
} else {
$blocked_list = json_encode(base64_decode($base64_obj));
}
}
return $blocked_list;
}
}

if (!hm_exists('get_domain')) {
function get_domain($email)
{
Expand Down Expand Up @@ -424,8 +440,7 @@ function get_blocked_senders_array($mailbox, $site_config, $user_config)
$blocked_senders = [];
$current_script = $client->getScript('blocked_senders');
if ($current_script != '') {
$base64_obj = str_replace("# ", "", preg_split('#\r?\n#', $current_script, 0)[1]);
$blocked_list = json_decode(base64_decode($base64_obj));
$blocked_list = encode_or_decode_blocked_senders_script($current_script);
if (!$blocked_list) {
return [];
}
Expand Down
69 changes: 50 additions & 19 deletions modules/sievefilters/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public function process() {
try {
$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)));
$base64_obj = str_replace("# ", "", preg_split('#\r?\n#', $script, 0)[2]);
$this->out('actions', json_encode(base64_decode($base64_obj)));
$list = encode_or_decode_blocked_senders_script($script, 1, "encode");
$this->out('conditions', $list);
$list = encode_or_decode_blocked_senders_script($script, 2, "encode");
$this->out('actions', $list);
if (mb_strstr($script, 'allof')) {
$this->out('test_type', 'ALLOF');
} else {
Expand Down Expand Up @@ -203,9 +203,11 @@ public function process() {
*/
class Hm_Handler_sieve_block_domain_script extends Hm_Handler_Module {
public function process() {
$imap_account = null;
foreach ($this->user_config->get('imap_servers') as $idx => $mailbox) {
if ($idx == $this->request->post['imap_server_id']) {
$imap_account = $mailbox;
break;
}
}

Expand All @@ -216,8 +218,7 @@ public function process() {
$scripts = $client->listScripts();

$current_script = $client->getScript('blocked_senders');
$base64_obj = str_replace("# ", "", preg_split('#\r?\n#', $current_script, 0)[1]);
$blocked_list = json_decode(base64_decode($base64_obj));
$blocked_list = encode_or_decode_blocked_senders_script($current_script);

$domain = get_domain($this->request->post['sender']);
$blocked_wildcard = '@'.$domain;
Expand Down Expand Up @@ -357,8 +358,7 @@ public function process() {
$current_script = $client->getScript('blocked_senders');
$unblock_sender = false;
if ($current_script != '') {
$base64_obj = str_replace("# ", "", preg_split('#\r?\n#', $current_script, 0)[1]);
$blocked_list = json_decode(str_replace("*", "", base64_decode($base64_obj)));
$blocked_list = encode_or_decode_blocked_senders_script($current_script);
foreach ($blocked_list as $blocked_sender) {
if ($blocked_sender != $email_sender) {
$blocked_senders[] = $blocked_sender;
Expand Down Expand Up @@ -492,20 +492,15 @@ public function process() {
$blocked_list_actions = [];
$unblock_sender = false;
if ($current_script != '') {
$script_split = preg_split('#\r?\n#', $current_script, 0);
$base64_obj = str_replace("# ", "", $script_split[1]);
$blocked_list = json_decode(base64_decode($base64_obj));
$blocked_list = encode_or_decode_blocked_senders_script($current_script);
foreach ($blocked_list as $blocked_sender) {
if ($blocked_sender != $email_sender) {
$blocked_senders[] = $blocked_sender;
continue;
}
$unblock_sender = true;
}
$base64_obj_actions = str_replace("# ", "", $script_split[2]);
if ($base64_obj_actions) {
$blocked_list_actions = json_decode(base64_decode($base64_obj_actions), true);
}
$blocked_list_actions = encode_or_decode_blocked_senders_script($current_script, 2);
}
if (isset($this->request->post['change_behavior']) && $unblock_sender) {
$unblock_sender = false;
Expand Down Expand Up @@ -1339,9 +1334,7 @@ public function process() {
}
}

/**
* @subpackage sievefilterstoggle/handler
*/

class Hm_Handler_sieve_toggle_script_state extends Hm_Handler_Module {
public function process() {
list($success, $form) = $this->process_form(array('imap_account', 'script_state', 'sieve_script_name'));
Expand Down Expand Up @@ -1373,11 +1366,49 @@ public function process() {
save_main_script($client, $main_script, $scripts);
$client->activateScript('main_script');
$client->close();

Hm_Msgs::add("Script $state");
} catch (Exception $e) {
Hm_Msgs::add("ERRSieve: {$e->getMessage()}");
}
$this->out('success', $success);
}
}
class Hm_Handler_list_block_sieve_script extends Hm_Handler_Module {
public function process() {
list($success, $form) = $this->process_form(array('imap_server_id'));
if (!$success) {
return;
}

Hm_IMAP_List::init($this->user_config, $this->session);
$imap_account = Hm_IMAP_List::get($form['imap_server_id'], true);

$factory = get_sieve_client_factory($this->config);
try {
$client = $factory->init($this->user_config, $imap_account);

$blocked_senders = [];
$current_script = $client->getScript('blocked_senders');
if ($current_script != '') {
$blocked_list = encode_or_decode_blocked_senders_script($current_script);
foreach ($blocked_list as $blocked_sender) {
$blocked_senders[] = $blocked_sender;
}
}
$this->out('ajax_list_block_sieve', json_encode($blocked_senders));

} catch (Exception $e) {
Hm_Msgs::add("ERRSieve: {$e->getMessage()}");
return;
}
}
}


class Hm_Output_list_block_sieve_output extends Hm_Output_Module {
public function output() {
$list_block_sieve = $this->get('ajax_list_block_sieve', "");
$this->out('ajax_list_block_sieve', $list_block_sieve);
}
}
8 changes: 8 additions & 0 deletions modules/sievefilters/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@
add_handler('ajax_sieve_unblock_sender', 'sieve_unblock_sender', true);
add_output('ajax_sieve_unblock_sender', 'sieve_block_unblock_output', true);

/* liste of sieve blocked */
setup_base_ajax_page('ajax_list_block_sieve', 'core');
add_handler('ajax_list_block_sieve', 'list_block_sieve_script', true);
add_output('ajax_list_block_sieve', 'list_block_sieve_output', true);

/* get mailboxes script */
setup_base_ajax_page('ajax_sieve_get_mailboxes', 'core');
add_handler('ajax_sieve_get_mailboxes', 'load_imap_servers_from_config', true, 'imap', 'load_user_data', 'after');
Expand Down Expand Up @@ -124,6 +129,8 @@
'ajax_sieve_block_domain',
'ajax_sieve_block_change_behaviour',
'ajax_sieve_toggle_script_state',
'ajax_list_block_sieve',
'message_list',
),
'allowed_output' => array(
'imap_server_ids' => array(FILTER_UNSAFE_RAW, false),
Expand All @@ -136,6 +143,7 @@
'sieve_detail_display' => array(FILTER_UNSAFE_RAW, false),
'imap_extensions_display' => array(FILTER_UNSAFE_RAW, false),
'script_details' => array(FILTER_UNSAFE_RAW, FILTER_REQUIRE_ARRAY),
'ajax_list_block_sieve' => array(FILTER_UNSAFE_RAW, false),
),
'allowed_get' => array(),
'allowed_post' => array(
Expand Down

0 comments on commit f847402

Please sign in to comment.