parent
283476a2f7
commit
f92f3a1a6e
@ -1,45 +0,0 @@ |
||||
<?php |
||||
/** |
||||
* Copyright (c) 2014-2015 Lukas Reschke <lukas@owncloud.com> |
||||
* This file is licensed under the Affero General Public License version 3 or |
||||
* later. |
||||
* See the COPYING-README file. |
||||
*/ |
||||
|
||||
namespace OC\Mail; |
||||
|
||||
/** |
||||
* Class Util |
||||
* |
||||
* @package OC\Mail |
||||
*/ |
||||
class Util { |
||||
/** |
||||
* Checks if an e-mail address is valid |
||||
* |
||||
* @param string $email Email address to be validated |
||||
* @return bool True if the mail address is valid, false otherwise |
||||
*/ |
||||
public static function validateMailAddress($email) { |
||||
return \Swift_Validate::email(self::convertEmail($email)); |
||||
} |
||||
|
||||
/** |
||||
* SwiftMailer does currently not work with IDN domains, this function therefore converts the domains |
||||
* |
||||
* FIXME: Remove this once SwiftMailer supports IDN |
||||
* |
||||
* @param string $email |
||||
* @return string Converted mail address if `idn_to_ascii` exists |
||||
*/ |
||||
protected static function convertEmail($email) { |
||||
if (!function_exists('idn_to_ascii') || strpos($email, '@') === false) { |
||||
return $email; |
||||
} |
||||
|
||||
list($name, $domain) = explode('@', $email, 2); |
||||
$domain = idn_to_ascii($domain); |
||||
return $name.'@'.$domain; |
||||
} |
||||
|
||||
} |
||||
@ -1,26 +0,0 @@ |
||||
<?php |
||||
/** |
||||
* Copyright (c) 2014 Lukas Reschke <lukas@owncloud.com> |
||||
* This file is licensed under the Affero General Public License version 3 or |
||||
* later. |
||||
* See the COPYING-README file. |
||||
*/ |
||||
|
||||
namespace OCP\Mail; |
||||
|
||||
/** |
||||
* Class Util provides some helpers for mail addresses |
||||
* |
||||
* @package OCP\Mail |
||||
*/ |
||||
class Util { |
||||
/** |
||||
* Checks if an e-mail address is valid |
||||
* |
||||
* @param string $email Email address to be validated |
||||
* @return bool True if the mail address is valid, false otherwise |
||||
*/ |
||||
public static function validateMailAddress($email) { |
||||
return \OC\Mail\Util::validateMailAddress($email); |
||||
} |
||||
} |
||||
@ -1,39 +0,0 @@ |
||||
<?php |
||||
/** |
||||
* Copyright (c) 2014 Lukas Reschke <lukas@owncloud.com> |
||||
* This file is licensed under the Affero General Public License version 3 or |
||||
* later. |
||||
* See the COPYING-README file. |
||||
*/ |
||||
|
||||
namespace Test; |
||||
use OCP\Mail\Util; |
||||
|
||||
/** |
||||
* Class Util |
||||
* |
||||
* @package OC\Mail |
||||
*/ |
||||
class UtilTest extends TestCase { |
||||
|
||||
/** |
||||
* @return array |
||||
*/ |
||||
public function mailAddressProvider() { |
||||
return array( |
||||
array('lukas@owncloud.com', true), |
||||
array('lukas@localhost', true), |
||||
array('lukas@192.168.1.1', true), |
||||
array('lukas@éxämplè.com', true), |
||||
array('asdf', false), |
||||
array('lukas@owncloud.org@owncloud.com', false) |
||||
); |
||||
} |
||||
|
||||
/** |
||||
* @dataProvider mailAddressProvider |
||||
*/ |
||||
public function testValidateMailAddress($email, $expected) { |
||||
$this->assertSame($expected, Util::validateMailAddress($email)); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue