@@ -33,6 +33,8 @@ public function __construct(ICrypto $crypto, IConfig $config) {
33
33
}
34
34
35
35
/**
36
+ * @param Account $account
37
+ * @return ManageSieve
36
38
* @throws ManageSieve\Exception
37
39
*/
38
40
public function getClient (Account $ account ): ManageSieve {
@@ -41,43 +43,59 @@ public function getClient(Account $account): ManageSieve {
41
43
if (empty ($ user )) {
42
44
$ user = $ account ->getMailAccount ()->getInboundUser ();
43
45
}
44
-
45
46
$ password = $ account ->getMailAccount ()->getSievePassword ();
46
47
if (empty ($ password )) {
47
48
$ password = $ account ->getMailAccount ()->getInboundPassword ();
48
49
}
49
50
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
+ );
78
58
}
79
59
80
60
return $ this ->cache [$ account ->getId ()];
81
61
}
82
62
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
+ }
83
101
}
0 commit comments