email filter improvement

This commit is contained in:
yuri
2015-10-19 15:36:22 +03:00
parent 7808865080
commit e89c7c9328
4 changed files with 26 additions and 6 deletions
@@ -36,7 +36,7 @@ class FiltersMatcher
{
foreach ($filterList as $filter) {
if ($filter->get('from')) {
if (strtolower($filter->get('from')) === strtolower($email->get('from'))) {
if ($this->matchString(strtolower($filter->get('from')), strtolower($email->get('from')))) {
return true;
}
}
@@ -44,7 +44,7 @@ class FiltersMatcher
if ($email->get('to')) {
$toArr = explode(';', $email->get('to'));
foreach ($toArr as $to) {
if (strtolower($to) === strtolower($filter->get('to'))) {
if ($this->matchString(strtolower($filter->get('to')), strtolower($to))) {
return true;
}
}
@@ -12,8 +12,8 @@
"name": "Just a name of the filter.",
"subject": "Use wildcard *:\n\ntext* - starts with text,\n*text* - contains text,\n*text - ends with text.",
"bodyContains": "Body of email contains any of specified words or phrases.",
"from": "Emails being sent from the specified address. Leave empty if not needed.",
"to": "Emails being sent to the specified address. Leave empty if not needed.",
"from": "Emails being sent from the specified address. Leave empty if not needed. You can use wildcard *.",
"to": "Emails being sent to the specified address. Leave empty if not needed. You can use wildcard *.",
"parent": "Leave it empty to apply this filter globally (to all incoming emails)."
}
}
@@ -9,12 +9,14 @@
"from": {
"type": "varchar",
"maxLength": 255,
"tooltip": true
"tooltip": true,
"trim": true
},
"to": {
"type": "varchar",
"maxLength": 255,
"tooltip": true
"tooltip": true,
"trim": true
},
"subject": {
"type": "varchar",
@@ -89,6 +89,15 @@ class FiltersMatcherTest extends \PHPUnit_Framework_TestCase
$filterList = [$filter];
$this->assertTrue($this->object->match($email, $filterList));
$email = new \Espo\Entities\Email($this->emailDefs);
$email->set('from', 'test@tester');
$filter = new \Espo\Entities\EmailFilter($this->filterDefs);
$filter->set(array(
'from' => '*@tester'
));
$filterList = [$filter];
$this->assertTrue($this->object->match($email, $filterList));
$email->set('from', 'test@tester');
$email->set('to', 'test@tester;baraka@tester');
$filter = new \Espo\Entities\EmailFilter($this->filterDefs);
@@ -98,6 +107,15 @@ class FiltersMatcherTest extends \PHPUnit_Framework_TestCase
$filterList = [$filter];
$this->assertTrue($this->object->match($email, $filterList));
$email->set('from', 'test@tester');
$email->set('to', 'test@tester;baraka@man');
$filter = new \Espo\Entities\EmailFilter($this->filterDefs);
$filter->set(array(
'to' => '*@tester'
));
$filterList = [$filter];
$this->assertTrue($this->object->match($email, $filterList));
$email->set('subject', 'test hello man');
$filter = new \Espo\Entities\EmailFilter($this->filterDefs);
$filter->set(array(