-
Notifications
You must be signed in to change notification settings - Fork 316
Expand file tree
/
Copy pathAliasesService.php
More file actions
144 lines (122 loc) Β· 3.59 KB
/
AliasesService.php
File metadata and controls
144 lines (122 loc) Β· 3.59 KB
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
143
144
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Mail\Service;
use OCA\Mail\Db\Alias;
use OCA\Mail\Db\AliasMapper;
use OCA\Mail\Db\MailAccountMapper;
use OCA\Mail\Exception\ClientException;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\IConfig;
class AliasesService {
/** @var AliasMapper */
private $aliasMapper;
/** @var MailAccountMapper */
private $mailAccountMapper;
/** @var IConfig */
private $config;
public function __construct(AliasMapper $aliasMapper, MailAccountMapper $mailAccountMapper, IConfig $config) {
$this->aliasMapper = $aliasMapper;
$this->mailAccountMapper = $mailAccountMapper;
$this->config = $config;
}
/**
* @param int $accountId
* @param String $currentUserId
* @return list<Alias>
*/
public function findAll(int $accountId, string $currentUserId): array {
return $this->aliasMapper->findAll($accountId, $currentUserId);
}
/**
* @param int $aliasId
* @param string $currentUserId
* @return Alias
* @throws DoesNotExistException
*/
public function find(int $aliasId, string $currentUserId): Alias {
return $this->aliasMapper->find($aliasId, $currentUserId);
}
/**
* @param string $aliasEmail
* @param string $userId
* @return Alias
* @throws DoesNotExistException
*/
public function findByAliasAndUserId(string $aliasEmail, string $userId): Alias {
return $this->aliasMapper->findByAlias($aliasEmail, $userId);
}
/**
* @param string $userId
* @param int $accountId
* @param string $alias
* @param string $aliasName
*
* @return Alias
* @throws DoesNotExistException
*/
public function create(string $userId, int $accountId, string $alias, string $aliasName): Alias {
if ($this->config->getAppValue('mail', 'allow_new_mail_aliases', 'yes') === 'no') {
throw new ClientException('Creating aliases has been disabled by the administrator.');
}
$this->mailAccountMapper->find($userId, $accountId);
$aliasEntity = new Alias();
$aliasEntity->setAccountId($accountId);
$aliasEntity->setAlias($alias);
$aliasEntity->setName($aliasName);
return $this->aliasMapper->insert($aliasEntity);
}
/**
* @throws ClientException
* @throws DoesNotExistException
*/
public function delete(string $userId, int $aliasId): Alias {
$entity = $this->aliasMapper->find($aliasId, $userId);
if ($entity->isProvisioned()) {
throw new ClientException('Deleting a provisioned alias is not allowed.');
}
return $this->aliasMapper->delete($entity);
}
/**
* Deletes all aliases of an account.
*
* @param int $accountId the account which aliases will be deleted
*
* @return void
*/
public function deleteAll($accountId): void {
$this->aliasMapper->deleteAll($accountId);
}
/**
* Update alias and name
*
* @throws DoesNotExistException
*/
public function update(string $userId,
int $aliasId,
string $alias,
string $aliasName,
?int $smimeCertificateId): Alias {
$entity = $this->aliasMapper->find($aliasId, $userId);
if (!$entity->isProvisioned()) {
$entity->setAlias($alias);
}
$entity->setName($aliasName);
$entity->setSmimeCertificateId($smimeCertificateId);
return $this->aliasMapper->update($entity);
}
/**
* Update signature for alias
*
* @throws DoesNotExistException
*/
public function updateSignature(string $userId, int $aliasId, ?string $signature = null): Alias {
$entity = $this->find($aliasId, $userId);
$entity->setSignature($signature);
return $this->aliasMapper->update($entity);
}
}