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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
<?php
declare(strict_types=1);
/**
* @copyright 2021 Anna Larch <anna@nextcloud.com>
*
* @author 2021 Anna Larch <anna@nextcloud.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace OCA\Mail\Db;
use JsonSerializable;
use OCP\AppFramework\Db\Entity;
use OCP\IUser;
use ReturnTypeWillChange;
/**
* @method string getProvisioningDomain()
* @method void setProvisioningDomain(string $provisioningDomain)
* @method string getEmailTemplate()
* @method void setEmailTemplate(string $emailTemplate)
* @method string getImapUser()
* @method void setImapUser(string $imapUser)
* @method string getImapHost()
* @method void setImapHost(string $imapHost)
* @method int getImapPort()
* @method void setImapPort(int $imapPort)
* @method string getImapSslMode()
* @method void setImapSslMode(string $imapSslMode)
* @method string getSmtpUser()
* @method void setSmtpUser(string $smtpUser)
* @method string getSmtpHost()
* @method void setSmtpHost(string $smtpHost)
* @method int getSmtpPort()
* @method void setSmtpPort(int $smtpPort)
* @method string getSmtpSslMode()
* @method void setSmtpSslMode(string $smtpSslMode)
* @method bool|null getSieveEnabled()
* @method void setSieveEnabled(bool $sieveEnabled)
* @method string|null getSieveHost()
* @method void setSieveHost(?string $sieveHost)
* @method int|null getSievePort()
* @method void setSievePort(?int $sievePort)
* @method string|null getSieveSslMode()
* @method void setSieveSslMode(?string $sieveSslMode)
* @method string|null getSieveUser()
* @method void setSieveUser(?string $sieveUser)
* @method array getAliases()
* @method void setAliases(array $aliases)
* @method bool getLdapAliasesProvisioning()
* @method void setLdapAliasesProvisioning(bool $ldapAliasesProvisioning)
* @method string|null getLdapAliasesAttribute()
* @method void setLdapAliasesAttribute(?string $ldapAliasesAttribute)
*/
class Provisioning extends Entity implements JsonSerializable {
public const WILDCARD = '*';
protected $provisioningDomain;
protected $emailTemplate;
protected $imapUser;
protected $imapHost;
protected $imapPort;
protected $imapSslMode;
protected $smtpUser;
protected $smtpHost;
protected $smtpPort;
protected $smtpSslMode;
protected $sieveEnabled;
protected $sieveUser;
protected $sieveHost;
protected $sievePort;
protected $sieveSslMode;
protected $aliases = [];
protected $ldapAliasesProvisioning;
protected $ldapAliasesAttribute;
public function __construct() {
$this->addType('imapPort', 'integer');
$this->addType('smtpPort', 'integer');
$this->addType('sieveEnabled', 'boolean');
$this->addType('sievePort', 'integer');
$this->addType('ldapAliasesProvisioning', 'boolean');
}
#[ReturnTypeWillChange]
public function jsonSerialize() {
return [
'id' => $this->getId(),
'provisioningDomain' => $this->getProvisioningDomain(),
'emailTemplate' => $this->getEmailTemplate(),
'imapUser' => $this->getImapUser(),
'imapHost' => $this->getImapHost(),
'imapPort' => $this->getImapPort(),
'imapSslMode' => $this->getImapSslMode(),
'smtpUser' => $this->getSmtpUser(),
'smtpHost' => $this->getSmtpHost(),
'smtpPort' => $this->getSmtpPort(),
'smtpSslMode' => $this->getSmtpSslMode(),
'sieveEnabled' => $this->getSieveEnabled(),
'sieveUser' => $this->getSieveUser(),
'sieveHost' => $this->getSieveHost(),
'sievePort' => $this->getSievePort(),
'sieveSslMode' => $this->getSieveSslMode(),
'aliases' => $this->getAliases(),
'ldapAliasesProvisioning' => $this->getLdapAliasesProvisioning(),
'ldapAliasesAttribute' => $this->getLdapAliasesAttribute(),
];
}
/**
* @return string
*/
public function buildImapUser(IUser $user) {
if (!is_null($this->getImapUser())) {
return $this->buildUserEmail($this->getImapUser(), $user);
}
return $this->buildEmail($user);
}
/**
* @param IUser $user
* @return string
*/
public function buildEmail(IUser $user) {
return $this->buildUserEmail($this->getEmailTemplate(), $user);
}
/**
* Replace %USERID% and %EMAIL% to allow special configurations
*
* @param string $original
* @param IUser $user
* @return string
*/
private function buildUserEmail(string $original, IUser $user) {
if ($user->getUID() !== null) {
$original = str_replace('%USERID%', $user->getUID(), $original);
}
if ($user->getEMailAddress() !== null) {
$original = str_replace('%EMAIL%', $user->getEMailAddress(), $original);
}
return $original;
}
/**
* @param IUser $user
* @return string
*/
public function buildSmtpUser(IUser $user) {
if (!is_null($this->getSmtpUser())) {
return $this->buildUserEmail($this->getSmtpUser(), $user);
}
return $this->buildEmail($user);
}
/**
* @param IUser $user
* @return string
*/
public function buildSieveUser(IUser $user) {
if (!is_null($this->getSieveUser())) {
return $this->buildUserEmail($this->getSieveUser(), $user);
}
return $this->buildEmail($user);
}
}
|