trim email address when added as forwarder, fixes #591
Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
@@ -63,6 +63,9 @@ class EmailForwarders extends ApiCommand implements ResourceEntity
|
|||||||
// current destination array
|
// current destination array
|
||||||
$result['destination_array'] = explode(' ', $result['destination']);
|
$result['destination_array'] = explode(' ', $result['destination']);
|
||||||
|
|
||||||
|
// prepare destination
|
||||||
|
$destination = trim($destination);
|
||||||
|
|
||||||
if (! validateEmail($destination)) {
|
if (! validateEmail($destination)) {
|
||||||
standard_error('destinationiswrong', $destination, true);
|
standard_error('destinationiswrong', $destination, true);
|
||||||
} elseif ($destination == $result['email']) {
|
} elseif ($destination == $result['email']) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* @covers ApiCommand
|
* @covers ApiCommand
|
||||||
* @covers ApiParameter
|
* @covers ApiParameter
|
||||||
* @covers Emails
|
* @covers Emails
|
||||||
@@ -16,13 +17,13 @@ class MailsTest extends TestCase
|
|||||||
public function testCustomerEmailsAdd()
|
public function testCustomerEmailsAdd()
|
||||||
{
|
{
|
||||||
global $admin_userdata;
|
global $admin_userdata;
|
||||||
|
|
||||||
// get customer
|
// get customer
|
||||||
$json_result = Customers::getLocal($admin_userdata, array(
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
'loginname' => 'test1'
|
'loginname' => 'test1'
|
||||||
))->get();
|
))->get();
|
||||||
$customer_userdata = json_decode($json_result, true)['data'];
|
$customer_userdata = json_decode($json_result, true)['data'];
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'email_part' => 'info',
|
'email_part' => 'info',
|
||||||
'domain' => 'test2.local'
|
'domain' => 'test2.local'
|
||||||
@@ -64,13 +65,13 @@ class MailsTest extends TestCase
|
|||||||
public function testCustomerEmailsUpdate()
|
public function testCustomerEmailsUpdate()
|
||||||
{
|
{
|
||||||
global $admin_userdata;
|
global $admin_userdata;
|
||||||
|
|
||||||
// get customer
|
// get customer
|
||||||
$json_result = Customers::getLocal($admin_userdata, array(
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
'loginname' => 'test1'
|
'loginname' => 'test1'
|
||||||
))->get();
|
))->get();
|
||||||
$customer_userdata = json_decode($json_result, true)['data'];
|
$customer_userdata = json_decode($json_result, true)['data'];
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'emailaddr' => 'catchall@test2.local',
|
'emailaddr' => 'catchall@test2.local',
|
||||||
'iscatchall' => 1
|
'iscatchall' => 1
|
||||||
@@ -83,13 +84,13 @@ class MailsTest extends TestCase
|
|||||||
public function testCustomerEmailForwardersAdd()
|
public function testCustomerEmailForwardersAdd()
|
||||||
{
|
{
|
||||||
global $admin_userdata;
|
global $admin_userdata;
|
||||||
|
|
||||||
// get customer
|
// get customer
|
||||||
$json_result = Customers::getLocal($admin_userdata, array(
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
'loginname' => 'test1'
|
'loginname' => 'test1'
|
||||||
))->get();
|
))->get();
|
||||||
$customer_userdata = json_decode($json_result, true)['data'];
|
$customer_userdata = json_decode($json_result, true)['data'];
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'emailaddr' => 'info@test2.local',
|
'emailaddr' => 'info@test2.local',
|
||||||
'destination' => 'other@domain.tld'
|
'destination' => 'other@domain.tld'
|
||||||
@@ -98,14 +99,15 @@ class MailsTest extends TestCase
|
|||||||
$result = json_decode($json_result, true)['data'];
|
$result = json_decode($json_result, true)['data'];
|
||||||
$this->assertEquals('other@domain.tld', $result['destination']);
|
$this->assertEquals('other@domain.tld', $result['destination']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* @depends testCustomerEmailForwardersAdd
|
* @depends testCustomerEmailForwardersAdd
|
||||||
*/
|
*/
|
||||||
public function testCustomerEmailForwardersAddNoMoreResources()
|
public function testCustomerEmailForwardersAddNoMoreResources()
|
||||||
{
|
{
|
||||||
global $admin_userdata;
|
global $admin_userdata;
|
||||||
|
|
||||||
// get customer
|
// get customer
|
||||||
$json_result = Customers::getLocal($admin_userdata, array(
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
'loginname' => 'test1'
|
'loginname' => 'test1'
|
||||||
@@ -116,16 +118,17 @@ class MailsTest extends TestCase
|
|||||||
$this->expectExceptionMessage("No more resources available");
|
$this->expectExceptionMessage("No more resources available");
|
||||||
EmailForwarders::getLocal($customer_userdata)->add();
|
EmailForwarders::getLocal($customer_userdata)->add();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* @depends testCustomerEmailForwardersAddNoMoreResources
|
* @depends testCustomerEmailForwardersAddNoMoreResources
|
||||||
*/
|
*/
|
||||||
public function testCustomerEmailForwardersAddEmailHidden()
|
public function testCustomerEmailForwardersAddEmailHidden()
|
||||||
{
|
{
|
||||||
global $admin_userdata;
|
global $admin_userdata;
|
||||||
|
|
||||||
Settings::Set('panel.customer_hide_options', 'email', true);
|
Settings::Set('panel.customer_hide_options', 'email', true);
|
||||||
|
|
||||||
// get customer
|
// get customer
|
||||||
$json_result = Customers::getLocal($admin_userdata, array(
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
'loginname' => 'test1'
|
'loginname' => 'test1'
|
||||||
@@ -137,14 +140,15 @@ class MailsTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* @depends testCustomerEmailForwardersAddEmailHidden
|
* @depends testCustomerEmailForwardersAddEmailHidden
|
||||||
*/
|
*/
|
||||||
public function testCustomerEmailForwardersDeleteEmailHidden()
|
public function testCustomerEmailForwardersDeleteEmailHidden()
|
||||||
{
|
{
|
||||||
global $admin_userdata;
|
global $admin_userdata;
|
||||||
|
|
||||||
Settings::Set('panel.customer_hide_options', 'email', true);
|
Settings::Set('panel.customer_hide_options', 'email', true);
|
||||||
|
|
||||||
// get customer
|
// get customer
|
||||||
$json_result = Customers::getLocal($admin_userdata, array(
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
'loginname' => 'test1'
|
'loginname' => 'test1'
|
||||||
@@ -154,22 +158,23 @@ class MailsTest extends TestCase
|
|||||||
$this->expectExceptionMessage("You cannot access this resource");
|
$this->expectExceptionMessage("You cannot access this resource");
|
||||||
EmailForwarders::getLocal($customer_userdata)->delete();
|
EmailForwarders::getLocal($customer_userdata)->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* @depends testCustomerEmailForwardersDeleteEmailHidden
|
* @depends testCustomerEmailForwardersDeleteEmailHidden
|
||||||
*/
|
*/
|
||||||
public function testCustomerEmailForwardersAddAnother()
|
public function testCustomerEmailForwardersAddAnother()
|
||||||
{
|
{
|
||||||
global $admin_userdata;
|
global $admin_userdata;
|
||||||
|
|
||||||
Settings::Set('panel.customer_hide_options', '', true);
|
Settings::Set('panel.customer_hide_options', '', true);
|
||||||
|
|
||||||
// get customer
|
// get customer
|
||||||
$json_result = Customers::getLocal($admin_userdata, array(
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
'loginname' => 'test1'
|
'loginname' => 'test1'
|
||||||
))->get();
|
))->get();
|
||||||
$customer_userdata = json_decode($json_result, true)['data'];
|
$customer_userdata = json_decode($json_result, true)['data'];
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'emailaddr' => 'info@test2.local',
|
'emailaddr' => 'info@test2.local',
|
||||||
'destination' => 'other2@domain.tld'
|
'destination' => 'other2@domain.tld'
|
||||||
@@ -180,18 +185,44 @@ class MailsTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @depends testCustomerEmailForwardersAdd
|
*
|
||||||
|
* @depends testCustomerEmailForwardersDeleteEmailHidden
|
||||||
*/
|
*/
|
||||||
public function testCustomerEmailForwardersAddExistingAsMail()
|
public function testCustomerEmailForwardersAddWithSpaces()
|
||||||
{
|
{
|
||||||
global $admin_userdata;
|
global $admin_userdata;
|
||||||
|
|
||||||
|
Settings::Set('panel.customer_hide_options', '', true);
|
||||||
|
|
||||||
// get customer
|
// get customer
|
||||||
$json_result = Customers::getLocal($admin_userdata, array(
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
'loginname' => 'test1'
|
'loginname' => 'test1'
|
||||||
))->get();
|
))->get();
|
||||||
$customer_userdata = json_decode($json_result, true)['data'];
|
$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()
|
||||||
|
{
|
||||||
|
global $admin_userdata;
|
||||||
|
|
||||||
|
// get customer
|
||||||
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
|
'loginname' => 'test1'
|
||||||
|
))->get();
|
||||||
|
$customer_userdata = json_decode($json_result, true)['data'];
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'emailaddr' => 'info@test2.local',
|
'emailaddr' => 'info@test2.local',
|
||||||
'destination' => 'info@test2.local'
|
'destination' => 'info@test2.local'
|
||||||
@@ -201,18 +232,19 @@ class MailsTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* @depends testCustomerEmailForwardersAdd
|
* @depends testCustomerEmailForwardersAdd
|
||||||
*/
|
*/
|
||||||
public function testCustomerEmailForwardersAddExistingAsDestination()
|
public function testCustomerEmailForwardersAddExistingAsDestination()
|
||||||
{
|
{
|
||||||
global $admin_userdata;
|
global $admin_userdata;
|
||||||
|
|
||||||
// get customer
|
// get customer
|
||||||
$json_result = Customers::getLocal($admin_userdata, array(
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
'loginname' => 'test1'
|
'loginname' => 'test1'
|
||||||
))->get();
|
))->get();
|
||||||
$customer_userdata = json_decode($json_result, true)['data'];
|
$customer_userdata = json_decode($json_result, true)['data'];
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'emailaddr' => 'info@test2.local',
|
'emailaddr' => 'info@test2.local',
|
||||||
'destination' => 'other@domain.tld'
|
'destination' => 'other@domain.tld'
|
||||||
@@ -224,13 +256,13 @@ class MailsTest extends TestCase
|
|||||||
public function testCustomerEmailForwardersAddInvalid()
|
public function testCustomerEmailForwardersAddInvalid()
|
||||||
{
|
{
|
||||||
global $admin_userdata;
|
global $admin_userdata;
|
||||||
|
|
||||||
// get customer
|
// get customer
|
||||||
$json_result = Customers::getLocal($admin_userdata, array(
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
'loginname' => 'test1'
|
'loginname' => 'test1'
|
||||||
))->get();
|
))->get();
|
||||||
$customer_userdata = json_decode($json_result, true)['data'];
|
$customer_userdata = json_decode($json_result, true)['data'];
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'emailaddr' => 'info@test2.local',
|
'emailaddr' => 'info@test2.local',
|
||||||
'destination' => '@domain.com'
|
'destination' => '@domain.com'
|
||||||
@@ -261,18 +293,19 @@ class MailsTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* @depends testCustomerEmailForwardersAddAnother
|
* @depends testCustomerEmailForwardersAddAnother
|
||||||
*/
|
*/
|
||||||
public function testCustomerEmailForwardersDelete()
|
public function testCustomerEmailForwardersDelete()
|
||||||
{
|
{
|
||||||
global $admin_userdata;
|
global $admin_userdata;
|
||||||
|
|
||||||
// get customer
|
// get customer
|
||||||
$json_result = Customers::getLocal($admin_userdata, array(
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
'loginname' => 'test1'
|
'loginname' => 'test1'
|
||||||
))->get();
|
))->get();
|
||||||
$customer_userdata = json_decode($json_result, true)['data'];
|
$customer_userdata = json_decode($json_result, true)['data'];
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'emailaddr' => 'info@test2.local',
|
'emailaddr' => 'info@test2.local',
|
||||||
'forwarderid' => 1
|
'forwarderid' => 1
|
||||||
@@ -283,18 +316,19 @@ class MailsTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* @depends testCustomerEmailForwardersAddAnother
|
* @depends testCustomerEmailForwardersAddAnother
|
||||||
*/
|
*/
|
||||||
public function testCustomerEmailForwardersDeleteUnknown()
|
public function testCustomerEmailForwardersDeleteUnknown()
|
||||||
{
|
{
|
||||||
global $admin_userdata;
|
global $admin_userdata;
|
||||||
|
|
||||||
// get customer
|
// get customer
|
||||||
$json_result = Customers::getLocal($admin_userdata, array(
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
'loginname' => 'test1'
|
'loginname' => 'test1'
|
||||||
))->get();
|
))->get();
|
||||||
$customer_userdata = json_decode($json_result, true)['data'];
|
$customer_userdata = json_decode($json_result, true)['data'];
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'emailaddr' => 'info@test2.local',
|
'emailaddr' => 'info@test2.local',
|
||||||
'forwarderid' => 1337
|
'forwarderid' => 1337
|
||||||
@@ -307,7 +341,7 @@ class MailsTest extends TestCase
|
|||||||
public function testCustomerEmailsListing()
|
public function testCustomerEmailsListing()
|
||||||
{
|
{
|
||||||
global $admin_userdata;
|
global $admin_userdata;
|
||||||
|
|
||||||
Settings::Set('panel.customer_hide_options', '', true);
|
Settings::Set('panel.customer_hide_options', '', true);
|
||||||
|
|
||||||
// get customer
|
// get customer
|
||||||
@@ -326,14 +360,14 @@ class MailsTest extends TestCase
|
|||||||
public function testCustomerEmailAccountsAdd()
|
public function testCustomerEmailAccountsAdd()
|
||||||
{
|
{
|
||||||
global $admin_userdata;
|
global $admin_userdata;
|
||||||
|
|
||||||
Settings::Set('panel.sendalternativemail', 1, true);
|
Settings::Set('panel.sendalternativemail', 1, true);
|
||||||
// get customer
|
// get customer
|
||||||
$json_result = Customers::getLocal($admin_userdata, array(
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
'loginname' => 'test1'
|
'loginname' => 'test1'
|
||||||
))->get();
|
))->get();
|
||||||
$customer_userdata = json_decode($json_result, true)['data'];
|
$customer_userdata = json_decode($json_result, true)['data'];
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'emailaddr' => 'info@test2.local',
|
'emailaddr' => 'info@test2.local',
|
||||||
'email_password' => generatePassword(),
|
'email_password' => generatePassword(),
|
||||||
@@ -348,13 +382,13 @@ class MailsTest extends TestCase
|
|||||||
public function testAdminEmailAccountsUpdate()
|
public function testAdminEmailAccountsUpdate()
|
||||||
{
|
{
|
||||||
global $admin_userdata;
|
global $admin_userdata;
|
||||||
|
|
||||||
// get customer
|
// get customer
|
||||||
$json_result = Customers::getLocal($admin_userdata, array(
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
'loginname' => 'test1'
|
'loginname' => 'test1'
|
||||||
))->get();
|
))->get();
|
||||||
$customer_userdata = json_decode($json_result, true)['data'];
|
$customer_userdata = json_decode($json_result, true)['data'];
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'emailaddr' => 'info@test2.local',
|
'emailaddr' => 'info@test2.local',
|
||||||
'email_password' => generatePassword(),
|
'email_password' => generatePassword(),
|
||||||
@@ -384,13 +418,13 @@ class MailsTest extends TestCase
|
|||||||
public function testCustomerEmailAccountsDelete()
|
public function testCustomerEmailAccountsDelete()
|
||||||
{
|
{
|
||||||
global $admin_userdata;
|
global $admin_userdata;
|
||||||
|
|
||||||
// get customer
|
// get customer
|
||||||
$json_result = Customers::getLocal($admin_userdata, array(
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
'loginname' => 'test1'
|
'loginname' => 'test1'
|
||||||
))->get();
|
))->get();
|
||||||
$customer_userdata = json_decode($json_result, true)['data'];
|
$customer_userdata = json_decode($json_result, true)['data'];
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'emailaddr' => 'info@test2.local',
|
'emailaddr' => 'info@test2.local',
|
||||||
'delete_userfiles' => 1
|
'delete_userfiles' => 1
|
||||||
@@ -403,17 +437,17 @@ class MailsTest extends TestCase
|
|||||||
public function testCustomerEmailsDelete()
|
public function testCustomerEmailsDelete()
|
||||||
{
|
{
|
||||||
global $admin_userdata;
|
global $admin_userdata;
|
||||||
|
|
||||||
// remove possible existing delete tasks
|
// remove possible existing delete tasks
|
||||||
Database::query("TRUNCATE `".TABLE_PANEL_TASKS."`");
|
Database::query("TRUNCATE `" . TABLE_PANEL_TASKS . "`");
|
||||||
|
|
||||||
Settings::Set('panel.sendalternativemail', 0, true);
|
Settings::Set('panel.sendalternativemail', 0, true);
|
||||||
// get customer
|
// get customer
|
||||||
$json_result = Customers::getLocal($admin_userdata, array(
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
'loginname' => 'test1'
|
'loginname' => 'test1'
|
||||||
))->get();
|
))->get();
|
||||||
$customer_userdata = json_decode($json_result, true)['data'];
|
$customer_userdata = json_decode($json_result, true)['data'];
|
||||||
|
|
||||||
// add account
|
// add account
|
||||||
$data = [
|
$data = [
|
||||||
'emailaddr' => 'info@test2.local',
|
'emailaddr' => 'info@test2.local',
|
||||||
@@ -423,7 +457,7 @@ class MailsTest extends TestCase
|
|||||||
$json_result = EmailAccounts::getLocal($customer_userdata, $data)->add();
|
$json_result = EmailAccounts::getLocal($customer_userdata, $data)->add();
|
||||||
$result = json_decode($json_result, true)['data'];
|
$result = json_decode($json_result, true)['data'];
|
||||||
$this->assertEquals(2, $result['popaccountid']);
|
$this->assertEquals(2, $result['popaccountid']);
|
||||||
|
|
||||||
// now delete the whole address
|
// now delete the whole address
|
||||||
$data = [
|
$data = [
|
||||||
'emailaddr' => 'info@test2.local',
|
'emailaddr' => 'info@test2.local',
|
||||||
|
|||||||
Reference in New Issue
Block a user