From ff8bf62d1d05bae2dd195f1e429414a458875997 Mon Sep 17 00:00:00 2001
From: christer kahasha <62720246+christer77@users.noreply.github.com>
Date: Wed, 2 Oct 2024 17:09:35 +0200
Subject: [PATCH] [FIX]Screen email: fix Adding to Trust Contact while the
email is blocked
---
modules/imap/site.js | 79 ++++++++++++++++++++++++++++----
modules/sievefilters/modules.php | 64 ++++++++++++++++++++++++--
modules/sievefilters/setup.php | 8 ++++
3 files changed, 137 insertions(+), 14 deletions(-)
diff --git a/modules/imap/site.js b/modules/imap/site.js
index 0269b596b..37b63affd 100644
--- a/modules/imap/site.js
+++ b/modules/imap/site.js
@@ -1301,15 +1301,35 @@ var imap_screen_email = function() {
var add_email_in_contact_trusted = function(list_email) {
if (list_email) {
- Hm_Ajax.request(
- [
- { name: 'hm_ajax_hook', value: 'ajax_add_contact' },
- { name: 'email_address', value: list_email.join(',') },
- ],
- function (res) {
- window.location.reload();
- }
- );
+ Hm_Ajax.request(
+ [
+ { name: 'hm_ajax_hook', value: 'ajax_add_contact' },
+ { name: 'email_address', value: list_email.join(',') },
+ ],
+ function (res) {
+ window.location.reload();
+ }
+ );
+ }
+};
+
+var list_blocked_senders = [];
+get_liste_block_sieve(Hm_Utils.parse_folder_path(hm_list_path()));
+
+function get_liste_block_sieve(detail) {
+ var page = hm_page_name();
+ if (page == 'message_list') {
+ Hm_Ajax.request(
+ [
+ { name: 'hm_ajax_hook', value: 'ajax_liste_block_sieve' },
+ { name: 'imap_server_id', 'value': detail.server_id},
+ ],
+ function (res) {
+ if (res.ajax_liste_block_sieve) {
+ list_blocked_senders = JSON.parse(res.ajax_liste_block_sieve);
+ }
+ }
+ );
}
};
@@ -1317,15 +1337,54 @@ $('.screen-email-unlike').on("click", function() { imap_screen_email(); return f
$('.screen-email-like').on("click", function() {
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 = "
";
+ email_existing_in_blocked_senders.forEach(sender => {
+ sender = sender.trim();
+ list_html += `- ${sender}
`;
+ });
+ list_html += "
";
+ 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 + `${hm_trans('If you add these, all will be unblocked.
Are you sure you want to add this in your Trust contact?')}
`);
+ 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() {
diff --git a/modules/sievefilters/modules.php b/modules/sievefilters/modules.php
index 8949e994d..42d2ce663 100644
--- a/modules/sievefilters/modules.php
+++ b/modules/sievefilters/modules.php
@@ -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;
}
}
@@ -1345,9 +1347,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'));
@@ -1379,7 +1379,7 @@ 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()}");
@@ -1387,3 +1387,59 @@ public function process() {
$this->out('success', $success);
}
}
+class Hm_Handler_liste_block_sieve_script extends Hm_Handler_Module {
+ public function process() {
+ list($success, $form) = $this->process_form(array('imap_server_id'));
+ if (!$success) {
+ return;
+ }
+
+ foreach ($this->user_config->get('imap_servers') as $idx => $mailbox) {
+ if ($idx == $form['imap_server_id']) {
+ $imap_account = $mailbox;
+ break;
+ }
+ }
+
+ $email_sender = $this->request->post['sender'];
+ if (mb_strstr($email_sender, '*')) {
+ $email_sender = str_replace('*', '', $email_sender);
+ }
+
+ $factory = get_sieve_client_factory($this->config);
+ try {
+ $client = $factory->init($this->user_config, $imap_account);
+ $scripts = $client->listScripts();
+
+ if(array_search('blocked_senders', $scripts, true) === false) {
+ $client->putScript(
+ 'blocked_senders',
+ ''
+ );
+ }
+
+ $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(str_replace("*", "", base64_decode($base64_obj)));
+ foreach ($blocked_list as $blocked_sender) {
+ $blocked_senders[] = $blocked_sender;
+ }
+ }
+ $this->out('ajax_liste_block_sieve', json_encode($blocked_senders));
+
+ } catch (Exception $e) {
+ Hm_Msgs::add("ERRSieve: {$e->getMessage()}");
+ return;
+ }
+ }
+}
+
+
+class Hm_Output_liste_block_sieve_output extends Hm_Output_Module {
+ public function output() {
+ $liste_block_sieve = $this->get('ajax_liste_block_sieve', "");
+ $this->out('ajax_liste_block_sieve', $liste_block_sieve);
+ }
+}
diff --git a/modules/sievefilters/setup.php b/modules/sievefilters/setup.php
index 121811301..c4f75af8b 100644
--- a/modules/sievefilters/setup.php
+++ b/modules/sievefilters/setup.php
@@ -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_liste_block_sieve', 'core');
+add_handler('ajax_liste_block_sieve', 'liste_block_sieve_script', true);
+add_output('ajax_liste_block_sieve', 'liste_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');
@@ -124,6 +129,8 @@
'ajax_sieve_block_domain',
'ajax_sieve_block_change_behaviour',
'ajax_sieve_toggle_script_state',
+ 'ajax_liste_block_sieve',
+ 'message_list',
),
'allowed_output' => array(
'imap_server_ids' => array(FILTER_UNSAFE_RAW, false),
@@ -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_liste_block_sieve' => array(FILTER_UNSAFE_RAW, false),
),
'allowed_get' => array(),
'allowed_post' => array(