Skip to content

Commit 760827b

Browse files
committed
fix(backend): refactor clas usage teting with postale
1 parent fd33a98 commit 760827b

File tree

4 files changed

+12
-25
lines changed

4 files changed

+12
-25
lines changed

config/app.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,11 @@
430430
| only one email source, this option is less likely to be a problem.
431431
|
432432
|
433-
| 'allow_session_cache' => env('ALLOW_SESSION_CACHE', false),
434-
| 'cache_class' => env('CACHE_CLASS')
435433
*/
436434

435+
'allow_session_cache' => env('ALLOW_SESSION_CACHE', false),
436+
437+
'cache_class' => env('CACHE_CLASS'),
437438

438439
/*
439440
| -------------

modules/sievefilters/functions.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,6 @@ function block_filter_dropdown ($mod, $mailbox_id = null, $with_scope = true, $s
451451
if (!hm_exists('get_blocked_senders_array')) {
452452
function get_blocked_senders_array($current_script, $scripts)
453453
{
454-
exit(var_dump($scripts, $current_script));
455454
try {
456455
if (!is_array($scripts) || array_search('blocked_senders', $scripts, true) === false) {
457456
return [];
@@ -461,7 +460,6 @@ function get_blocked_senders_array($current_script, $scripts)
461460
// $blocked_list = prepare_sieve_script ($current_script);
462461
$base64_obj = str_replace("# ", "", preg_split('#\r?\n#', $current_script, 0)[1]);
463462
$blocked_list = json_decode(base64_decode($base64_obj));
464-
exit(var_dump($scripts, $current_script, $blocked_list));
465463
if (!$blocked_list) {
466464
return [];
467465
}
@@ -590,7 +588,7 @@ function get_all_scripts($imapServer, $load_current = true, $return_only = null)
590588
}
591589
$current_script = '';
592590
if($load_current) {
593-
$current_script = $client->getScript('blocked_senders');
591+
$current_script = SieveConnectionPool::getScript($imapServer, 'blocked_senders');
594592
}
595593
if ($return_only === 'scripts') return $scripts;
596594
if ($return_only === 'current_script') return $current_script;

modules/sievefilters/hm-sieve-pool.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ public static function getScript($key, string $scriptName)
8787

8888
// Try to fetch from persistent cache
8989
$cached = self::$cache->get($cacheKey, false, true);
90-
// global $session;
9190

9291
if ($cached && isset($cached['time']) && (time() - $cached['time']) < self::$scriptCacheTTL) {
9392
return $cached['data'];
@@ -103,9 +102,6 @@ public static function getScript($key, string $scriptName)
103102
'time' => time()
104103
], self::$scriptCacheTTL, true);
105104

106-
// exit(var_dump("CACHE HIT", self::$cache->get($cacheKey, 'HEHEHEHE', true)));
107-
// exit(var_dump("CACHE HIT", self::$cache->type));
108-
// die();
109105
return $script;
110106
}
111107

@@ -135,7 +131,7 @@ private static function isAlive($key)
135131
*/
136132
private static function connectServer(array $serverConfig)
137133
{
138-
$client = new ClientWithTimeout($serverConfig['host'], $serverConfig['port']);
134+
$client = new Client($serverConfig['host'], $serverConfig['port']);
139135
$client->connect(
140136
$serverConfig['username'],
141137
$serverConfig['password'],
@@ -146,11 +142,3 @@ private static function connectServer(array $serverConfig)
146142
return $client;
147143
}
148144
}
149-
150-
class ClientWithTimeout extends Client
151-
{
152-
// public function getSocket()
153-
// {
154-
// return $this->sock;
155-
// }
156-
}

modules/sievefilters/modules.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,14 +1236,10 @@ protected function output() {
12361236
}
12371237
$default_behaviour_html .= '<button class="submit_default_behavior btn btn-primary">' . $this->trans('Submit') . '</button></div></div>';
12381238
$client = SieveConnectionPool::get($mailbox['id']);
1239-
// $current_script = SieveConnectionPool::getScript($mailbox['id'], 'blocked_senders');
12401239
$current_script = SieveConnectionPool::getScript($mailbox['id'], 'blocked_senders');
1241-
// $client->getScript('blocked_senders');
12421240
$scripts = $client->listScripts();
1243-
exit(var_dump($scripts, $current_script));//SieveConnectionPool::get($imapServer);
12441241
list($scripts, $current_script) = get_all_scripts($mailbox['id'], true);
12451242
$blocked_senders = get_blocked_senders_array($current_script, $scripts);
1246-
exit(var_dump($blocked_senders));
12471243
$num_blocked = $blocked_senders ? sizeof($blocked_senders) : 0;
12481244
$res = '<div class="sievefilters_accounts_item">';
12491245
$res .= '<div class="sievefilters_accounts_title settings_subtitle py-2 border-bottom cursor-pointer d-flex justify-content-between" data-num-blocked="' . $num_blocked . '">' . $mailbox['name'];
@@ -1466,7 +1462,7 @@ public function process() {
14661462
}
14671463

14681464
try {
1469-
$current_script = get_all_scripts($this->config, $this->user_config, $imap_account, true, 'current_script');
1465+
list($scripts, $current_script) = get_all_scripts($form['imap_server_id'], true);
14701466

14711467
$blocked_senders = [];
14721468
if ($current_script != '') {
@@ -1551,6 +1547,7 @@ public function process()
15511547
}
15521548
// set the sieve connection pool with the sieve accounts configs
15531549
if (!empty($sieve_accounts_configs)) {
1550+
SieveConnectionPool::setCache($this->cache);
15541551
SieveConnectionPool::setConfig($sieve_accounts_configs);
15551552
}
15561553
if (isset($accounts[$form['imap_server_id']])) {
@@ -1574,7 +1571,8 @@ public function process()
15741571

15751572
$mailbox = Hm_IMAP_List::get_connected_mailbox($form['imap_server_id'], $this->cache);
15761573
if ($mailbox && $mailbox->authed() && $mailbox->is_imap()) {
1577-
list($scripts, $current_script, $client) = get_all_scripts($this->config, $this->user_config, $mailbox, true);
1574+
// list($scripts, $current_script, $client) = get_all_scripts($this->config, $this->user_config, $mailbox, true);
1575+
list($scripts, $current_script) = get_all_scripts($form['imap_server_id'], true);
15781576
$linked_mailboxes = get_sieve_linked_mailbox($scripts, $current_script);
15791577
if ($linked_mailboxes && in_array($form['folder'], $linked_mailboxes)) {
15801578
try {
@@ -1623,7 +1621,9 @@ public function process()
16231621
$mailbox = Hm_IMAP_List::get_connected_mailbox($form['imap_server_id'], $this->cache);
16241622
if ($mailbox && $mailbox->authed() && $mailbox->is_imap()) {
16251623
$del_folder = prep_folder_name($mailbox->get_connection(), $form['folder'], true);
1626-
list($scripts, $current_script, $client) = get_all_scripts($this->config, $this->user_config, $mailbox);
1624+
$client = SieveConnectionPool::get($mailbox['id']);
1625+
// list($scripts, $current_script, $client) = get_all_scripts($this->config, $this->user_config, $mailbox);
1626+
list($scripts) = get_all_scripts($form['imap_server_id'], false);
16271627
if (is_mailbox_linked_with_filters($del_folder, $form['imap_server_id'], $this, $scripts, $client)) {
16281628
$this->out('sieve_can_delete_folder', false);
16291629
Hm_Msgs::add('This folder can\'t be deleted because it is used in a Sieve filter.', 'warning');

0 commit comments

Comments
 (0)