diff --git a/modules/imap/site.js b/modules/imap/site.js index 4a16d00227..e00b01f26c 100644 --- a/modules/imap/site.js +++ b/modules/imap/site.js @@ -1408,12 +1408,35 @@ var add_email_in_contact_trusted = function(list_email) { } ); } - }; +}; + +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 = res.ajax_liste_block_sieve; + } + console.log(res) + } + ); + } + +}; $('.screen-email-unlike').on("click", function() { imap_screen_email(); return false; }); $('.screen-email-like').on("click", function() { var list_email = []; + 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") @@ -1422,5 +1445,39 @@ $('.screen-email-like').on("click", function() { } } }); - add_email_in_contact_trusted(list_email); return false; + if (list_blocked_senders) { + for (let i = 0; i < list_blocked_senders.length; i++) { + for (let j = 0; j < list_email.length; j++) { + if (list_blocked_senders[i] === list_email[j]) { + email_existing_in_blocked_senders.push(list_blocked_senders[i]); + } + } + } + console.log(email_existing_in_blocked_senders) + + var list_html = "
    "; + email_existing_in_blocked_senders.forEach(sender => { + console.log(sender) + sender = sender.trim(); + list_html += `
  1. ${sender}
  2. `; + }); + list_html += "
"; + const modal = new Hm_Modal({ + modalId: 'emptySubjectBodyModal', + title: 'Warning', + btnSize: 'sm' + }); + + var modalContentHeadline = "Adress mail exist in your Block list"; + var showBtnSendAnywayDontWarnFuture = false; + modal.addFooterBtn(hm_trans('Add Emails to Trust contact'), 'btn-warning', handleAddEmail); + modal.setContent(modalContentHeadline + list_html + `

${hm_trans('Are you sure you want to add this in your Trust contact?')}

`); + modal.open(); + function handleAddEmail() { + add_email_in_contact_trusted(list_email); + }; + } else { + add_email_in_contact_trusted(list_email); + } + return false; }); diff --git a/modules/sievefilters/modules.php b/modules/sievefilters/modules.php index dd34d04c06..04a1820501 100644 --- a/modules/sievefilters/modules.php +++ b/modules/sievefilters/modules.php @@ -1345,3 +1345,63 @@ public function process() { } } } + +/** + * Check the status of an SIEVE server + * @subpackage sieve/handler + */ +class Hm_Handler_load_list_sieve_block 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 == $this->request->post['imap_server_id']) { + $imap_account = $mailbox; + } + } + + $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 != '') { + $script_split = preg_split('#\r?\n#', $current_script, 0); + $base64_obj = str_replace("# ", "", $script_split[1]); + $blocked_list = json_decode(base64_decode($base64_obj)); + foreach ($blocked_list as $blocked_sender) { + $blocked_senders[] = $blocked_sender; + } + } + $blocked_senders = array_unique($blocked_senders); + var_dump($blocked_senders);// exit; + $this->out('list_blocked_senders', $blocked_senders); + + } catch (Exception $e) { + Hm_Msgs::add("ERRSieve: {$e->getMessage()}"); + return; + } + } +} +/** + * @subpackage sievefilters/output + */ +class Hm_Output_get_list_sieve_block extends Hm_Output_Module { + public function output() { + $this->out('ajax_liste_block_sieve', $this->get('list_blocked_senders', array())); + } +} diff --git a/modules/sievefilters/setup.php b/modules/sievefilters/setup.php index dceab0a1aa..d5951ae52b 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', 'load_list_sieve_block', true); +add_output('ajax_liste_block_sieve', 'get_list_sieve_block', 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'); @@ -115,6 +120,8 @@ 'ajax_sieve_get_mailboxes', 'ajax_sieve_block_domain', 'ajax_sieve_block_change_behaviour', + 'ajax_liste_block_sieve', + 'message_list', ), 'allowed_output' => array( 'imap_server_ids' => array(FILTER_UNSAFE_RAW, false), @@ -127,6 +134,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, FILTER_REQUIRE_ARRAY), ), 'allowed_get' => array(), 'allowed_post' => array(