blob: b301e79d4926587d35db5a448eb6d3e6d811f919 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
<?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;
}
}
|