15
15
use OCP \Security \ICrypto ;
16
16
17
17
class SieveClientFactory {
18
- /** @var ICrypto */
19
- private $ crypto ;
18
+ private ICrypto $ crypto ;
19
+ private IConfig $ config ;
20
+ private array $ cache = [];
20
21
21
- /** @var IConfig */
22
- private $ config ;
23
-
24
- private $ cache = [];
25
-
26
- /**
27
- * @param ICrypto $crypto
28
- * @param IConfig $config
29
- */
30
22
public function __construct (ICrypto $ crypto , IConfig $ config ) {
31
23
$ this ->crypto = $ crypto ;
32
24
$ this ->config = $ config ;
33
25
}
34
26
35
27
/**
36
- * @param Account $account
37
- * @return ManageSieve
38
28
* @throws ManageSieve\Exception
39
29
*/
40
30
public function getClient (Account $ account ): ManageSieve {
@@ -48,28 +38,31 @@ public function getClient(Account $account): ManageSieve {
48
38
$ password = $ account ->getMailAccount ()->getInboundPassword ();
49
39
}
50
40
41
+ if ($ account ->getDebug () || $ this ->config ->getSystemValueBool ('app.mail.debug ' )) {
42
+ $ logFile = $ this ->config ->getSystemValue ('datadirectory ' ) . '/mail- ' . $ account ->getUserId () . '- ' . $ account ->getId () . '-sieve.log ' ;
43
+ } else {
44
+ $ logFile = null ;
45
+ }
46
+
51
47
$ this ->cache [$ account ->getId ()] = $ this ->createClient (
52
48
$ account ->getMailAccount ()->getSieveHost (),
53
49
$ account ->getMailAccount ()->getSievePort (),
54
50
$ user ,
55
- $ password ,
56
- $ account ->getMailAccount ()->getSieveSslMode ()
51
+ $ this ->crypto ->decrypt ($ password ),
52
+ $ account ->getMailAccount ()->getSieveSslMode (),
53
+ $ logFile ,
57
54
);
58
55
}
59
56
60
57
return $ this ->cache [$ account ->getId ()];
61
58
}
62
59
63
60
/**
64
- * @param string $host
65
- * @param int $port
66
- * @param string $user
67
- * @param string $password
68
- * @param string $sslMode
69
- * @return ManageSieve
61
+ * @param string $sslMode possible values: '', 'none', 'ssl' or 'tls'
62
+ * @param ?string $logFile absolute path for logFile or null to disable logging
70
63
* @throws ManageSieve\Exception
71
64
*/
72
- public function createClient (string $ host , int $ port , string $ user , string $ password , string $ sslMode ): ManageSieve {
65
+ public function createClient (string $ host , int $ port , string $ user , string $ password , string $ sslMode, ? string $ logFile ): ManageSieve {
73
66
if (empty ($ sslMode )) {
74
67
$ sslMode = true ;
75
68
} elseif ($ sslMode === 'none ' ) {
@@ -80,9 +73,9 @@ public function createClient(string $host, int $port, string $user, string $pass
80
73
'host ' => $ host ,
81
74
'port ' => $ port ,
82
75
'user ' => $ user ,
83
- 'password ' => $ this -> crypto -> decrypt ( $ password) ,
76
+ 'password ' => $ password ,
84
77
'secure ' => $ sslMode ,
85
- 'timeout ' => ( int ) $ this ->config ->getSystemValue ('app.mail.sieve.timeout ' , 5 ),
78
+ 'timeout ' => $ this ->config ->getSystemValueInt ('app.mail.sieve.timeout ' , 5 ),
86
79
'context ' => [
87
80
'ssl ' => [
88
81
'verify_peer ' => $ this ->config ->getSystemValueBool ('app.mail.verify-tls-peer ' , true ),
@@ -92,8 +85,8 @@ public function createClient(string $host, int $port, string $user, string $pass
92
85
],
93
86
];
94
87
95
- if ($ this -> config -> getSystemValue ( ' debug ' , false ) ) {
96
- $ params ['logger ' ] = new SieveLogger ($ this -> config -> getSystemValue ( ' datadirectory ' ) . ' /horde_sieve.log ' );
88
+ if ($ logFile !== null ) {
89
+ $ params ['logger ' ] = new SieveLogger ($ logFile );
97
90
}
98
91
99
92
return new ManageSieve ($ params );
0 commit comments