1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @author Christoph Wurst <[email protected]> |
5
|
|
|
* |
6
|
|
|
* 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\AutoCompletion; |
23
|
|
|
|
24
|
|
|
use Horde_Mail_Rfc822_Address; |
25
|
|
|
use OCA\Mail\Db\CollectedAddress; |
26
|
|
|
use OCA\Mail\Db\CollectedAddressMapper; |
27
|
|
|
use OCA\Mail\Service\Logger; |
28
|
|
|
|
29
|
|
|
class AddressCollector { |
30
|
|
|
|
31
|
|
|
/** @var CollectedAddressMapper */ |
32
|
|
|
private $mapper; |
33
|
|
|
|
34
|
|
|
/** @var string */ |
35
|
|
|
private $userId; |
36
|
|
|
|
37
|
|
|
/** @var Logger */ |
38
|
|
|
private $logger; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param CollectedAddressMapper $mapper |
42
|
|
|
* @param string $UserId |
43
|
|
|
* @param Logger $logger |
44
|
|
|
*/ |
45
|
3 |
|
public function __construct(CollectedAddressMapper $mapper, $UserId, Logger $logger) { |
46
|
3 |
|
$this->mapper = $mapper; |
47
|
3 |
|
$this->userId = $UserId; |
48
|
3 |
|
$this->logger = $logger; |
49
|
3 |
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Add a new email addresses |
53
|
|
|
* |
54
|
|
|
* Duplicates are ignored |
55
|
|
|
* |
56
|
|
|
* @param string[] $addresses |
57
|
|
|
*/ |
58
|
2 |
|
public function addAddresses($addresses) { |
59
|
2 |
|
$this->logger->debug("collecting " . count($addresses) . " email addresses"); |
60
|
2 |
|
foreach ($addresses as $address) { |
61
|
|
|
|
62
|
2 |
|
if (!$this->mapper->exists($this->userId, $address)) { |
63
|
1 |
|
$this->logger->debug("saving new address <$address>"); |
64
|
|
|
|
65
|
1 |
|
$entity = new CollectedAddress(); |
66
|
1 |
|
$entity->setUserId($this->userId); |
67
|
1 |
|
$entity->setEmail($address); |
68
|
1 |
|
$this->mapper->insert($entity); |
69
|
1 |
|
} |
70
|
2 |
|
} |
71
|
2 |
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Find and return all known and matching email addresses |
75
|
|
|
* |
76
|
|
|
* @param Horde_Mail_Rfc822_Address[] $term |
77
|
|
|
* @param string $UserId |
|
|
|
|
78
|
|
|
*/ |
79
|
1 |
|
public function searchAddress($term) { |
80
|
1 |
|
$this->logger->debug("searching for collected address <$term>"); |
81
|
1 |
|
$result = $this->mapper->findMatching($this->userId, $term); |
82
|
1 |
|
$this->logger->debug("found " . count($result) . " matches in collected addresses"); |
83
|
1 |
|
return $result; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
} |
87
|
|
|
|
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.