]> source.dussan.org Git - nextcloud-server.git/commitdiff
Incorporate review changes
authorLukas Reschke <lukas@owncloud.com>
Thu, 19 Feb 2015 17:55:27 +0000 (18:55 +0100)
committerLukas Reschke <lukas@owncloud.com>
Mon, 16 Mar 2015 11:47:05 +0000 (12:47 +0100)
lib/private/mail/mailer.php
lib/private/mail/util.php [deleted file]
lib/public/mail/imailer.php
lib/public/mail/util.php [deleted file]
lib/public/util.php
settings/controller/userscontroller.php
tests/lib/mail/mailer.php
tests/lib/mail/util.php [deleted file]

index ff4b0a0ef624218ed738c5fb1fb99a35affe6ed1..92e6b91ce1c6511d05c6bc72db0592617ef99709 100644 (file)
@@ -1,6 +1,6 @@
 <?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.
@@ -77,6 +77,34 @@ class Mailer implements IMailer {
                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
         *
diff --git a/lib/private/mail/util.php b/lib/private/mail/util.php
deleted file mode 100644 (file)
index b301e79..0000000
+++ /dev/null
@@ -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;
-       }
-
-}
index 2a20ead612b946aed0860acb39ea65e8b83dab54..dc6fe5ba869248b3965b6c823fe9ad9fd44d0d94 100644 (file)
@@ -46,4 +46,12 @@ interface IMailer {
         * 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);
 }
diff --git a/lib/public/mail/util.php b/lib/public/mail/util.php
deleted file mode 100644 (file)
index ea59649..0000000
+++ /dev/null
@@ -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);
-       }
-}
index 71ab8cabce58b901288a0edead8a01dc33ef11ea..338c216f255f745fe566cf7735c7c25b7be64765 100644 (file)
@@ -294,7 +294,8 @@ class Util {
                $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;
                }
 
index 507e57ef940384557d13ab47bbd7f963412aa42b..11afe5140164d118a52bac355ce6616f2d947638 100644 (file)
@@ -263,8 +263,7 @@ class UsersController extends Controller {
         * @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')
@@ -443,7 +442,7 @@ class UsersController extends Controller {
                        );
                }
 
-               if($mailAddress !== '' && ! \OCP\Mail\Util::validateMailAddress($mailAddress)) {
+               if($mailAddress !== '' && !$this->mailer->validateMailAddress($mailAddress)) {
                        return new DataResponse(
                                array(
                                        'status' => 'error',
index bd410dd3383a22415a3867d89dec2682bce04ed9..2cb4c5cfde352142061744d9dcee516e747f91dc 100644 (file)
@@ -1,6 +1,6 @@
 <?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.
@@ -115,4 +115,25 @@ class MailerTest extends TestCase {
                $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));
+       }
+
 }
diff --git a/tests/lib/mail/util.php b/tests/lib/mail/util.php
deleted file mode 100644 (file)
index 04d9d5d..0000000
+++ /dev/null
@@ -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));
-       }
-}