Skip to content

Commit

Permalink
Improved support for white and black list
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuszkrzaczkowski committed Nov 27, 2020
1 parent 0486806 commit 48a931b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 11 deletions.
4 changes: 4 additions & 0 deletions plugins/yetiforce/elastic.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
12 changes: 8 additions & 4 deletions plugins/yetiforce/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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 {
Expand All @@ -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(
Expand Down Expand Up @@ -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'
});
});
Expand Down
53 changes: 48 additions & 5 deletions plugins/yetiforce/yetiforce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -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('</span></span></div>', '', rtrim($args['content'])) . " | {$label} {$mail}</span></span></div>";
return $args;
}
}
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

return [
'patch' => '2020.11.23',
'version' => '0.1.0'
'patch' => '2020.11.27',
'version' => '0.1.1'
];

0 comments on commit 48a931b

Please sign in to comment.