diff options
author | Lukas Reschke <lukas@owncloud.com> | 2015-02-19 18:55:27 +0100 |
---|---|---|
committer | Lukas Reschke <lukas@owncloud.com> | 2015-03-16 12:47:05 +0100 |
commit | f92f3a1a6ecbce06fbe24204ef12b2eeeb0f0d15 (patch) | |
tree | dca224d1136cae6d5a971cd110a0591ce0d8d1ef /lib/private/mail/mailer.php | |
parent | 283476a2f7c200912352eb4db097f540e3993e75 (diff) | |
download | nextcloud-server-f92f3a1a6ecbce06fbe24204ef12b2eeeb0f0d15.tar.gz nextcloud-server-f92f3a1a6ecbce06fbe24204ef12b2eeeb0f0d15.zip |
Incorporate review changes
Diffstat (limited to 'lib/private/mail/mailer.php')
-rw-r--r-- | lib/private/mail/mailer.php | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/lib/private/mail/mailer.php b/lib/private/mail/mailer.php index ff4b0a0ef62..92e6b91ce1c 100644 --- a/lib/private/mail/mailer.php +++ b/lib/private/mail/mailer.php @@ -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. @@ -78,6 +78,34 @@ class Mailer implements IMailer { } /** + * 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 * * @return \Swift_SmtpTransport|\Swift_SendmailTransport|\Swift_MailTransport |