Fix undefined offset 1 for wrong user mail address

* fixes Undefined offset: 1 at lib/private/mail.php#143
This commit is contained in:
Morris Jobke 2015-01-22 15:17:29 +01:00
parent b5b491d1bb
commit 3d42ecea37
2 changed files with 27 additions and 12 deletions

View File

@ -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);
}

View File

@ -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);
}
}