Completed
Pull Request — master (#1559)
by Christoph
09:17
created

Config::getImapHost()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * @author Christoph Wurst <[email protected]>
5
 *
6
 * ownCloud - 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\DefaultAccount;
23
24
use OCP\IUser;
25
26
class Config {
27
28
	private $data;
29
30
	/**
31
	 * @param array $data
32
	 */
33
	public function __construct($data) {
34
		$this->data = $data;
35
	}
36
37
	/**
38
	 * @param IUser $user
39
	 * @return string
40
	 */
41
	public function buildEmail(IUser $user) {
42
		return $this->buildUserEmail($this->data['email'], $user);
43
	}
44
45
	/**
46
	 * @return string
47
	 */
48
	public function getImapHost() {
49
		return $this->data['imapHost'];
50
	}
51
52
	/**
53
	 * @return string|int
54
	 */
55
	public function getImapPort() {
56
		return $this->data['imapPort'];
57
	}
58
59
	/**
60
	 * @return string
61
	 */
62
	public function buildImapUser(IUser $user) {
63
		if (isset($this->data['imapUser'])) {
64
			return $this->buildUserEmail($this->data['imapUser'], $user);
65
		}
66
		return $this->buildEmail($user);
67
	}
68
69
	/**
70
	 * @return string
71
	 */
72
	public function getImapSslMode() {
73
		return $this->data['imapSslMode'];
74
	}
75
76
	/**
77
	 * @return string
78
	 */
79
	public function getSmtpHost() {
80
		return $this->data['smtpHost'];
81
	}
82
83
	/**
84
	 * @return string|int
85
	 */
86
	public function getSmtpPort() {
87
		return $this->data['smtpPort'];
88
	}
89
90
	/**
91
	 * @param IUser $user
92
	 * @return string
93
	 */
94
	public function buildSmtpUser(IUser $user) {
95
		if (isset($this->data['smtpUser'])) {
96
			return $this->buildUserEmail($this->data['smtpUser'], $user);
97
		}
98
		return $this->buildEmail($user);
99
	}
100
101
	/**
102
	 * @return string
103
	 */
104
	public function getSmtpSslMode() {
105
		return $this->data['smtpSslMode'];
106
	}
107
108
	/**
109
	 * Replace %USERID% and %EMAIL% to allow special configurations
110
	 *
111
	 * @param string $original
112
	 * @param IUser $user
113
	 * @return string
114
	 */
115
	private function buildUserEmail($original, IUser $user) {
116
		$original = str_replace('%USERID%', $user->getUID(), $original);
117
		if (!is_null($user->getEMailAddress())) {
118
			$original = str_replace('%EMAIL%', $user->getEMailAddress(), $original);
119
		}
120
121
		return $original;
122
	}
123
124
}
125