|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* ownCloud - Mail |
|
5
|
|
|
* |
|
6
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
7
|
|
|
* later. See the COPYING file. |
|
8
|
|
|
* |
|
9
|
|
|
* @author Christoph Wurst <[email protected]> |
|
10
|
|
|
* @copyright Christoph Wurst 2016 |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace OCA\Mail\Service\AutoCompletion; |
|
14
|
|
|
|
|
15
|
|
|
use Horde_Mail_Rfc822_Address; |
|
16
|
|
|
use OCA\Mail\Db\CollectedAddress; |
|
17
|
|
|
use OCA\Mail\Db\CollectedAddressMapper; |
|
18
|
|
|
use OCA\Mail\Service\Logger; |
|
19
|
|
|
|
|
20
|
|
|
class AddressCollector { |
|
21
|
|
|
|
|
22
|
|
|
/** @var CollectedAddressMapper */ |
|
23
|
|
|
private $mapper; |
|
24
|
|
|
|
|
25
|
|
|
/** @var string */ |
|
26
|
|
|
private $userId; |
|
27
|
|
|
|
|
28
|
|
|
/** @var Logger */ |
|
29
|
|
|
private $logger; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param CollectedAddressMapper $mapper |
|
33
|
|
|
* @param string $UserId |
|
34
|
|
|
* @param Logger $logger |
|
35
|
|
|
*/ |
|
36
|
3 |
|
public function __construct(CollectedAddressMapper $mapper, $UserId, Logger $logger) { |
|
37
|
3 |
|
$this->mapper = $mapper; |
|
38
|
3 |
|
$this->userId = $UserId; |
|
39
|
3 |
|
$this->logger = $logger; |
|
40
|
3 |
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Add a new email addresses |
|
44
|
|
|
* |
|
45
|
|
|
* Duplicates are ignored |
|
46
|
|
|
* |
|
47
|
|
|
* @param string[] $addresses |
|
48
|
|
|
*/ |
|
49
|
2 |
|
public function addAddresses($addresses) { |
|
50
|
2 |
|
$this->logger->debug("collecting " . count($addresses) . " email addresses"); |
|
51
|
2 |
|
foreach ($addresses as $address) { |
|
52
|
|
|
|
|
53
|
2 |
|
if (!$this->mapper->exists($this->userId, $address)) { |
|
54
|
1 |
|
$this->logger->debug("saving new address <$address>"); |
|
55
|
|
|
|
|
56
|
1 |
|
$entity = new CollectedAddress(); |
|
57
|
1 |
|
$entity->setUserId($this->userId); |
|
58
|
1 |
|
$entity->setEmail($address); |
|
59
|
1 |
|
$this->mapper->insert($entity); |
|
60
|
1 |
|
} |
|
61
|
2 |
|
} |
|
62
|
2 |
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Find and return all known and matching email addresses |
|
66
|
|
|
* |
|
67
|
|
|
* @param Horde_Mail_Rfc822_Address[] $term |
|
68
|
|
|
* @param string $UserId |
|
|
|
|
|
|
69
|
|
|
*/ |
|
70
|
1 |
|
public function searchAddress($term) { |
|
71
|
1 |
|
$this->logger->debug("searching for collected address <$term>"); |
|
72
|
1 |
|
$result = $this->mapper->findMatching($this->userId, $term); |
|
73
|
1 |
|
$this->logger->debug("found " . count($result) . " matches in collected addresses"); |
|
74
|
1 |
|
return $result; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|
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
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.