Skip to content

Commit

Permalink
Added try/catch on sieve manager getScript
Browse files Browse the repository at this point in the history
  • Loading branch information
josaphatim committed Oct 9, 2023
1 parent 454ad1a commit 138a202
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions modules/sievefilters/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,37 +208,38 @@ function get_blocked_senders($mailbox, $mailbox_id, $icon_svg, $icon_block_domai
try {
$client = $factory->init($user_config, $mailbox);
$scripts = $client->listScripts();
} catch (Exception $e) {
Hm_Msgs::add("ERRSieve: {$e->getMessage()}");
return '';
}
if (array_search('blocked_senders', $scripts, true) === false) {
return '';
}
$current_script = $client->getScript('blocked_senders');
if ($current_script != '') {
$base64_obj = str_replace("# ", "", preg_split('#\r?\n#', $current_script, 0)[1]);
$blocked_list = json_decode(base64_decode($base64_obj));
if (!$blocked_list) {

if (array_search('blocked_senders', $scripts, true) === false) {
return '';
}
foreach ($blocked_list as $blocked_sender) {
if (explode('@', $blocked_sender)[0] == '') {
$blocked_sender = '*'.$blocked_sender;
$current_script = $client->getScript('blocked_senders');
if ($current_script != '') {
$base64_obj = str_replace("# ", "", preg_split('#\r?\n#', $current_script, 0)[1]);
$blocked_list = json_decode(base64_decode($base64_obj));
if (!$blocked_list) {
return '';
}
foreach ($blocked_list as $blocked_sender) {
if (explode('@', $blocked_sender)[0] == '') {
$blocked_sender = '*'.$blocked_sender;
}
$blocked_senders[] = $blocked_sender;
}
$blocked_senders[] = $blocked_sender;
}
}

$ret = '';
foreach ($blocked_senders as $sender) {
$ret .= '<tr><td>'.$sender.'</td><td><img class="unblock_button" mailbox_id="'.$mailbox_id.'" src="'.$icon_svg.'" />';
if (!strstr($sender, '*')) {
$ret .= ' <img class="block_domain_button" mailbox_id="'.$mailbox_id.'" src="'.$icon_block_domain_svg.'" />';
$ret = '';
foreach ($blocked_senders as $sender) {
$ret .= '<tr><td>'.$sender.'</td><td><img class="unblock_button" mailbox_id="'.$mailbox_id.'" src="'.$icon_svg.'" />';
if (!strstr($sender, '*')) {
$ret .= ' <img class="block_domain_button" mailbox_id="'.$mailbox_id.'" src="'.$icon_block_domain_svg.'" />';
}
$ret .= '</tr></td></tr>';
}
$ret .= '</tr></td></tr>';
return $ret;
} catch (Exception $e) {
Hm_Msgs::add("ERRSieve: {$e->getMessage()}");
return '';
}
return $ret;
}


Expand Down

0 comments on commit 138a202

Please sign in to comment.