From e89c7c932894b69d9ee65bdca4255af3fe432708 Mon Sep 17 00:00:00 2001 From: yuri Date: Mon, 19 Oct 2015 15:36:22 +0300 Subject: [PATCH] email filter improvement --- application/Espo/Core/Mail/FiltersMatcher.php | 4 ++-- .../Espo/Resources/i18n/en_US/EmailFilter.json | 4 ++-- .../metadata/entityDefs/EmailFilter.json | 6 ++++-- tests/Espo/Core/Mail/FiltersMatcherTest.php | 18 ++++++++++++++++++ 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/application/Espo/Core/Mail/FiltersMatcher.php b/application/Espo/Core/Mail/FiltersMatcher.php index bbe686b534..b813d60b58 100644 --- a/application/Espo/Core/Mail/FiltersMatcher.php +++ b/application/Espo/Core/Mail/FiltersMatcher.php @@ -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; } } diff --git a/application/Espo/Resources/i18n/en_US/EmailFilter.json b/application/Espo/Resources/i18n/en_US/EmailFilter.json index b801377d9f..538b4a2e73 100644 --- a/application/Espo/Resources/i18n/en_US/EmailFilter.json +++ b/application/Espo/Resources/i18n/en_US/EmailFilter.json @@ -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)." } } diff --git a/application/Espo/Resources/metadata/entityDefs/EmailFilter.json b/application/Espo/Resources/metadata/entityDefs/EmailFilter.json index 87daac9dce..dfb358c07c 100644 --- a/application/Espo/Resources/metadata/entityDefs/EmailFilter.json +++ b/application/Espo/Resources/metadata/entityDefs/EmailFilter.json @@ -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", diff --git a/tests/Espo/Core/Mail/FiltersMatcherTest.php b/tests/Espo/Core/Mail/FiltersMatcherTest.php index 05969e2802..c533e5fb73 100644 --- a/tests/Espo/Core/Mail/FiltersMatcherTest.php +++ b/tests/Espo/Core/Mail/FiltersMatcherTest.php @@ -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(