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