diff --git a/lib/private/mail.php b/lib/private/mail.php index 8ba7343e01..6b7eec6e08 100644 --- a/lib/private/mail.php +++ b/lib/private/mail.php @@ -126,6 +126,9 @@ class OC_Mail { * @return bool */ public static function validateAddress($emailAddress) { + if (strpos($emailAddress, '@') === false) { + return false; + } $emailAddress = self::buildAsciiEmail($emailAddress); return PHPMailer::ValidateAddress($emailAddress); } diff --git a/tests/lib/mail.php b/tests/lib/mail.php index 568ecff52b..813dde1944 100644 --- a/tests/lib/mail.php +++ b/tests/lib/mail.php @@ -8,28 +8,23 @@ class Test_Mail extends \Test\TestCase { - protected function setUp() - { - parent::setUp(); - - if (!function_exists('idn_to_ascii')) { - $this->markTestSkipped( - 'The intl extension is not available.' - ); - } - } - /** * @dataProvider buildAsciiEmailProvider * @param $expected * @param $address */ public function testBuildAsciiEmail($expected, $address) { + if (!function_exists('idn_to_ascii')) { + $this->markTestSkipped( + 'The intl extension is not available.' + ); + } + $actual = \OC_Mail::buildAsciiEmail($address); $this->assertEquals($expected, $actual); } - function buildAsciiEmailProvider() { + public function buildAsciiEmailProvider() { return array( array('info@example.com', 'info@example.com'), array('info@xn--cjr6vy5ejyai80u.com', 'info@國際化域名.com'), @@ -38,4 +33,21 @@ class Test_Mail extends \Test\TestCase { ); } + public function validateMailProvider() { + return array( + array('infoatexample.com', false), + array('info', false), + ); + } + + /** + * @dataProvider validateMailProvider + * @param $address + * @param $expected + */ + public function testValidateEmail($address, $expected) { + $actual = \OC_Mail::validateAddress($address); + $this->assertEquals($expected, $actual); + } + }