1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @author Christoph Wurst <[email protected]> |
5
|
|
|
* |
6
|
|
|
* ownCloud - Mail |
7
|
|
|
* |
8
|
|
|
* This code is free software: you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
10
|
|
|
* as published by the Free Software Foundation. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU Affero General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
19
|
|
|
* |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace OCA\Mail\Service\AutoConfig; |
23
|
|
|
|
24
|
|
|
use Exception; |
25
|
|
|
use OCA\Mail\Service\Logger; |
26
|
|
|
|
27
|
|
|
class IspDb { |
28
|
|
|
|
29
|
|
|
/** @var Logger */ |
30
|
|
|
private $logger; |
31
|
|
|
|
32
|
|
|
/** @var string[] */ |
33
|
2 |
|
public function getUrls() { |
34
|
|
|
return [ |
35
|
2 |
|
'https://autoconfig.{DOMAIN}/mail/config-v1.1.xml', |
36
|
2 |
|
'https://{DOMAIN}/.well-known/autoconfig/mail/config-v1.1.xml', |
37
|
2 |
|
'https://autoconfig.thunderbird.net/v1.1/{DOMAIN}', |
38
|
2 |
|
]; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param Logger $logger |
43
|
|
|
* @param string[] $ispUrls |
|
|
|
|
44
|
|
|
*/ |
45
|
3 |
|
public function __construct(Logger $logger) { |
46
|
3 |
|
$this->logger = $logger; |
47
|
3 |
|
} |
48
|
|
|
|
49
|
3 |
|
private function queryUrl($url) { |
50
|
|
|
try { |
51
|
3 |
|
$xml = @simplexml_load_file($url); |
52
|
3 |
|
if (libxml_get_last_error() !== False || !is_object($xml) || !$xml->emailProvider) { |
53
|
2 |
|
libxml_clear_errors(); |
54
|
2 |
|
return []; |
55
|
|
|
} |
56
|
|
|
$provider = [ |
57
|
3 |
|
'displayName' => (string) $xml->emailProvider->displayName, |
58
|
3 |
|
]; |
59
|
3 |
|
foreach ($xml->emailProvider->children() as $tag => $server) { |
60
|
3 |
|
if (!in_array($tag, ['incomingServer', 'outgoingServer'])) { |
61
|
3 |
|
continue; |
62
|
|
|
} |
63
|
3 |
|
foreach ($server->attributes() as $name => $value) { |
64
|
3 |
|
if ($name == 'type') { |
65
|
3 |
|
$type = (string) $value; |
66
|
3 |
|
} |
67
|
3 |
|
} |
68
|
3 |
|
$data = []; |
69
|
3 |
|
foreach ($server as $name => $value) { |
70
|
3 |
|
foreach ($value->children() as $tag => $val) { |
71
|
2 |
|
$data[$name][$tag] = (string) $val; |
72
|
3 |
|
} |
73
|
3 |
|
if (!isset($data[$name])) { |
74
|
3 |
|
$data[$name] = (string) $value; |
75
|
3 |
|
} |
76
|
3 |
|
} |
77
|
3 |
|
$provider[$type][] = $data; |
|
|
|
|
78
|
3 |
|
} |
79
|
3 |
|
} catch (Exception $e) { |
80
|
|
|
// ignore own not-found exception or xml parsing exceptions |
81
|
|
|
unset($e); |
82
|
|
|
$provider = []; |
83
|
|
|
} |
84
|
3 |
|
return $provider; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param string $domain |
89
|
|
|
* @return array |
90
|
|
|
*/ |
91
|
3 |
|
public function query($domain, $tryMx = true) { |
92
|
3 |
|
$this->logger->debug("IsbDb: querying <$domain>"); |
93
|
3 |
|
if (strpos($domain, '@') !== false) { |
94
|
|
|
// TODO: use horde mail address parsing instead |
95
|
|
|
list(, $domain) = explode('@', $domain); |
96
|
|
|
} |
97
|
|
|
|
98
|
3 |
|
$provider = []; |
99
|
3 |
|
foreach ($this->getUrls() as $url) { |
100
|
3 |
|
$url = str_replace("{DOMAIN}", $domain, $url); |
101
|
3 |
|
$this->logger->debug("IsbDb: querying <$domain> via <$url>"); |
102
|
|
|
|
103
|
3 |
|
$provider = $this->queryUrl($url); |
104
|
3 |
|
if (!empty($provider)) { |
105
|
3 |
|
return $provider; |
106
|
|
|
} |
107
|
2 |
|
} |
108
|
|
|
|
109
|
|
|
if ($tryMx && ($dns = dns_get_record($domain, DNS_MX))) { |
110
|
|
|
$domain = $dns[0]['target']; |
111
|
|
|
if (!($provider = $this->query($domain, false))) { |
112
|
|
|
list(, $domain) = explode('.', $domain, 2); |
113
|
|
|
$provider = $this->query($domain, false); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
return $provider; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
} |
120
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.