trim email address when added as forwarder, fixes #591

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2018-11-23 09:03:27 +01:00
parent 3a3b35b2eb
commit 1d3d8d0f28
2 changed files with 78 additions and 41 deletions

View File

@@ -63,6 +63,9 @@ class EmailForwarders extends ApiCommand implements ResourceEntity
// current destination array
$result['destination_array'] = explode(' ', $result['destination']);
// prepare destination
$destination = trim($destination);
if (! validateEmail($destination)) {
standard_error('destinationiswrong', $destination, true);
} elseif ($destination == $result['email']) {

View File

@@ -2,6 +2,7 @@
use PHPUnit\Framework\TestCase;
/**
*
* @covers ApiCommand
* @covers ApiParameter
* @covers Emails
@@ -100,6 +101,7 @@ class MailsTest extends TestCase
}
/**
*
* @depends testCustomerEmailForwardersAdd
*/
public function testCustomerEmailForwardersAddNoMoreResources()
@@ -118,6 +120,7 @@ class MailsTest extends TestCase
}
/**
*
* @depends testCustomerEmailForwardersAddNoMoreResources
*/
public function testCustomerEmailForwardersAddEmailHidden()
@@ -137,6 +140,7 @@ class MailsTest extends TestCase
}
/**
*
* @depends testCustomerEmailForwardersAddEmailHidden
*/
public function testCustomerEmailForwardersDeleteEmailHidden()
@@ -156,6 +160,7 @@ class MailsTest extends TestCase
}
/**
*
* @depends testCustomerEmailForwardersDeleteEmailHidden
*/
public function testCustomerEmailForwardersAddAnother()
@@ -180,6 +185,32 @@ class MailsTest extends TestCase
}
/**
*
* @depends testCustomerEmailForwardersDeleteEmailHidden
*/
public function testCustomerEmailForwardersAddWithSpaces()
{
global $admin_userdata;
Settings::Set('panel.customer_hide_options', '', true);
// get customer
$json_result = Customers::getLocal($admin_userdata, array(
'loginname' => 'test1'
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$data = [
'emailaddr' => 'info@test2.local',
'destination' => 'other3@domain.tld '
];
$json_result = EmailForwarders::getLocal($customer_userdata, $data)->add();
$result = json_decode($json_result, true)['data'];
$this->assertEquals('other@domain.tld other2@domain.tld other3@domain.tld', $result['destination']);
}
/**
*
* @depends testCustomerEmailForwardersAdd
*/
public function testCustomerEmailForwardersAddExistingAsMail()
@@ -201,6 +232,7 @@ class MailsTest extends TestCase
}
/**
*
* @depends testCustomerEmailForwardersAdd
*/
public function testCustomerEmailForwardersAddExistingAsDestination()
@@ -261,6 +293,7 @@ class MailsTest extends TestCase
}
/**
*
* @depends testCustomerEmailForwardersAddAnother
*/
public function testCustomerEmailForwardersDelete()
@@ -283,6 +316,7 @@ class MailsTest extends TestCase
}
/**
*
* @depends testCustomerEmailForwardersAddAnother
*/
public function testCustomerEmailForwardersDeleteUnknown()
@@ -405,7 +439,7 @@ class MailsTest extends TestCase
global $admin_userdata;
// remove possible existing delete tasks
Database::query("TRUNCATE `".TABLE_PANEL_TASKS."`");
Database::query("TRUNCATE `" . TABLE_PANEL_TASKS . "`");
Settings::Set('panel.sendalternativemail', 0, true);
// get customer