Skip to content

Commit 38a786b

Browse files
committed
fix(backend): refactor clas usage teting with postale
1 parent 1149208 commit 38a786b

File tree

5 files changed

+12
-26
lines changed

5 files changed

+12
-26
lines changed

config/app.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,10 +425,11 @@
425425
| only one email source, this option is less likely to be a problem.
426426
|
427427
|
428-
| 'allow_session_cache' => env('ALLOW_SESSION_CACHE', false),
429-
| 'cache_class' => env('CACHE_CLASS')
430428
*/
431429

430+
'allow_session_cache' => env('ALLOW_SESSION_CACHE', false),
431+
432+
'cache_class' => env('CACHE_CLASS'),
432433

433434
/*
434435
| -------------

modules/imap_folders/modules.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@ function only_subscribed_folders_setting_callback($val) {
337337
class Hm_Output_folders_server_select extends Hm_Output_Module {
338338
protected function output() {
339339
$server_id = $this->get('folder_server', '');
340-
// exit(var_dump($server_id));
341340
// $res = '<div class="folders_page mt-4 row mb-4"><div class="col-xl-6 col-sm-12"><form id="form_folder_imap" method="get">';
342341
$data_auto_submit = !empty($this->get('trigger_default_submit')) ? ' data-auto-submit="1"' : 'data-auto-submit="0"';
343342
$res = '<div class="folders_page mt-4 row mb-4"><div class="col-xl-6 col-sm-12"><form id="form_folder_imap" method="get"'.$data_auto_submit.'>';

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
@@ -1230,14 +1230,10 @@ protected function output() {
12301230
}
12311231
$default_behaviour_html .= '<button class="submit_default_behavior btn btn-primary">' . $this->trans('Submit') . '</button></div></div>';
12321232
$client = SieveConnectionPool::get($mailbox['id']);
1233-
// $current_script = SieveConnectionPool::getScript($mailbox['id'], 'blocked_senders');
12341233
$current_script = SieveConnectionPool::getScript($mailbox['id'], 'blocked_senders');
1235-
// $client->getScript('blocked_senders');
12361234
$scripts = $client->listScripts();
1237-
exit(var_dump($scripts, $current_script));//SieveConnectionPool::get($imapServer);
12381235
list($scripts, $current_script) = get_all_scripts($mailbox['id'], true);
12391236
$blocked_senders = get_blocked_senders_array($current_script, $scripts);
1240-
exit(var_dump($blocked_senders));
12411237
$num_blocked = $blocked_senders ? sizeof($blocked_senders) : 0;
12421238
$res = '<div class="sievefilters_accounts_item">';
12431239
$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'];
@@ -1460,7 +1456,7 @@ public function process() {
14601456
}
14611457

14621458
try {
1463-
$current_script = get_all_scripts($this->config, $this->user_config, $imap_account, true, 'current_script');
1459+
list($scripts, $current_script) = get_all_scripts($form['imap_server_id'], true);
14641460

14651461
$blocked_senders = [];
14661462
if ($current_script != '') {
@@ -1545,6 +1541,7 @@ public function process()
15451541
}
15461542
// set the sieve connection pool with the sieve accounts configs
15471543
if (!empty($sieve_accounts_configs)) {
1544+
SieveConnectionPool::setCache($this->cache);
15481545
SieveConnectionPool::setConfig($sieve_accounts_configs);
15491546
}
15501547
if (isset($accounts[$form['imap_server_id']])) {
@@ -1568,7 +1565,8 @@ public function process()
15681565

15691566
$mailbox = Hm_IMAP_List::get_connected_mailbox($form['imap_server_id'], $this->cache);
15701567
if ($mailbox && $mailbox->authed() && $mailbox->is_imap()) {
1571-
list($scripts, $current_script, $client) = get_all_scripts($this->config, $this->user_config, $mailbox, true);
1568+
// list($scripts, $current_script, $client) = get_all_scripts($this->config, $this->user_config, $mailbox, true);
1569+
list($scripts, $current_script) = get_all_scripts($form['imap_server_id'], true);
15721570
$linked_mailboxes = get_sieve_linked_mailbox($scripts, $current_script);
15731571
if ($linked_mailboxes && in_array($form['folder'], $linked_mailboxes)) {
15741572
try {
@@ -1617,7 +1615,9 @@ public function process()
16171615
$mailbox = Hm_IMAP_List::get_connected_mailbox($form['imap_server_id'], $this->cache);
16181616
if ($mailbox && $mailbox->authed() && $mailbox->is_imap()) {
16191617
$del_folder = prep_folder_name($mailbox->get_connection(), $form['folder'], true);
1620-
list($scripts, $current_script, $client) = get_all_scripts($this->config, $this->user_config, $mailbox);
1618+
$client = SieveConnectionPool::get($mailbox['id']);
1619+
// list($scripts, $current_script, $client) = get_all_scripts($this->config, $this->user_config, $mailbox);
1620+
list($scripts) = get_all_scripts($form['imap_server_id'], false);
16211621
if (is_mailbox_linked_with_filters($del_folder, $form['imap_server_id'], $this, $scripts, $client)) {
16221622
$this->out('sieve_can_delete_folder', false);
16231623
Hm_Msgs::add('This folder can\'t be deleted because it is used in a Sieve filter.', 'warning');

0 commit comments

Comments
 (0)