<?php
/**
- * Copyright (c) 2014 Lukas Reschke <lukas@owncloud.com>
+ * 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.
return $failedRecipients;
}
+ /**
+ * 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 function validateMailAddress($email) {
+ return \Swift_Validate::email($this->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 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;
+ }
+
/**
* Returns whatever transport is configured within the config
*
+++ /dev/null
-<?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;
- }
-
-}
* has been supplied.)
*/
public function send(Message $message);
+
+ /**
+ * 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 function validateMailAddress($email);
}
+++ /dev/null
-<?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);
- }
-}
$host_name = \OC_Config::getValue('mail_domain', $host_name);
$defaultEmailAddress = $user_part.'@'.$host_name;
- if (\OCP\Mail\Util::validateMailAddress($defaultEmailAddress)) {
+ $mailer = \OC::$server->getMailer();
+ if ($mailer->validateMailAddress($defaultEmailAddress)) {
return $defaultEmailAddress;
}
* @return DataResponse
*/
public function create($username, $password, array $groups=array(), $email='') {
-
- if($email !== '' && !\OCP\Mail\Util::validateMailAddress($email)) {
+ if($email !== '' && !$this->mailer->validateMailAddress($email)) {
return new DataResponse(
array(
'message' => (string)$this->l10n->t('Invalid mail address')
);
}
- if($mailAddress !== '' && ! \OCP\Mail\Util::validateMailAddress($mailAddress)) {
+ if($mailAddress !== '' && !$this->mailer->validateMailAddress($mailAddress)) {
return new DataResponse(
array(
'status' => 'error',
<?php
/**
- * Copyright (c) 2014 Lukas Reschke <lukas@owncloud.com>
+ * 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.
$this->mailer->send($message);
}
+ /**
+ * @return array
+ */
+ public function mailAddressProvider() {
+ return [
+ ['lukas@owncloud.com', true],
+ ['lukas@localhost', true],
+ ['lukas@192.168.1.1', true],
+ ['lukas@éxämplè.com', true],
+ ['asdf', false],
+ ['lukas@owncloud.org@owncloud.com', false],
+ ];
+ }
+
+ /**
+ * @dataProvider mailAddressProvider
+ */
+ public function testValidateMailAddress($email, $expected) {
+ $this->assertSame($expected, $this->mailer->validateMailAddress($email));
+ }
+
}
+++ /dev/null
-<?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));
- }
-}