Commit 5f2405d8 authored by Marius Burkard's avatar Marius Burkard
Browse files

Merge branch '5543-changing-tag-method-in-policy-is-not-applied-to-spamfilter-users' into 'develop'

Resolve "Changing tag method in policy is not applied to spamfilter users"

Closes #5543

See merge request ispconfig/ispconfig3!1438
parents 3ba74fd3 1deb325d
......@@ -446,7 +446,7 @@ class page_action extends tform_actions {
//* Update the mailboxes
$mailusers = $app->db->queryAllRecords("SELECT * FROM mail_user WHERE email like ?", '%@' . $this->oldDataRecord['domain']);
$sys_groupid = $app->functions->intval((isset($this->dataRecord['client_group_id']))?$this->dataRecord['client_group_id']:$this->oldDataRecord['sys_groupid']);
$tmp = $app->db->queryOneRecord("SELECT userid FROM sys_user WHERE default_group = ?", $client_group_id);
$tmp = $app->db->queryOneRecord("SELECT userid FROM sys_user WHERE default_group = ?", $sys_groupid);
$client_user_id = $app->functions->intval(($tmp['userid'] > 0)?$tmp['userid']:1);
if(is_array($mailusers)) {
foreach($mailusers as $rec) {
......
......@@ -139,7 +139,7 @@ class rspamd_plugin {
$app->plugins->registerEvent('mail_forwarding_delete', $this->plugin_name, 'user_settings_update');
}
function user_settings_update($event_name, $data) {
function user_settings_update($event_name, $data, $internal = false) {
global $app, $conf;
if(!is_dir('/etc/rspamd')) {
......@@ -206,6 +206,23 @@ class rspamd_plugin {
return;
}
$entries_to_update = [
'mail_user' => [],
'mail_forwarding' => []
];
if($is_domain === true) {
// get all child records to update / delete
$mailusers = $app->db->queryAllRecords("SELECT mu.* FROM mail_user as mu LEFT JOIN spamfilter_users as su ON (su.email = mu.email) WHERE mu.email LIKE ? AND su.id IS NULL", '%' . $email_address);
if(is_array($mailusers) && !empty($mailusers)) {
$entries_to_update['mail_user'] = $mailusers;
}
$forwardings = $app->db->queryAllRecords("SELECT mf.* FROM mail_forwarding as mf LEFT JOIN spamfilter_users as su ON (su.email = mf.source) WHERE mf.source LIKE ? AND su.id IS NULL", '%' . $email_address);
if(is_array($forwardings) && !empty($forwardings)) {
$entries_to_update['mail_forwarding'] = $forwardings;
}
}
$old_settings_name = $settings_name;
$settings_name = $app->functions->idn_encode($settings_name);
......@@ -220,7 +237,17 @@ class rspamd_plugin {
$settings_file = $this->users_config_dir . str_replace('@', '_', $settings_name) . '.conf';
//$app->log('Settings file for rspamd is ' . $settings_file, LOGLEVEL_WARN);
if($mode === 'delete') {
if(is_file($settings_file)) {
$delete_file = true;
if($type === 'spamfilter_user') {
$search_for_policy[] = $email_address;
$search_for_policy[] = substr($email_address, strpos($email_address, '@'));
$policy = $app->db->queryOneRecord("SELECT p.* FROM spamfilter_users as u INNER JOIN spamfilter_policy as p ON (p.id = u.policy_id) WHERE u.server_id = ? AND u.email IN ? ORDER BY u.priority DESC", $conf['server_id'], $search_for_policy);
if($policy) {
$delete_file = false;
}
}
if($delete_file === true && is_file($settings_file)) {
unlink($settings_file);
}
} else {
......@@ -318,7 +345,16 @@ class rspamd_plugin {
}
}
if($mail_config['content_filter'] == 'rspamd'){
if($is_domain === true) {
foreach($entries_to_update['mail_user'] as $entry) {
$this->user_settings_update('mail_user_' . $mode, ['old' => $entry, 'new' => $entry], true);
}
foreach($entries_to_update['mail_forwarding'] as $entry) {
$this->user_settings_update('mail_forwarding_' . $mode, ['old' => $entry, 'new' => $entry], true);
}
}
if($internal !== true && $mail_config['content_filter'] == 'rspamd'){
$app->services->restartServiceDelayed('rspamd', 'reload');
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment