From 48a931ba990e49d6e331fe5a753a7e5ef45957f8 Mon Sep 17 00:00:00 2001 From: Mariusz Krzaczkowski Date: Fri, 27 Nov 2020 11:47:47 +0100 Subject: [PATCH] Improved support for white and black list --- plugins/yetiforce/elastic.css | 4 +++ plugins/yetiforce/preview.js | 12 +++++--- plugins/yetiforce/yetiforce.php | 53 +++++++++++++++++++++++++++++---- version.php | 4 +-- 4 files changed, 62 insertions(+), 11 deletions(-) diff --git a/plugins/yetiforce/elastic.css b/plugins/yetiforce/elastic.css index 7abd8d36..133ee7c6 100644 --- a/plugins/yetiforce/elastic.css +++ b/plugins/yetiforce/elastic.css @@ -72,3 +72,7 @@ button.btn.fakeMail:before { #message-content .attachmentslist:not(:empty) { margin-bottom: 0.5rem; } +.listing li.selected, +.listing tr.selected td { + background-color: #d0f1ff; +} diff --git a/plugins/yetiforce/preview.js b/plugins/yetiforce/preview.js index 7f6f387e..be48e653 100644 --- a/plugins/yetiforce/preview.js +++ b/plugins/yetiforce/preview.js @@ -3,7 +3,9 @@ if (window.rcmail) { rcmail.addEventListener('init', function () { rcmail.crm = rcmail.getCrmWindow(); - rcmail.loadActionBar(); + if (rcmail.env.uid) { + rcmail.loadActionBar(); + } rcmail.env.message_commands.push('yetiforce.importICS'); rcmail.register_command( 'yetiforce.importICS', @@ -35,7 +37,7 @@ if (window.rcmail) { rcmail.enable_command('plugin.yetiforce.loadMailAnalysis', list.get_selection(false).length > 0); }); rcmail.addEventListener('listupdate', function () { - let btns = $('#toolbar-menu .js-spam-btn'); + let btns = $('#toolbar-menu .js-white-list-btn'); if (rcmail.env.mailbox === rcmail.env.junk_mailbox) { btns.hide(); } else { @@ -48,6 +50,8 @@ if (window.rcmail) { rcmail.addEventListener('insertrow', function (evt) { if (typeof rcmail.env.rbl_list[evt.uid] !== 'undefined') { evt.row.obj.style.backgroundColor = rcmail.env.rbl_list[evt.uid]; + } else { + evt.row.obj.style.backgroundColor = '#eaeaea'; } if (typeof rcmail.env.sender_list[evt.uid] !== 'undefined') { $('.fromto', evt.row.obj).prepend( @@ -400,8 +404,8 @@ rcube_webmail.prototype.showMailAnalysis = function (content) { }) .fail(function () { progressIndicatorElement.progressIndicator({ mode: 'hide' }); - app.showNotify({ - text: app.vtranslate('JS_ERROR'), + rcmail.crm.app.showNotify({ + text: rcmail.crm.app.vtranslate('JS_ERROR'), type: 'error' }); }); diff --git a/plugins/yetiforce/yetiforce.php b/plugins/yetiforce/yetiforce.php index 16cfba73..da033618 100644 --- a/plugins/yetiforce/yetiforce.php +++ b/plugins/yetiforce/yetiforce.php @@ -52,6 +52,7 @@ public function init() 'LBL_BLACK_LIST_DESC' => \App\Language::translate('LBL_BLACK_LIST_DESC', 'OSSMail', false, false), 'BTN_WHITE_LIST' => \App\Language::translate('LBL_WHITE_LIST', 'OSSMail', false, false), 'LBL_WHITE_LIST_DESC' => \App\Language::translate('LBL_WHITE_LIST_DESC', 'OSSMail', false, false), + 'LBL_ALERT_NEUTRAL_LIST' => \App\Language::translate('LBL_ALERT_NEUTRAL_LIST', 'OSSMail', false, false), 'LBL_ALERT_BLACK_LIST' => \App\Language::translate('LBL_BLACK_LIST_ALERT', 'OSSMail', false, false), 'LBL_ALERT_WHITE_LIST' => \App\Language::translate('LBL_WHITE_LIST_ALERT', 'OSSMail', false, false), 'LBL_ALERT_FAKE_MAIL' => \App\Language::translate('LBL_ALERT_FAKE_MAIL', 'OSSMail'), @@ -64,13 +65,14 @@ public function init() $this->include_stylesheet('preview.css'); $this->add_hook('template_object_messageattachments', [$this, 'appendIcsPreview']); + $this->add_hook('template_object_messagesummary', [$this, 'messageSummary']); $this->add_hook('message_load', [$this, 'messageLoad']); $this->add_button([ 'command' => 'plugin.yetiforce.addSenderToList', 'type' => 'link', 'prop' => 1, - 'class' => 'button yfi-fa-check-circle disabled js-spam-btn text-success', + 'class' => 'button yfi-fa-check-circle disabled js-white-list-btn text-success', 'classact' => 'button yfi-fa-check-circle text-success', 'classsel' => 'button yfi-fa-check-circle pressed text-success', 'title' => 'LBL_WHITE_LIST_DESC', @@ -81,7 +83,7 @@ public function init() 'command' => 'plugin.yetiforce.addSenderToList', 'type' => 'link', 'prop' => 0, - 'class' => 'button yfi-fa-ban disabled js-spam-btn text-danger', + 'class' => 'button yfi-fa-ban disabled text-danger', 'classact' => 'button yfi-fa-ban text-danger', 'classsel' => 'button yfi-fa-ban pressed text-danger', 'title' => 'LBL_BLACK_LIST_DESC', @@ -91,7 +93,7 @@ public function init() $this->add_button([ 'command' => 'plugin.yetiforce.loadMailAnalysis', 'type' => 'link', - 'class' => 'button yfi-fa-book-reader disabled js-spam-btn text-info', + 'class' => 'button yfi-fa-book-reader disabled text-info', 'classact' => 'button yfi-fa-book-reader text-info', 'classsel' => 'button yfi-fa-book-reader pressed text-info', 'title' => 'BTN_ANALYSIS_DETAILS', @@ -522,15 +524,21 @@ public function loadSignature(array $args) public function getGlobalSignature() { + $currentPath = getcwd(); + chdir($this->rc->config->get('root_directory')); $config = Settings_Mail_Config_Model::getConfig('signature'); $parser = App\TextParser::getInstanceById($this->currentUser->getId(), 'Users'); $result['text'] = $result['html'] = $parser->setContent($config['signature'])->parse()->getContent(); + chdir($currentPath); return $result; } public function checkAddSignature() { + $currentPath = getcwd(); + chdir($this->rc->config->get('root_directory')); $config = Settings_Mail_Config_Model::getConfig('signature'); + chdir($currentPath); return empty($config['addSignature']) || 'false' === $config['addSignature'] ? true : false; } @@ -1100,18 +1108,27 @@ public function messageObjects(array $p): array ); } } + $rows = []; if ($ip = $rblInstance->getSender()['ip'] ?? '') { - foreach (\App\Mail\Rbl::findIp($ip) as $row) { + $rows = \App\Mail\Rbl::findIp($ip); + } + if ($rows) { + foreach ($rows as $row) { if (1 !== (int) $row['status']) { $black = \App\Mail\Rbl::LIST_TYPE_BLACK_LIST === (int) $row['type'] || \App\Mail\Rbl::LIST_TYPE_PUBLIC_BLACK_LIST === (int) $row['type']; $type = \App\Mail\Rbl::LIST_TYPES[$row['type']]; - $p['content'][] = html::p(['class' => 'mail-type-alert', 'style' => 'background:' . $type['color']], + $p['content'][] = html::p(['class' => 'mail-type-alert', 'style' => 'background:' . $type['alertColor']], html::span(['class' => 'alert-icon ' . $type['icon']], '') . html::span(null, rcube::Q($this->rc->gettext($black ? 'LBL_ALERT_BLACK_LIST' : 'LBL_ALERT_WHITE_LIST'))) ); return $p; } } + } else { + $p['content'][] = html::p(['class' => 'mail-type-alert', 'style' => 'background: #ffd45233'], + html::span(['class' => 'alert-icon far fa-question-circle mr-2 text-warning'], '') . + html::span(null, rcube::Q($this->rc->gettext('LBL_ALERT_NEUTRAL_LIST'))) + ); } return $p; } @@ -1121,4 +1138,30 @@ public function loadMailAnalysis(): void $uid = (int) rcube_utils::get_input_value('_uid', rcube_utils::INPUT_POST); $this->rc->output->command('plugin.yetiforce.showMailAnalysis', $this->rc->imap->get_raw_body($uid)); } + + /** + * Message summary area. + * template_object_messagesummary hook handler. + * + * @param array $args + * + * @return array + */ + public function messageSummary($args) + { + global $MESSAGE, $RCMAIL; + if (!isset($MESSAGE) || empty($MESSAGE->headers)) { + return $args; + } + $header = $MESSAGE->context ? 'from' : rcmail_message_list_smart_column_name(); + if ('from' === $header) { + $mail = $MESSAGE->headers->to; + $label = $RCMAIL->gettext('to'); + } else { + $mail = $MESSAGE->headers->from; + $label = $RCMAIL->gettext('from'); + } + $args['content'] = str_replace('', '', rtrim($args['content'])) . " | {$label} {$mail}"; + return $args; + } } diff --git a/version.php b/version.php index a0701fe6..2357131d 100644 --- a/version.php +++ b/version.php @@ -1,6 +1,6 @@ '2020.11.23', - 'version' => '0.1.0' + 'patch' => '2020.11.27', + 'version' => '0.1.1' ];