Skip to content

Commit 27bbb5b

Browse files
committed
Revert "feat: per account sieve debugging"
This reverts commit 5ba8dbc. Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
1 parent 6bf0776 commit 27bbb5b

File tree

4 files changed

+61
-40
lines changed

4 files changed

+61
-40
lines changed

lib/Controller/SieveController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
namespace OCA\Mail\Controller;
1111

1212
use Horde\ManageSieve\Exception as ManagesieveException;
13-
use OCA\Mail\Account;
1413
use OCA\Mail\AppInfo\Application;
1514
use OCA\Mail\Db\MailAccountMapper;
1615
use OCA\Mail\Exception\ClientException;
@@ -161,7 +160,7 @@ public function updateAccount(int $id,
161160
}
162161

163162
try {
164-
$this->sieveClientFactory->getClient(new Account($mailAccount));
163+
$this->sieveClientFactory->createClient($sieveHost, $sievePort, $sieveUser, $sievePassword, $sieveSslMode);
165164
} catch (ManagesieveException $e) {
166165
throw new CouldNotConnectException($e, 'ManageSieve', $sieveHost, $sievePort);
167166
}

lib/Sieve/SieveClientFactory.php

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public function __construct(ICrypto $crypto, IConfig $config) {
3333
}
3434

3535
/**
36+
* @param Account $account
37+
* @return ManageSieve
3638
* @throws ManageSieve\Exception
3739
*/
3840
public function getClient(Account $account): ManageSieve {
@@ -41,43 +43,59 @@ public function getClient(Account $account): ManageSieve {
4143
if (empty($user)) {
4244
$user = $account->getMailAccount()->getInboundUser();
4345
}
44-
4546
$password = $account->getMailAccount()->getSievePassword();
4647
if (empty($password)) {
4748
$password = $account->getMailAccount()->getInboundPassword();
4849
}
4950

50-
$sslMode = $account->getMailAccount()->getSieveSslMode();
51-
if (empty($sslMode)) {
52-
$sslMode = true;
53-
} elseif ($sslMode === 'none') {
54-
$sslMode = false;
55-
}
56-
57-
$params = [
58-
'host' => $account->getMailAccount()->getSieveHost(),
59-
'port' => $account->getMailAccount()->getSievePort(),
60-
'user' => $user,
61-
'password' => $this->crypto->decrypt($password),
62-
'secure' => $sslMode,
63-
'timeout' => $this->config->getSystemValueInt('app.mail.sieve.timeout', 5),
64-
'context' => [
65-
'ssl' => [
66-
'verify_peer' => $this->config->getSystemValueBool('app.mail.verify-tls-peer', true),
67-
'verify_peer_name' => $this->config->getSystemValueBool('app.mail.verify-tls-peer', true),
68-
]
69-
],
70-
];
71-
72-
if ($account->getDebug() || $this->config->getSystemValueBool('app.mail.debug')) {
73-
$fn = 'mail-' . $account->getUserId() . '-' . $account->getId() . '-sieve.log';
74-
$params['logger'] = new SieveLogger($this->config->getSystemValue('datadirectory') . '/' . $fn);
75-
}
76-
77-
$this->cache[$account->getId()] = new ManageSieve($params);
51+
$this->cache[$account->getId()] = $this->createClient(
52+
$account->getMailAccount()->getSieveHost(),
53+
$account->getMailAccount()->getSievePort(),
54+
$user,
55+
$password,
56+
$account->getMailAccount()->getSieveSslMode()
57+
);
7858
}
7959

8060
return $this->cache[$account->getId()];
8161
}
8262

63+
/**
64+
* @param string $host
65+
* @param int $port
66+
* @param string $user
67+
* @param string $password
68+
* @param string $sslMode
69+
* @return ManageSieve
70+
* @throws ManageSieve\Exception
71+
*/
72+
public function createClient(string $host, int $port, string $user, string $password, string $sslMode): ManageSieve {
73+
if (empty($sslMode)) {
74+
$sslMode = true;
75+
} elseif ($sslMode === 'none') {
76+
$sslMode = false;
77+
}
78+
79+
$params = [
80+
'host' => $host,
81+
'port' => $port,
82+
'user' => $user,
83+
'password' => $this->crypto->decrypt($password),
84+
'secure' => $sslMode,
85+
'timeout' => (int)$this->config->getSystemValue('app.mail.sieve.timeout', 5),
86+
'context' => [
87+
'ssl' => [
88+
'verify_peer' => $this->config->getSystemValueBool('app.mail.verify-tls-peer', true),
89+
'verify_peer_name' => $this->config->getSystemValueBool('app.mail.verify-tls-peer', true),
90+
91+
]
92+
],
93+
];
94+
95+
if ($this->config->getSystemValue('debug', false)) {
96+
$params['logger'] = new SieveLogger($this->config->getSystemValue('datadirectory') . '/horde_sieve.log');
97+
}
98+
99+
return new ManageSieve($params);
100+
}
83101
}

tests/Integration/Sieve/SieveClientFactoryTest.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,20 @@ protected function setUp(): void {
3535
$this->crypto = $this->createMock(ICrypto::class);
3636
$this->config = $this->createMock(IConfig::class);
3737

38-
$this->config->method('getSystemValueInt')
39-
->willReturnMap([
40-
['app.mail.sieve.timeout', 5, 5],
41-
]);
38+
$this->config->method('getSystemValue')
39+
->willReturnCallback(static function ($key, $default) {
40+
if ($key === 'app.mail.sieve.timeout') {
41+
return 5;
42+
}
43+
if ($key === 'debug') {
44+
return false;
45+
}
46+
return null;
47+
});
4248

4349
$this->config->method('getSystemValueBool')
44-
->willReturnMap([
45-
['app.mail.verify-tls-peer', true, false],
46-
['app.mail.debug', false, false],
47-
]);
50+
->with('app.mail.verify-tls-peer', true)
51+
->willReturn(false);
4852

4953
$this->factory = new SieveClientFactory($this->crypto, $this->config);
5054
}

tests/Unit/Controller/SieveControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function testUpdateAccountEnableNoConnection(): void {
107107

108108
$sieveClientFactory = $this->serviceMock->getParameter('sieveClientFactory');
109109
$sieveClientFactory->expects($this->once())
110-
->method('getClient')
110+
->method('createClient')
111111
->willThrowException(new Exception('Computer says no'));
112112

113113
$response = $this->sieveController->updateAccount(2, true, 'localhost', 4190, 'user', 'password', '');

0 commit comments

Comments
 (0)