-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathParser.php
142 lines (131 loc) · 4.31 KB
/
Parser.php
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
/*
* This file is part of the Yoozi Golem package.
*
* (c) Yoozi Inc. <hello@yoozi.cn>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Yoozi\Email\Address;
/**
* Email address parser.
*
* @author Saturn HU <yangg.hu@yoozi.cn>
*/
class Parser
{
/**
* A list of common used email providers.
*
* @var array
*/
public static $providers = array(
'126.com' => 'http://www.126.com',
'139.com' => 'http://mail.139.com',
'163.com' => 'http://www.163.com',
'188.com' => 'http://www.188.com/',
'189.cn' => 'http://mail.189.cn/',
'21cn.com' => 'http://mail.21cn.com',
'2980.com' => 'http://www.2980.com/',
'aim.com' => 'http://webmail.aol.com/?offerId=aimmail-en-us',
'aliyun.com' => 'http://mail.aliyun.com/alimail/',
'aol.com' => 'http://webmail.aol.com',
'china.com' => 'http://mail.china.com/index.html',
'citiz.net' => 'http://www.citiz.net/cloudmail/',
'cntv.cn' => 'http://mail.china.com/index.html',
'eyou.com' => 'http://www.eyou.com',
'foxmail.com' => 'http://mail.qq.com/cgi-bin/loginpage',
'gmail.com' => 'http://mail.google.com',
'hexun.com' => 'http://mail.hexun.com',
'hotmail.com' => 'http://www.hotmail.com',
'icloud.com' => 'https://www.icloud.com/#mail',
'mail.com' => 'http://www.mail.com/int/',
'me.com' => 'https://www.icloud.com/#mail',
'msn.com' => 'https://accountservices.msn.com/',
'outlook.com' => 'http://www.outlook.com',
'qq.com' => 'http://mail.qq.com/cgi-bin/loginpage',
'renren.com' => 'http://mail.renren.com/',
'sina.cn' => 'http://mail.sina.cn',
'sina.com' => 'http://mail.sina.com',
'sogou.com' => 'http://mail.sogou.com/',
'sohu.com' => 'http://mail.sohu.com',
'tom.com' => 'http://mail.tom.com',
'vip.126.com' => 'http://vip.126.com',
'vip.163.com' => 'http://vip.163.com',
'vip.21cn.com' => 'http://vip.21cn.com',
'vip.citiz.net' => 'http://www.citiz.net/cloudmail/',
'vip.cntv.cn' => 'http://mail.china.com/index.html',
'vip.qq.com' => 'http://mail.qq.com/cgi-bin/loginpage',
'vip.sina.com' => 'http://vip.sina.com',
'vnet.citiz.net' => 'http://www.citiz.net/cloudmail/',
'wo.com.cn' => 'http://mail.wo.com.cn/mail/login.action',
'yahoo.com' => 'http://mail.yahoo.com',
'yeah.net' => 'http://www.yeah.net'
);
/**
* Holds the parsed segments.
*
* @var array
*/
protected $parts = array();
/**
* Create a new email address parser.
*
* @param array $providers
* @return void
*/
public function __construct(array $providers = array())
{
if ($providers) {
static::$providers = $providers;
}
}
/**
* Parse a email address, return the parsed parts.
*
* @param string $email
* @return array
*/
public function parse($email)
{
if (! filter_var($email, FILTER_VALIDATE_EMAIL)) {
throw new \InvalidArgumentException(
"\$email($email) is not a valid email address."
);
}
$email = strtolower($email);
list($local, $domain) = explode('@', $email);
$listed = isset(static::$providers[$domain]);
$url = $listed ? static::$providers[$domain] : 'http://mail.' . $domain;
return $this->parts = compact('email', 'local', 'domain', 'url', 'listed');
}
/**
* Get the list of providers.
*
* @return array
*/
public function getProviders()
{
return static::$providers;
}
/**
* The parsed result in array.
*
* @return array
*/
public function toArray()
{
return $this->parts;
}
/**
* The parsed result in json.
*
* @param int $options
* @return string
*/
public function toJson($options = 0)
{
return json_encode($this->parts, $options);
}
}