diff --git a/install/dist/tpl/gentoo/amavisd-ispconfig.conf.master b/install/dist/tpl/gentoo/amavisd-ispconfig.conf.master
index 7e42c8a362b86f9255fbd46aa16c3a546b727a34..c60b50e2fa9aa47e3a9a93b187c701ba7c6d7e34 100644
--- a/install/dist/tpl/gentoo/amavisd-ispconfig.conf.master
+++ b/install/dist/tpl/gentoo/amavisd-ispconfig.conf.master
@@ -51,7 +51,8 @@ use strict;
$sql_select_policy =
'SELECT *,spamfilter_users.id'.
' FROM spamfilter_users LEFT JOIN spamfilter_policy ON spamfilter_users.policy_id=spamfilter_policy.id'.
- ' WHERE spamfilter_users.email IN (%k) ORDER BY spamfilter_users.priority DESC';
+ ' WHERE spamfilter_users.email IN (%k) AND spamfilter_users.policy_id != 0'.
+ ' ORDER BY spamfilter_users.priority DESC';
$sql_select_white_black_list = 'SELECT wb FROM spamfilter_wblist'.
diff --git a/install/sql/incremental/upd_dev_collection.sql b/install/sql/incremental/upd_dev_collection.sql
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..2a9a9ffd091f961e8003a7f0bf0c58c8f8db4798 100644
--- a/install/sql/incremental/upd_dev_collection.sql
+++ b/install/sql/incremental/upd_dev_collection.sql
@@ -0,0 +1,2 @@
+-- default spamfilter_users.policy_id to 0
+ALTER TABLE `spamfilter_users` ALTER `policy_id` SET DEFAULT 0;
diff --git a/install/sql/ispconfig3.sql b/install/sql/ispconfig3.sql
index 006beb6b53945de3403408dac1bfcbab8b7bb498..9ebb69090f9a508a39cab80b9dd2df09ed0690fc 100644
--- a/install/sql/ispconfig3.sql
+++ b/install/sql/ispconfig3.sql
@@ -1545,7 +1545,7 @@ CREATE TABLE `spamfilter_users` (
`sys_perm_other` varchar(5) NOT NULL DEFAULT '',
`server_id` int(11) unsigned NOT NULL DEFAULT '0',
`priority` tinyint(3) unsigned NOT NULL default '7',
- `policy_id` int(11) unsigned NOT NULL default '1',
+ `policy_id` int(11) unsigned NOT NULL default '0',
`email` varchar(255) NOT NULL DEFAULT '',
`fullname` varchar(64) default NULL,
`local` varchar(1) default NULL,
diff --git a/install/tpl/amavisd_user_config.master b/install/tpl/amavisd_user_config.master
index 344ea9a152de0ab43982c83b18b6bb7e99525d6c..f764bb3acb0bedd1c884f255662e7782e58b473a 100644
--- a/install/tpl/amavisd_user_config.master
+++ b/install/tpl/amavisd_user_config.master
@@ -33,7 +33,8 @@ use strict;
$sql_select_policy =
'SELECT *,spamfilter_users.id'.
' FROM spamfilter_users LEFT JOIN spamfilter_policy ON spamfilter_users.policy_id=spamfilter_policy.id'.
- ' WHERE spamfilter_users.email IN (%k) ORDER BY spamfilter_users.priority DESC';
+ ' WHERE spamfilter_users.email IN (%k) AND spamfilter_users.policy_id != 0'.
+ ' ORDER BY spamfilter_users.priority DESC';
$sql_select_white_black_list = 'SELECT wb FROM spamfilter_wblist'.
diff --git a/install/tpl/fedora_amavisd_conf.master b/install/tpl/fedora_amavisd_conf.master
index 9cf4b801bc669813239dc8d4478729b492623872..2435e6939e06511899dde1377f50c27de15c48b5 100644
--- a/install/tpl/fedora_amavisd_conf.master
+++ b/install/tpl/fedora_amavisd_conf.master
@@ -751,7 +751,8 @@ $banned_filename_re = new_RE(
$sql_select_policy =
'SELECT *,spamfilter_users.id'.
' FROM spamfilter_users LEFT JOIN spamfilter_policy ON spamfilter_users.policy_id=spamfilter_policy.id'.
- ' WHERE spamfilter_users.email IN (%k) ORDER BY spamfilter_users.priority DESC';
+ ' WHERE spamfilter_users.email IN (%k) AND spamfilter_users.policy_id != 0'.
+ ' ORDER BY spamfilter_users.priority DESC';
$sql_select_white_black_list = 'SELECT wb FROM spamfilter_wblist'.
diff --git a/install/tpl/opensuse_amavisd_conf.master b/install/tpl/opensuse_amavisd_conf.master
index 419eea237c2a81d2bbb939a135ffe0accacfd4c4..7310db9cbf9e45956d5ce6cdbb7aa1dcaf19231d 100644
--- a/install/tpl/opensuse_amavisd_conf.master
+++ b/install/tpl/opensuse_amavisd_conf.master
@@ -746,7 +746,8 @@ $banned_filename_re = new_RE(
$sql_select_policy =
'SELECT *,spamfilter_users.id'.
' FROM spamfilter_users LEFT JOIN spamfilter_policy ON spamfilter_users.policy_id=spamfilter_policy.id'.
- ' WHERE spamfilter_users.email IN (%k) ORDER BY spamfilter_users.priority DESC';
+ ' WHERE spamfilter_users.email IN (%k) AND spamfilter_users.policy_id != 0'.
+ ' ORDER BY spamfilter_users.priority DESC';
$sql_select_white_black_list = 'SELECT wb FROM spamfilter_wblist'.
diff --git a/interface/lib/classes/remote.d/client.inc.php b/interface/lib/classes/remote.d/client.inc.php
index 58dcc3119f592413dc93ee658de530b2524dc3ec..5af1592db9347d60932f5f05b44b27d2274a6d05 100644
--- a/interface/lib/classes/remote.d/client.inc.php
+++ b/interface/lib/classes/remote.d/client.inc.php
@@ -413,7 +413,7 @@ class remoting_client extends remoting {
$app->db->query("DELETE FROM sys_user WHERE client_id = ?", $client_id);
//* Delete all records (sub-clients, mail, web, etc....) of this client.
- $tables = 'cron,dns_rr,dns_soa,dns_slave,ftp_user,mail_access,mail_content_filter,mail_domain,mail_forwarding,mail_get,mail_user,mail_user_filter,shell_user,spamfilter_users,support_message,web_database,web_database_user,web_domain,web_traffic,domain,mail_mailinglist,client';
+ $tables = 'cron,dns_rr,dns_soa,dns_slave,ftp_user,mail_access,mail_content_filter,mail_domain,mail_forwarding,mail_get,mail_user,mail_user_filter,shell_user,spamfilter_users,support_message,web_database,web_database_user,web_domain,web_traffic,domain,mail_mailinglist,client,spamfilter_wblist';
$tables_array = explode(',', $tables);
$client_group_id = $app->functions->intval($client_group['groupid']);
if($client_group_id > 1) {
diff --git a/interface/lib/classes/remote.d/mail.inc.php b/interface/lib/classes/remote.d/mail.inc.php
index c4582c634e43824d632881b2496b5a71930c3ba9..286d6f6c57d6e30d72b4b869b15a0648477e7a3b 100644
--- a/interface/lib/classes/remote.d/mail.inc.php
+++ b/interface/lib/classes/remote.d/mail.inc.php
@@ -663,7 +663,7 @@ class remoting_mail extends remoting {
return $app->remoting_lib->getDataRecord($primary_id);
}
- //* biała lista e-mail
+ //* add spamfilter whitelist entry
public function mail_spamfilter_whitelist_add($session_id, $client_id, $params)
{
if (!$this->checkPerm($session_id, 'mail_spamfilter_whitelist_add'))
@@ -763,7 +763,7 @@ class remoting_mail extends remoting {
return $app->remoting_lib->getDataRecord($primary_id);
}
- //* filtr spamu użytkowników e-mail
+ //* Add new spamfilter_users
public function mail_spamfilter_user_add($session_id, $client_id, $params)
{
if (!$this->checkPerm($session_id, 'mail_spamfilter_user_add'))
diff --git a/interface/lib/plugins/mail_mail_domain_plugin.inc.php b/interface/lib/plugins/mail_mail_domain_plugin.inc.php
index 598fe74f09bb75c843b4a9a66a322e454a471957..4ff756f44fb2ec1be22c46313b8c7da649128a99 100644
--- a/interface/lib/plugins/mail_mail_domain_plugin.inc.php
+++ b/interface/lib/plugins/mail_mail_domain_plugin.inc.php
@@ -13,9 +13,10 @@ class mail_mail_domain_plugin {
/*
This function is called when the plugin is loaded
- */
+ */
function onLoad() {
global $app;
+
//Register for the events
$app->plugin->registerEvent('mail:mail_domain:on_after_insert', 'mail_mail_domain_plugin', 'mail_mail_domain_edit');
$app->plugin->registerEvent('mail:mail_domain:on_after_update', 'mail_mail_domain_plugin', 'mail_mail_domain_edit');
@@ -23,13 +24,13 @@ class mail_mail_domain_plugin {
/*
Function to create the sites_web_domain rule and insert it into the custom rules
- */
+ */
function mail_mail_domain_edit($event_name, $page_form) {
global $app, $conf;
$domain = $app->functions->idn_encode($page_form->dataRecord['domain']);
- // make sure that the record belongs to the client group and not the admin group when a dmin inserts it
+ // make sure that the record belongs to the client group and not the admin group when admin inserts it
// also make sure that the user can not delete entry created by an admin
if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($page_form->dataRecord["client_group_id"])) {
$client_group_id = $app->functions->intval($page_form->dataRecord["client_group_id"]);
@@ -64,6 +65,8 @@ class mail_mail_domain_plugin {
$app->uses('getconf');
$mail_config = $app->getconf->get_server_config($page_form->dataRecord["server_id"], 'mail');
+ $old_domain = $app->functions->idn_encode($page_form->oldDataRecord['domain']);
+
//* Update the mailboxes
$mailusers = $app->db->queryAllRecords("SELECT * FROM mail_user WHERE email like ?", "%@" . $page_form->oldDataRecord['domain']);
$sys_groupid = $app->functions->intval((isset($page_form->dataRecord['client_group_id']))?$page_form->dataRecord['client_group_id']:$page_form->oldDataRecord['sys_groupid']);
@@ -76,25 +79,164 @@ class mail_mail_domain_plugin {
$maildir = str_replace("[domain]", $domain, $mail_config["maildir_path"]);
$maildir = str_replace("[localpart]", $mail_parts[0], $maildir);
$email = $mail_parts[0].'@'.$domain;
+
+ // update spamfilter_users and spamfilter_wblist if email change
+ $skip_spamfilter_users_update = false;
+ if($email != $rec['email']) {
+ $tmp_olduser = $app->db->queryOneRecord("SELECT id,fullname FROM spamfilter_users WHERE email = ?", $rec['email']);
+ if($tmp_olduser['id'] > 0) {
+ $tmp_newuser = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = ?", $email);
+ if($tmp_newuser['id'] > 0) {
+ // There is a spamfilter_users for both old and new email, we'll update old wblist entries
+ $tmp_wblist = $app->db->queryAllRecords("SELECT wblist_id FROM spamfilter_wblist WHERE rid = ?", $tmp_olduser['id']);
+ foreach ($tmp_wblist as $tmp) {
+ $update_data = array(
+ 'rid' => $tmp_newuser['id'],
+ 'sys_userid' => $client_user_id,
+ 'sys_groupid' => $sys_groupid,
+ );
+ $app->db->datalogUpdate('spamfilter_wblist', $update_data, 'wblist_id', $tmp['wblist_id']);
+ }
+
+ // now delete old spamfilter_users entry
+ $app->db->datalogDelete('spamfilter_users', 'id', $tmp_olduser['id']);
+ } else {
+ $update_data = array(
+ 'email' => $email,
+ 'sys_userid' => $client_user_id,
+ 'sys_groupid' => $sys_groupid,
+ );
+ if($tmp_olduser['fullname'] == $app->functions->idn_decode($rec['email'])) {
+ $update_data['fullname'] = $app->functions->idn_decode($email);
+ }
+ $app->db->datalogUpdate('spamfilter_users', $update_data, 'id', $tmp_olduser['id']);
+ $skip_spamfilter_users_update = true;
+
+ $tmp_wblist = $app->db->queryAllRecords("SELECT wblist_id FROM spamfilter_wblist WHERE rid = ?", $tmp_olduser['id']);
+ $update_data = array(
+ 'sys_userid' => $client_user_id,
+ 'sys_groupid' => $sys_groupid,
+ );
+ foreach ($tmp_wblist as $tmp) {
+ $app->db->datalogUpdate('spamfilter_wblist', $update_data, 'wblist_id', $tmp['wblist_id']);
+ }
+ }
+ }
+
+ $tmp_user = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = ?", $email);
+ if($tmp_user["id"] > 0) {
+ // There is already a record that we will update
+ if(!$skip_spamfilter_users_update) {
+ $update_data = array(
+ 'sys_userid' => $client_user_id,
+ 'sys_groupid' => $sys_groupid,
+ );
+ $app->db->datalogUpdate('spamfilter_users', $update_data, 'id', $tmp_user['id']);
+ }
+ } else {
+ // We create a new record
+ $insert_data = array(
+ "sys_userid" => $client_user_id,
+ "sys_groupid" => $sys_groupid,
+ "sys_perm_user" => 'riud',
+ "sys_perm_group" => 'riud',
+ "sys_perm_other" => '',
+ "server_id" => $page_form->dataRecord["server_id"],
+ "priority" => 5,
+ "policy_id" => 0,
+ "email" => $email,
+ "fullname" => $app->functions->idn_decode($email),
+ "local" => 'Y'
+ );
+ $app->db->datalogInsert('spamfilter_users', $insert_data, 'id');
+ }
+ }
+
$app->db->datalogUpdate('mail_user', array("maildir" => $maildir, "email" => $email, "sys_userid" => $client_user_id, "sys_groupid" => $sys_groupid), 'mailuser_id', $rec['mailuser_id']);
+
}
}
//* Update the aliases
- $forwardings = $app->db->queryAllRecords("SELECT * FROM mail_forwarding WHERE source LIKE ? OR destination LIKE ?", "%@" . $page_form->oldDataRecord['domain'], "%@" . $page_form->oldDataRecord['domain']);
+ $forwardings = $app->db->queryAllRecords("SELECT * FROM mail_forwarding WHERE source like ? OR destination like ?", '%@' . $old_domain, '%@' . $old_domain);
if(is_array($forwardings)) {
foreach($forwardings as $rec) {
- $destination = str_replace($page_form->oldDataRecord['domain'], $domain, $rec['destination']);
- $source = str_replace($page_form->oldDataRecord['domain'], $domain, $rec['source']);
+ $destination = str_replace($old_domain, $domain, $rec['destination']);
+ $source = str_replace($old_domain, $domain, $rec['source']);
+
+ // update spamfilter_users and spamfilter_wblist if source email changes
+ $skip_spamfilter_users_update = false;
+ if(strpos($rec['source'],'@'.$old_domain) && $source != $rec['source']) {
+ $tmp_olduser = $app->db->queryOneRecord("SELECT id,fullname FROM spamfilter_users WHERE email = ?", $rec['source']);
+ if($tmp_olduser['id'] > 0) {
+ $tmp_newuser = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = ?", $source);
+ if($tmp_newuser['id'] > 0) {
+ // There is a spamfilter_users for both old and new email, we'll update old wblist entries
+ $tmp_wblist = $app->db->queryAllRecords("SELECT wblist_id FROM spamfilter_wblist WHERE rid = ?", $tmp_olduser['id']);
+ foreach ($tmp_wblist as $tmp) {
+ $update_data = array(
+ 'rid' => $tmp_newuser['id'],
+ 'sys_userid' => $client_user_id,
+ 'sys_groupid' => $sys_groupid,
+ );
+ $app->db->datalogUpdate('spamfilter_wblist', $update_data, 'wblist_id', $tmp['wblist_id']);
+ }
+
+ // now delete old spamfilter_users entry
+ $app->db->datalogDelete('spamfilter_users', 'id', $tmp_olduser['id']);
+ } else {
+ $update_data = array(
+ 'email' => $source,
+ 'sys_userid' => $client_user_id,
+ 'sys_groupid' => $sys_groupid,
+ );
+ if($tmp_olduser['fullname'] == $app->functions->idn_decode($rec['source'])) {
+ $update_data['fullname'] = $app->functions->idn_decode($source);
+ }
+ $app->db->datalogUpdate('spamfilter_users', $update_data, 'id', $tmp_olduser['id']);
+ $skip_spamfilter_users_update = true;
+
+ $tmp_wblist = $app->db->queryAllRecords("SELECT wblist_id FROM spamfilter_wblist WHERE rid = ?", $tmp_olduser['id']);
+ $update_data = array(
+ 'sys_userid' => $client_user_id,
+ 'sys_groupid' => $sys_groupid,
+ );
+ foreach ($tmp_wblist as $tmp) {
+ $app->db->datalogUpdate('spamfilter_wblist', $update_data, 'wblist_id', $tmp['wblist_id']);
+ }
+ }
+ }
+
+
+ $tmp_user = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = ?", $source);
+ if($tmp_user["id"] > 0) {
+ // There is already a record that we will update
+ if(!$skip_spamfilter_users_update) {
+ $update_data = array(
+ 'sys_userid' => $client_user_id,
+ 'sys_groupid' => $sys_groupid,
+ );
+ $app->db->datalogUpdate('spamfilter_users', $update_data, 'id', $tmp_user['id']);
+ }
+ }
+
+ }
+
$app->db->datalogUpdate('mail_forwarding', array("source" => $source, "destination" => $destination, "sys_userid" => $client_user_id, "sys_groupid" => $sys_groupid), 'forwarding_id', $rec['forwarding_id']);
}
}
//* Update the mailinglist
- $mailing_lists = $app->db->queryAllRecords("SELECT mailinglist_id FROM mail_mailinglist WHERE domain = ?", $page_form->oldDataRecord['domain']);
- if(is_array($mailing_lists)) {
- foreach($mailing_lists as $rec) {
- $app->db->datalogUpdate('mail_mailinglist', array("sys_userid" => $client_user_id, "sys_groupid" => $sys_groupid), 'mailinglist_id', $rec['mailinglist_id']);
+ $mailinglists = $app->db->queryAllRecords("SELECT * FROM mail_mailinglist WHERE domain = ?", $old_domain);
+ if(is_array($mailinglists)) {
+ foreach($mailinglists as $rec) {
+ $update_data = array(
+ 'sys_userid' => $client_user_id,
+ 'sys_groupid' => $sys_groupid,
+ 'domain' => $domain,
+ 'email' => str_replace($old_domain, $domain, $rec['email']),
+ );
+ $app->db->datalogUpdate('mail_mailinglist', $update_data, 'mailinglist_id', $rec['mailinglist_id']);
}
}
@@ -107,25 +249,81 @@ class mail_mail_domain_plugin {
}
}
- if ($page_form->oldDataRecord["domain"] != $domain) {
- //* Delete the old spamfilter record
- $tmp = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = ?", "@" . $page_form->oldDataRecord["domain"]);
- $app->db->datalogDelete('spamfilter_users', 'id', $tmp["id"]);
- unset($tmp);
+ // Spamfilter policy
+ $policy_id = $app->functions->intval($page_form->dataRecord["policy"]);
+
+ // If domain changes, update spamfilter_users
+ // and fire spamfilter_wblist_update events so rspamd files are rewritten
+ if ($old_domain != $domain) {
+ $tmp_users = $app->db->queryOneRecord("SELECT id,fullname FROM spamfilter_users WHERE email LIKE ?", '%@' . $old_domain);
+ if(is_array($tmp_users)) {
+ foreach ($tmp_users as $tmp_old) {
+ $tmp_new = $app->db->queryOneRecord("SELECT id,fullname FROM spamfilter_users WHERE email = ?", '@' . $domain);
+ if($tmp_new['id'] > 0) {
+ // There is a spamfilter_users for both old and new domain, we'll update old wblist entries
+ $update_data = array(
+ 'sys_userid' => $client_user_id,
+ 'sys_groupid' => $sys_groupid,
+ 'rid' => $tmp_new['id'],
+ );
+ $tmp_wblist = $app->db->queryAllRecords("SELECT wblist_id FROM spamfilter_wblist WHERE rid = ?", $tmp_old['id']);
+ foreach ($tmp_wblist as $tmp) {
+ $app->db->datalogUpdate('spamfilter_wblist', $update_data, 'wblist_id', $tmp['wblist_id']);
+ }
+
+ // now delete old spamfilter_users entry
+ $app->db->datalogDelete('spamfilter_users', 'id', $tmp_old['id']);
+
+ /// and update the new
+ $update_data = array(
+ 'sys_userid' => $client_user_id,
+ 'sys_groupid' => $sys_groupid,
+ );
+ $app->db->datalogUpdate('spamfilter_users', $update_data, 'id', $tmp_old['id']);
+ } else {
+ $update_data = array(
+ 'sys_userid' => $client_user_id,
+ 'sys_groupid' => $sys_groupid,
+ 'email' => '@' . $domain,
+ );
+ if($tmp_old['fullname'] == '@' . $old_domain) {
+ $update_data['fullname'] = '@' . $domain;
+ }
+ $app->db->datalogUpdate('spamfilter_users', $update_data, 'id', $tmp_old['id']);
+ }
+ }
+ }
}
- $app->db->query("UPDATE spamfilter_users SET email=REPLACE(email, ?, ?), sys_userid = ?, sys_groupid = ? WHERE email LIKE ?", $page_form->oldDataRecord['domain'], $domain, $client_user_id, $sys_groupid, "%@" . $page_form->oldDataRecord['domain']);
- } // end if domain name changed
-
- //* Force-update the aliases (required for spamfilter changes)
- $forwardings = $app->db->queryAllRecords("SELECT * FROM mail_forwarding WHERE source LIKE ? OR destination LIKE ?", "%@" . $domain, "%@" . $domain);
-
- if(is_array($forwardings)) {
- foreach($forwardings as $rec) {
- $app->db->datalogUpdate('mail_forwarding', array("source" => $rec['source']), 'forwarding_id', $rec['forwarding_id'],true);
+ $tmp_user = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = ?", '@' . $domain);
+ if(isset($tmp_user['id']) && $tmp_user['id'] > 0) {
+ // There is already a record that we will update
+ if($policy_id != $tmp_user['policy_id']) {
+ $update_data = array(
+ 'policy_id' => $policy_id,
+ );
+ $app->db->datalogUpdate('spamfilter_users', $update_data, 'id', $tmp_user["id"]);
+ }
+ } else {
+ // We create a new record
+ $insert_data = array(
+ "sys_userid" => $client_user_id,
+ "sys_groupid" => $sys_groupid,
+ "sys_perm_user" => 'riud',
+ "sys_perm_group" => 'riud',
+ "sys_perm_other" => '',
+ "server_id" => $page_form->dataRecord["server_id"],
+ "priority" => 5,
+ "policy_id" => $policy_id,
+ "email" => '@' . $domain,
+ "fullname" => '@' . $domain,
+ "local" => 'Y'
+ );
+ $app->db->datalogInsert('spamfilter_users', $insert_data, 'id');
}
- }
-
+
+ } // end if domain name changed
+
}
}
diff --git a/interface/web/client/client_del.php b/interface/web/client/client_del.php
index c018b7a27db50b9686f63aedce827cc8a89b49ef..dadcae0bdff53f2152b17a59e596d0d906902def 100644
--- a/interface/web/client/client_del.php
+++ b/interface/web/client/client_del.php
@@ -69,7 +69,8 @@ class page_action extends tform_actions {
'mail_user' => 'email',
'mail_user_filter' => '',
'shell_user' => 'username',
- 'spamfilter_users' => '', 'spamfilter_wblist' => '',
+ 'spamfilter_users' => '',
+ 'spamfilter_wblist' => '',
'support_message' => '',
'web_domain' => 'domain',
'web_folder' => 'path',
@@ -208,6 +209,5 @@ class page_action extends tform_actions {
}
$page = new page_action;
-$page->onDelete()
+$page->onDelete();
-?>
diff --git a/interface/web/mail/form/spamfilter_users.tform.php b/interface/web/mail/form/spamfilter_users.tform.php
index 65f196b9879be55f37d170b3a447f8395f0ec946..1bb7b5f682f0ce0e221f4e3f00708ad6163ba1d3 100644
--- a/interface/web/mail/form/spamfilter_users.tform.php
+++ b/interface/web/mail/form/spamfilter_users.tform.php
@@ -78,7 +78,7 @@ $form["tabs"]['users'] = array (
'policy_id' => array (
'datatype' => 'INTEGER',
'formtype' => 'SELECT',
- 'default' => '5',
+ 'default' => '0',
'datasource' => array ( 'type' => 'SQL',
'querystring' => 'SELECT id,policy_name FROM spamfilter_policy WHERE {AUTHSQL} ORDER BY policy_name',
'keyfield'=> 'id',
diff --git a/interface/web/mail/lib/lang/ar_spamfilter_users.lng b/interface/web/mail/lib/lang/ar_spamfilter_users.lng
index efe95b5c7f1bad9138a1a9c141787f1f06141c6d..05d0ca9bd627de80cdd373cfe5fe80af517ff484 100644
--- a/interface/web/mail/lib/lang/ar_spamfilter_users.lng
+++ b/interface/web/mail/lib/lang/ar_spamfilter_users.lng
@@ -10,4 +10,4 @@ $wb['fullname_error_notempty'] = 'The name must not be empty.';
$wb['10 - highest'] = '10 - highest';
$wb['5 - medium'] = '5 - medium';
$wb['1 - lowest'] = '1 - lowest';
-?>
+$wb['inherit_policy'] = '- Inherit domain setting -';
diff --git a/interface/web/mail/lib/lang/bg_spamfilter_users.lng b/interface/web/mail/lib/lang/bg_spamfilter_users.lng
index efe95b5c7f1bad9138a1a9c141787f1f06141c6d..05d0ca9bd627de80cdd373cfe5fe80af517ff484 100644
--- a/interface/web/mail/lib/lang/bg_spamfilter_users.lng
+++ b/interface/web/mail/lib/lang/bg_spamfilter_users.lng
@@ -10,4 +10,4 @@ $wb['fullname_error_notempty'] = 'The name must not be empty.';
$wb['10 - highest'] = '10 - highest';
$wb['5 - medium'] = '5 - medium';
$wb['1 - lowest'] = '1 - lowest';
-?>
+$wb['inherit_policy'] = '- Inherit domain setting -';
diff --git a/interface/web/mail/lib/lang/br_spamfilter_users.lng b/interface/web/mail/lib/lang/br_spamfilter_users.lng
index d18fbc13a9f29a018258c23b254bd2c2bacb45a4..bdc989833e5bc2af51ba8c3d5fe4b3f06221b59f 100644
--- a/interface/web/mail/lib/lang/br_spamfilter_users.lng
+++ b/interface/web/mail/lib/lang/br_spamfilter_users.lng
@@ -10,3 +10,4 @@ $wb['fullname_error_notempty'] = 'Nome está vazio.';
$wb['10 - highest'] = '10 - alta';
$wb['5 - medium'] = '5 - média';
$wb['1 - lowest'] = '1 - baixa';
+$wb['inherit_policy'] = '- Herdar configuração de domínio -';
diff --git a/interface/web/mail/lib/lang/ca_spamfilter_users.lng b/interface/web/mail/lib/lang/ca_spamfilter_users.lng
index 9c7d5bbe7a645145c386eb32654ffc0f50bb72cc..a54e84e6080587f2f4a130ef1f530e3cdfbbe63f 100644
--- a/interface/web/mail/lib/lang/ca_spamfilter_users.lng
+++ b/interface/web/mail/lib/lang/ca_spamfilter_users.lng
@@ -10,4 +10,4 @@ $wb['fullname_error_notempty'] = 'The name must not be empty.';
$wb['10 - highest'] = '10 - highest';
$wb['5 - medium'] = '5 - medium';
$wb['1 - lowest'] = '1 - lowest';
-?>
+$wb['inherit_policy'] = '- Inherit domain setting -';
diff --git a/interface/web/mail/lib/lang/cz_spamfilter_users.lng b/interface/web/mail/lib/lang/cz_spamfilter_users.lng
index f2fff323f4a71ebb187aa7f983b7593b7b12bed5..8c66a071440a39562bc05da565acbfe804741971 100644
--- a/interface/web/mail/lib/lang/cz_spamfilter_users.lng
+++ b/interface/web/mail/lib/lang/cz_spamfilter_users.lng
@@ -10,3 +10,4 @@ $wb['fullname_error_notempty'] = 'Jméno nesmí být prázdné.';
$wb['10 - highest'] = '10 - nejvyšší';
$wb['5 - medium'] = '5 - střední';
$wb['1 - lowest'] = '1 - nejnižší';
+$wb['inherit_policy'] = '- Zdědit nastavení od domény -';
diff --git a/interface/web/mail/lib/lang/de_spamfilter_users.lng b/interface/web/mail/lib/lang/de_spamfilter_users.lng
index 9322c804664200e59122b34b0ab1f1e2d57bf722..d6b148cbe3153ab5343b5faaeffd2b925d0693ac 100644
--- a/interface/web/mail/lib/lang/de_spamfilter_users.lng
+++ b/interface/web/mail/lib/lang/de_spamfilter_users.lng
@@ -10,4 +10,4 @@ $wb['fullname_error_notempty'] = 'Der Name darf nicht leer sein.';
$wb['10 - highest'] = '10 - höchste';
$wb['5 - medium'] = '5 - normal';
$wb['1 - lowest'] = '1 - niedrigste';
-?>
+$wb['inherit_policy'] = '- Inherit domain setting -';
diff --git a/interface/web/mail/lib/lang/dk_spamfilter_users.lng b/interface/web/mail/lib/lang/dk_spamfilter_users.lng
index 5b132bc77405cb7d983d9ff638076c44267fa9ca..b6d9a226d0e84031700acdb7e8522fa37975c510 100644
--- a/interface/web/mail/lib/lang/dk_spamfilter_users.lng
+++ b/interface/web/mail/lib/lang/dk_spamfilter_users.lng
@@ -10,4 +10,4 @@ $wb['fullname_error_notempty'] = 'Navn må ikke være tomt.';
$wb['10 - highest'] = '10 - højeste';
$wb['5 - medium'] = '5 - medium';
$wb['1 - lowest'] = '1 - laveste';
-?>
+$wb['inherit_policy'] = '- Inherit domain setting -';
diff --git a/interface/web/mail/lib/lang/el_spamfilter_users.lng b/interface/web/mail/lib/lang/el_spamfilter_users.lng
index b6da2d1e15dc3ea54c0ce3c3d206d80fbd4065c3..fc61aa818dc0ef1d5a0f8ddf64ff703ffaa2b279 100644
--- a/interface/web/mail/lib/lang/el_spamfilter_users.lng
+++ b/interface/web/mail/lib/lang/el_spamfilter_users.lng
@@ -10,4 +10,4 @@ $wb['fullname_error_notempty'] = 'The name must not be empty.';
$wb['10 - highest'] = '10 - highest';
$wb['5 - medium'] = '5 - medium';
$wb['1 - lowest'] = '1 - lowest';
-?>
+$wb['inherit_policy'] = '- Inherit domain setting -';
diff --git a/interface/web/mail/lib/lang/en_spamfilter_users.lng b/interface/web/mail/lib/lang/en_spamfilter_users.lng
index e43b315df6b655a4cc738a77a4a1a328521915f6..05d0ca9bd627de80cdd373cfe5fe80af517ff484 100644
--- a/interface/web/mail/lib/lang/en_spamfilter_users.lng
+++ b/interface/web/mail/lib/lang/en_spamfilter_users.lng
@@ -10,4 +10,4 @@ $wb['fullname_error_notempty'] = 'The name must not be empty.';
$wb['10 - highest'] = '10 - highest';
$wb['5 - medium'] = '5 - medium';
$wb['1 - lowest'] = '1 - lowest';
-?>
\ No newline at end of file
+$wb['inherit_policy'] = '- Inherit domain setting -';
diff --git a/interface/web/mail/lib/lang/es_spamfilter_users.lng b/interface/web/mail/lib/lang/es_spamfilter_users.lng
index c5a5a0f9480cb677df0f003378c94d6594ce933d..575c14a9f4cc5df4d0aa0e8c547bc68303ded332 100644
--- a/interface/web/mail/lib/lang/es_spamfilter_users.lng
+++ b/interface/web/mail/lib/lang/es_spamfilter_users.lng
@@ -10,4 +10,4 @@ $wb['local_txt'] = 'Local';
$wb['policy_id_txt'] = 'Directiva';
$wb['priority_txt'] = 'Prioridad';
$wb['server_id_txt'] = 'Servidor';
-?>
+$wb['inherit_policy'] = '- Inherit domain setting -';
diff --git a/interface/web/mail/lib/lang/fi_spamfilter_users.lng b/interface/web/mail/lib/lang/fi_spamfilter_users.lng
index c4290efbf25f6dce6c23523c2683bcedfec571f5..5c9570d6fb5e7bfb8aa900f23570e9002f23dcda 100644
--- a/interface/web/mail/lib/lang/fi_spamfilter_users.lng
+++ b/interface/web/mail/lib/lang/fi_spamfilter_users.lng
@@ -10,4 +10,4 @@ $wb['fullname_error_notempty'] = 'The name must not be empty.';
$wb['10 - highest'] = '10 - highest';
$wb['5 - medium'] = '5 - medium';
$wb['1 - lowest'] = '1 - lowest';
-?>
+$wb['inherit_policy'] = '- Inherit domain setting -';
diff --git a/interface/web/mail/lib/lang/fr_spamfilter_users.lng b/interface/web/mail/lib/lang/fr_spamfilter_users.lng
index e8936b01833f43adb8057bef19b7d566c153b28d..b87fe87ccb6ae51a8f3a79b63b40129754a3db7c 100644
--- a/interface/web/mail/lib/lang/fr_spamfilter_users.lng
+++ b/interface/web/mail/lib/lang/fr_spamfilter_users.lng
@@ -10,4 +10,4 @@ $wb['fullname_error_notempty'] = 'The name must not be empty.';
$wb['10 - highest'] = '10 - highest';
$wb['5 - medium'] = '5 - medium';
$wb['1 - lowest'] = '1 - lowest';
-?>
+$wb['inherit_policy'] = '- Inherit domain setting -';
diff --git a/interface/web/mail/lib/lang/hr_spamfilter_users.lng b/interface/web/mail/lib/lang/hr_spamfilter_users.lng
index 9969ef421d93ae8f4b78ce8b87074b7d5a76b7f4..9e78310d71d13eb020ebd7855635a255c41c54e2 100644
--- a/interface/web/mail/lib/lang/hr_spamfilter_users.lng
+++ b/interface/web/mail/lib/lang/hr_spamfilter_users.lng
@@ -10,4 +10,4 @@ $wb['fullname_error_notempty'] = 'The name must not be empty.';
$wb['10 - highest'] = '10 - highest';
$wb['5 - medium'] = '5 - medium';
$wb['1 - lowest'] = '1 - lowest';
-?>
+$wb['inherit_policy'] = '- Inherit domain setting -';
diff --git a/interface/web/mail/lib/lang/hu_spamfilter_users.lng b/interface/web/mail/lib/lang/hu_spamfilter_users.lng
index 573d696182d6451da51b202602229b542aa6cb7a..a5097ddbfde5272c06aa6110de2b12809e4b4fd6 100644
--- a/interface/web/mail/lib/lang/hu_spamfilter_users.lng
+++ b/interface/web/mail/lib/lang/hu_spamfilter_users.lng
@@ -10,4 +10,4 @@ $wb['fullname_error_notempty'] = 'The name must not be empty.';
$wb['10 - highest'] = '10 - highest';
$wb['5 - medium'] = '5 - medium';
$wb['1 - lowest'] = '1 - lowest';
-?>
+$wb['inherit_policy'] = '- Inherit domain setting -';
diff --git a/interface/web/mail/lib/lang/id_spamfilter_users.lng b/interface/web/mail/lib/lang/id_spamfilter_users.lng
index f4549c5c46bba8e4afcd30497f0f6b886b253548..4777d33581258ff23d77245ceafde81cb6a0cdab 100644
--- a/interface/web/mail/lib/lang/id_spamfilter_users.lng
+++ b/interface/web/mail/lib/lang/id_spamfilter_users.lng
@@ -10,4 +10,4 @@ $wb['fullname_error_notempty'] = 'The name must not be empty.';
$wb['10 - highest'] = '10 - highest';
$wb['5 - medium'] = '5 - medium';
$wb['1 - lowest'] = '1 - lowest';
-?>
+$wb['inherit_policy'] = '- Inherit domain setting -';
diff --git a/interface/web/mail/lib/lang/it_spamfilter_users.lng b/interface/web/mail/lib/lang/it_spamfilter_users.lng
index cebb20324e774bc92664e93435b23551fee213b1..2f49b05a41afee3b8b92cd7e76918fa3684312fc 100644
--- a/interface/web/mail/lib/lang/it_spamfilter_users.lng
+++ b/interface/web/mail/lib/lang/it_spamfilter_users.lng
@@ -10,4 +10,4 @@ $wb['fullname_error_notempty'] = 'The name must not be vuoto.';
$wb['10 - highest'] = '10 - elevata';
$wb['5 - medium'] = '5 - media';
$wb['1 - lowest'] = '1 - minima';
-?>
+$wb['inherit_policy'] = '- Inherit domain setting -';
diff --git a/interface/web/mail/lib/lang/ja_spamfilter_users.lng b/interface/web/mail/lib/lang/ja_spamfilter_users.lng
index cd212e941845697a470401501d90929af3856203..5272d3f3e1b2de9e3aba322fd76a2cbbbd62560b 100644
--- a/interface/web/mail/lib/lang/ja_spamfilter_users.lng
+++ b/interface/web/mail/lib/lang/ja_spamfilter_users.lng
@@ -10,4 +10,4 @@ $wb['fullname_error_notempty'] = 'The name must not be empty.';
$wb['10 - highest'] = '10 - highest';
$wb['5 - medium'] = '5 - medium';
$wb['1 - lowest'] = '1 - lowest';
-?>
+$wb['inherit_policy'] = '- Inherit domain setting -';
diff --git a/interface/web/mail/lib/lang/nl_spamfilter_users.lng b/interface/web/mail/lib/lang/nl_spamfilter_users.lng
index 697e130b35b684598ec557f33e87614e51ad65b5..b9da8e7e4a56c55e18c2203361dd830f6dbaf113 100644
--- a/interface/web/mail/lib/lang/nl_spamfilter_users.lng
+++ b/interface/web/mail/lib/lang/nl_spamfilter_users.lng
@@ -10,4 +10,4 @@ $wb['fullname_error_notempty'] = 'The name must not be empty.';
$wb['10 - highest'] = '10 - highest';
$wb['5 - medium'] = '5 - medium';
$wb['1 - lowest'] = '1 - lowest';
-?>
+$wb['inherit_policy'] = '- Inherit domain setting -';
diff --git a/interface/web/mail/lib/lang/pl_spamfilter_users.lng b/interface/web/mail/lib/lang/pl_spamfilter_users.lng
index c46589b18d71b76431e6f947bbce3f816432c012..5173099c274b83460b08b8b4416d406f3ddda793 100644
--- a/interface/web/mail/lib/lang/pl_spamfilter_users.lng
+++ b/interface/web/mail/lib/lang/pl_spamfilter_users.lng
@@ -10,4 +10,4 @@ $wb['fullname_error_notempty'] = 'The name must not be empty.';
$wb['10 - highest'] = '10 - highest';
$wb['5 - medium'] = '5 - medium';
$wb['1 - lowest'] = '1 - lowest';
-?>
+$wb['inherit_policy'] = '- Inherit domain setting -';
diff --git a/interface/web/mail/lib/lang/pt_spamfilter_users.lng b/interface/web/mail/lib/lang/pt_spamfilter_users.lng
index 0ee8d37d50dcd22c40f553b7f0c985f2dad521d4..adec31f8a1bac31963273aaa04e4291b99b35378 100644
--- a/interface/web/mail/lib/lang/pt_spamfilter_users.lng
+++ b/interface/web/mail/lib/lang/pt_spamfilter_users.lng
@@ -10,4 +10,4 @@ $wb['fullname_error_notempty'] = 'The name must not be empty.';
$wb['10 - highest'] = '10 - highest';
$wb['5 - medium'] = '5 - medium';
$wb['1 - lowest'] = '1 - lowest';
-?>
+$wb['inherit_policy'] = '- Inherit domain setting -';
diff --git a/interface/web/mail/lib/lang/ro_spamfilter_users.lng b/interface/web/mail/lib/lang/ro_spamfilter_users.lng
index c51b0b8182ce1a943fd625812cd1bf09dc847a37..bdc418c92c9a1627a678a4cb1ae50dbdc2a504f2 100644
--- a/interface/web/mail/lib/lang/ro_spamfilter_users.lng
+++ b/interface/web/mail/lib/lang/ro_spamfilter_users.lng
@@ -10,4 +10,4 @@ $wb['fullname_error_notempty'] = 'The name must not be empty.';
$wb['10 - highest'] = '10 - highest';
$wb['5 - medium'] = '5 - medium';
$wb['1 - lowest'] = '1 - lowest';
-?>
+$wb['inherit_policy'] = '- Inherit domain setting -';
diff --git a/interface/web/mail/lib/lang/ru_spamfilter_users.lng b/interface/web/mail/lib/lang/ru_spamfilter_users.lng
index 8fcfff421b33e42ac4ec30ba3886c6ccb74a0968..238f3b70480914256aa37f4a0ddb98c0550a1e9d 100644
--- a/interface/web/mail/lib/lang/ru_spamfilter_users.lng
+++ b/interface/web/mail/lib/lang/ru_spamfilter_users.lng
@@ -10,4 +10,4 @@ $wb['fullname_error_notempty'] = 'Имя не может быть пустым.'
$wb['10 - highest'] = '10 - сильный';
$wb['5 - medium'] = '5 - средний';
$wb['1 - lowest'] = '1 - слабый';
-?>
+$wb['inherit_policy'] = '- Inherit domain setting -';
diff --git a/interface/web/mail/lib/lang/se_spamfilter_users.lng b/interface/web/mail/lib/lang/se_spamfilter_users.lng
index ba3b60e273cbac87369962e66c4b75f44f9c0d31..ca3fac06c20f3c748f8374a6f135da6d36346dd9 100644
--- a/interface/web/mail/lib/lang/se_spamfilter_users.lng
+++ b/interface/web/mail/lib/lang/se_spamfilter_users.lng
@@ -10,4 +10,4 @@ $wb['fullname_error_notempty'] = 'Fältet för namn kan inte vara tomt.';
$wb['10 - highest'] = '10 - högsta';
$wb['5 - medium'] = '5 - medium';
$wb['1 - lowest'] = '1 - lägsta';
-?>
+$wb['inherit_policy'] = '- Inherit domain setting -';
diff --git a/interface/web/mail/lib/lang/sk_spamfilter_users.lng b/interface/web/mail/lib/lang/sk_spamfilter_users.lng
index 89bc415672edb4dc6fd367015f0560ff3e13e0f9..dfd74a3291eca5b2766e12ab8fd08b8962bef45d 100644
--- a/interface/web/mail/lib/lang/sk_spamfilter_users.lng
+++ b/interface/web/mail/lib/lang/sk_spamfilter_users.lng
@@ -10,4 +10,4 @@ $wb['fullname_error_notempty'] = 'The name must not be empty.';
$wb['10 - highest'] = '10 - highest';
$wb['5 - medium'] = '5 - medium';
$wb['1 - lowest'] = '1 - lowest';
-?>
+$wb['inherit_policy'] = '- Inherit domain setting -';
diff --git a/interface/web/mail/lib/lang/tr_spamfilter_users.lng b/interface/web/mail/lib/lang/tr_spamfilter_users.lng
index 33ef04c610b94444dce3ce0571056630a08278d2..10144b8232ab2bd2116511e2de960160947a2684 100644
--- a/interface/web/mail/lib/lang/tr_spamfilter_users.lng
+++ b/interface/web/mail/lib/lang/tr_spamfilter_users.lng
@@ -10,4 +10,4 @@ $wb['fullname_error_notempty'] = 'Ad boş olamaz.';
$wb['10 - highest'] = '10 - en yüksek';
$wb['5 - medium'] = '5 - orta';
$wb['1 - lowest'] = '1 - en düşük';
-?>
+$wb['inherit_policy'] = '- Inherit domain setting -';
diff --git a/interface/web/mail/mail_domain_del.php b/interface/web/mail/mail_domain_del.php
index bce89695dc53ee1e016aec966a2d5030014b2db9..e4c26399ef110cb0079f6162c0e5ba58f6ce6af4 100644
--- a/interface/web/mail/mail_domain_del.php
+++ b/interface/web/mail/mail_domain_del.php
@@ -80,6 +80,10 @@ class page_action extends tform_actions {
// Delete all spamfilters that belong to this domain
$records = $app->db->queryAllRecords("SELECT id FROM spamfilter_users WHERE email like ?", '%@' . $domain);
foreach($records as $rec) {
+ $wblists = $app->db->queryAllRecords("SELECT wblist_id FROM spamfilter_wblist WHERE rid = ?", $rec['id']);
+ foreach($wblists as $wblist) {
+ $app->db->datalogDelete('spamfilter_wblist', 'wblist_id', $wblist['wblist_id']);
+ }
$app->db->datalogDelete('spamfilter_users', 'id', $rec['id']);
}
diff --git a/interface/web/mail/mail_domain_edit.php b/interface/web/mail/mail_domain_edit.php
index 67a724dbaf04b1f9536aa4196b4617928a138311..48f6eb2e4d5f5ec90bd8f27cec7491147301ec62 100644
--- a/interface/web/mail/mail_domain_edit.php
+++ b/interface/web/mail/mail_domain_edit.php
@@ -190,19 +190,19 @@ class page_action extends tform_actions {
$app->tpl->setVar("domain_module", 0);
}
- // Get the spamfilter policys for the user
+ // Get the spamfilter policies for the user
$tmp_user = $app->db->queryOneRecord("SELECT policy_id FROM spamfilter_users WHERE email = ?", '@' . $this->dataRecord["domain"]);
$sql = "SELECT id, policy_name FROM spamfilter_policy WHERE ".$app->tform->getAuthSQL('r')." ORDER BY policy_name";
- $policys = $app->db->queryAllRecords($sql);
- $policy_select = "";
- if(is_array($policys)) {
- foreach( $policys as $p) {
+ $policies = $app->db->queryAllRecords($sql);
+ $policy_select = "";
+ if(is_array($policies)) {
+ foreach( $policies as $p) {
$selected = ($p["id"] == $tmp_user["policy_id"])?'SELECTED':'';
$policy_select .= "\r\n";
}
}
$app->tpl->setVar("policy", $policy_select);
- unset($policys);
+ unset($policies);
unset($policy_select);
unset($tmp_user);
@@ -257,7 +257,7 @@ class page_action extends tform_actions {
if (!empty($rec['dkim_public'])) $app->tpl->setVar('dns_record', $dns_record, true);
parent::onShowEnd();
- }
+ }
function onSubmit() {
global $app, $conf;
@@ -334,30 +334,30 @@ class page_action extends tform_actions {
// Spamfilter policy
$policy_id = $app->functions->intval($this->dataRecord["policy"]);
- if($policy_id > 0) {
- $tmp_user = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = ?", '@' . $domain);
- if($tmp_user["id"] > 0) {
- // There is already a record that we will update
+ $tmp_user = $app->db->queryOneRecord("SELECT id, policy_id FROM spamfilter_users WHERE email = ?", '@' . $domain);
+ if($tmp_user["id"] > 0) {
+ // There is already a record that we will update
+ if($policy_id != $tmp_user['policy_id']) {
$app->db->datalogUpdate('spamfilter_users', array("policy_id" => $policy_id), 'id', $tmp_user["id"]);
- } else {
- $tmp_domain = $app->db->queryOneRecord("SELECT sys_groupid FROM mail_domain WHERE domain_id = ?", $this->id);
- // We create a new record
- $insert_data = array(
- "sys_userid" => $_SESSION["s"]["user"]["userid"],
- "sys_groupid" => $tmp_domain["sys_groupid"],
- "sys_perm_user" => 'riud',
- "sys_perm_group" => 'riud',
- "sys_perm_other" => '',
- "server_id" => $this->dataRecord["server_id"],
- "priority" => 5,
- "policy_id" => $policy_id,
- "email" => '@' . $domain,
- "fullname" => '@' . $domain,
- "local" => 'Y'
- );
- $app->db->datalogInsert('spamfilter_users', $insert_data, 'id');
- unset($tmp_domain);
}
+ } else {
+ $tmp_domain = $app->db->queryOneRecord("SELECT sys_groupid FROM mail_domain WHERE domain_id = ?", $this->id);
+ // We create a new record
+ $insert_data = array(
+ "sys_userid" => $_SESSION["s"]["user"]["userid"],
+ "sys_groupid" => $tmp_domain["sys_groupid"],
+ "sys_perm_user" => 'riud',
+ "sys_perm_group" => 'riud',
+ "sys_perm_other" => '',
+ "server_id" => $this->dataRecord["server_id"],
+ "priority" => 5,
+ "policy_id" => $policy_id,
+ "email" => '@' . $domain,
+ "fullname" => '@' . $domain,
+ "local" => 'Y'
+ );
+ $app->db->datalogInsert('spamfilter_users', $insert_data, 'id');
+ unset($tmp_domain);
} // endif spamfilter policy
//* create dns-record with dkim-values if the zone exists
@@ -405,46 +405,74 @@ class page_action extends tform_actions {
global $app, $conf;
$domain = $app->functions->idn_encode($this->dataRecord["domain"]);
+ $old_domain = $app->functions->idn_encode($this->oldDataRecord["domain"]);
// Spamfilter policy
$policy_id = $app->functions->intval($this->dataRecord["policy"]);
+
+ // If domain changes, update spamfilter_users
+ // and fire spamfilter_wblist_update events so rspamd files are rewritten
+ $skip_spamfilter_users_update = false;
+ if($old_domain != $domain) {
+ $tmp_old = $app->db->queryOneRecord("SELECT id,fullname FROM spamfilter_users WHERE email = ?", '@' . $old_domain);
+ if($tmp_old['id'] > 0) {
+ $tmp_new = $app->db->queryOneRecord("SELECT id,fullname FROM spamfilter_users WHERE email = ?", '@' . $domain);
+ if($tmp_new['id'] > 0) {
+ // There is a spamfilter_users for both old and new domain, we'll update old wblist entries
+ $tmp_wblist = $app->db->queryAllRecords("SELECT wblist_id FROM spamfilter_wblist WHERE rid = ?", $tmp_old['id']);
+ foreach ($tmp_wblist as $tmp) {
+ $app->db->datalogUpdate('spamfilter_wblist', array('rid' => $tmp_new['id']), 'wblist_id', $tmp['wblist_id']);
+ }
+
+ // now delete old spamfilter_users entry
+ $app->db->datalogDelete('spamfilter_users', 'id', $tmp_old['id']);
+ } else {
+ $update_data = array(
+ 'email' => '@' . $domain,
+ 'policy_id' => $policy_id,
+ );
+ if($tmp_old['fullname'] == '@' . $old_domain) {
+ $update_data['fullname'] = '@' . $domain;
+ }
+ $app->db->datalogUpdate('spamfilter_users', $update_data, 'id', $tmp_old['id']);
+ $skip_spamfilter_users_update = true;
+ }
+ }
+ }
+
$tmp_user = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = ?", '@' . $domain);
- if($policy_id > 0) {
- if($tmp_user["id"] > 0) {
- // There is already a record that we will update
+ if($tmp_user["id"] > 0) {
+ // There is already a record that we will update
+ if((! $skip_spamfilter_users_update) && ($policy_id != $tmp_user['policy_id'])) {
$app->db->datalogUpdate('spamfilter_users', array("policy_id" => $policy_id), 'id', $tmp_user["id"]);
- } else {
- $tmp_domain = $app->db->queryOneRecord("SELECT sys_groupid FROM mail_domain WHERE domain_id = ?", $this->id);
- // We create a new record
- $insert_data = array(
- "sys_userid" => $_SESSION["s"]["user"]["userid"],
- "sys_groupid" => $tmp_domain["sys_groupid"],
- "sys_perm_user" => 'riud',
- "sys_perm_group" => 'riud',
- "sys_perm_other" => '',
- "server_id" => $this->dataRecord["server_id"],
- "priority" => 5,
- "policy_id" => $policy_id,
- "email" => '@' . $domain,
- "fullname" => '@' . $domain,
- "local" => 'Y'
- );
- $app->db->datalogInsert('spamfilter_users', $insert_data, 'id');
- unset($tmp_domain);
}
} else {
- if($tmp_user["id"] > 0) {
- // There is already a record but the user shall have no policy, so we delete it
- $app->db->datalogDelete('spamfilter_users', 'id', $tmp_user["id"]);
- }
+ $tmp_domain = $app->db->queryOneRecord("SELECT sys_groupid FROM mail_domain WHERE domain_id = ?", $this->id);
+ // We create a new record
+ $insert_data = array(
+ "sys_userid" => $_SESSION["s"]["user"]["userid"],
+ "sys_groupid" => $tmp_domain["sys_groupid"],
+ "sys_perm_user" => 'riud',
+ "sys_perm_group" => 'riud',
+ "sys_perm_other" => '',
+ "server_id" => $this->dataRecord["server_id"],
+ "priority" => 5,
+ "policy_id" => $policy_id,
+ "email" => '@' . $domain,
+ "fullname" => '@' . $domain,
+ "local" => 'Y'
+ );
+ $app->db->datalogInsert('spamfilter_users', $insert_data, 'id');
+ unset($tmp_domain);
} // endif spamfilter policy
+
//** If the domain name or owner has been changed, change the domain and owner in all mailbox records
- if($this->oldDataRecord['domain'] != $domain || (isset($this->dataRecord['client_group_id']) && $this->oldDataRecord['sys_groupid'] != $this->dataRecord['client_group_id'])) {
+ if($old_domain != $domain || (isset($this->dataRecord['client_group_id']) && $this->oldDataRecord['sys_groupid'] != $this->dataRecord['client_group_id'])) {
$app->uses('getconf');
$mail_config = $app->getconf->get_server_config($this->dataRecord["server_id"], 'mail');
//* Update the mailboxes
- $mailusers = $app->db->queryAllRecords("SELECT * FROM mail_user WHERE email like ?", '%@' . $this->oldDataRecord['domain']);
+ $mailusers = $app->db->queryAllRecords("SELECT * FROM mail_user WHERE email like ?", '%@' . $old_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 = ?", $sys_groupid);
$client_user_id = $app->functions->intval(($tmp['userid'] > 0)?$tmp['userid']:1);
@@ -455,37 +483,194 @@ class page_action extends tform_actions {
$maildir = str_replace("[domain]", $domain, $mail_config["maildir_path"]);
$maildir = str_replace("[localpart]", $mail_parts[0], $maildir);
$email = $mail_parts[0].'@'.$this->dataRecord['domain'];
- $app->db->datalogUpdate('mail_user', array("maildir" => $maildir, "email" => $email, "sys_userid" => $client_user_id, "sys_groupid" => $sys_groupid), 'mailuser_id', $rec['mailuser_id']);
+ // update spamfilter_users and spamfilter_wblist if email change
+ $skip_spamfilter_users_update = false;
+ if($email != $rec['email']) {
+ $tmp_olduser = $app->db->queryOneRecord("SELECT id,fullname FROM spamfilter_users WHERE email = ?", $rec['email']);
+ if($tmp_olduser['id'] > 0) {
+ $tmp_newuser = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = ?", $email);
+ if($tmp_newuser['id'] > 0) {
+ // There is a spamfilter_users for both old and new email, we'll update old wblist entries
+ $tmp_wblist = $app->db->queryAllRecords("SELECT wblist_id FROM spamfilter_wblist WHERE rid = ?", $tmp_olduser['id']);
+ foreach ($tmp_wblist as $tmp) {
+ $update_data = array(
+ 'rid' => $tmp_newuser['id'],
+ 'sys_userid' => $client_user_id,
+ 'sys_groupid' => $sys_groupid,
+ );
+ $app->db->datalogUpdate('spamfilter_wblist', $update_data, 'wblist_id', $tmp['wblist_id']);
+ }
+
+ // now delete old spamfilter_users entry
+ $app->db->datalogDelete('spamfilter_users', 'id', $tmp_olduser['id']);
+ } else {
+ $update_data = array(
+ 'email' => $mail_parts[0].'@'.$this->dataRecord['domain'],
+ 'sys_userid' => $client_user_id,
+ 'sys_groupid' => $sys_groupid,
+ );
+ if($tmp_olduser['fullname'] == $app->functions->idn_decode($rec['email'])) {
+ $update_data['fullname'] = $app->functions->idn_decode($email);
+ }
+ $app->db->datalogUpdate('spamfilter_users', $update_data, 'id', $tmp_olduser['id']);
+ $skip_spamfilter_users_update = true;
+
+ $tmp_wblist = $app->db->queryAllRecords("SELECT wblist_id FROM spamfilter_wblist WHERE rid = ?", $tmp_olduser['id']);
+ $update_data = array(
+ 'sys_userid' => $client_user_id,
+ 'sys_groupid' => $sys_groupid,
+ );
+ foreach ($tmp_wblist as $tmp) {
+ $app->db->datalogUpdate('spamfilter_wblist', $update_data, 'wblist_id', $tmp['wblist_id']);
+ }
+ }
+ }
+
+ $tmp_user = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = ?", $email);
+ if($tmp_user["id"] > 0) {
+ // There is already a record that we will update
+ if(!$skip_spamfilter_users_update) {
+ $update_data = array(
+ 'sys_userid' => $client_user_id,
+ 'sys_groupid' => $sys_groupid,
+ );
+ $app->db->datalogUpdate('spamfilter_users', $update_data, 'id', $tmp_user['id']);
+ }
+ } else {
+ // We create a new record
+ $insert_data = array(
+ "sys_userid" => $client_user_id,
+ "sys_groupid" => $sys_groupid,
+ "sys_perm_user" => 'riud',
+ "sys_perm_group" => 'riud',
+ "sys_perm_other" => '',
+ "server_id" => $this->dataRecord["server_id"],
+ "priority" => 5,
+ "policy_id" => 0,
+ "email" => $email,
+ "fullname" => $app->functions->idn_decode($email),
+ "local" => 'Y'
+ );
+ $app->db->datalogInsert('spamfilter_users', $insert_data, 'id');
+ }
+
+ $app->db->datalogUpdate('mail_user', array("maildir" => $maildir, "email" => $email, "sys_userid" => $client_user_id, "sys_groupid" => $sys_groupid), 'mailuser_id', $rec['mailuser_id']);
+ }
}
}
//* Update the aliases
- $forwardings = $app->db->queryAllRecords("SELECT * FROM mail_forwarding WHERE source like ? OR destination like ?", '%@' . $this->oldDataRecord['domain'], '%@' . $this->oldDataRecord['domain']);
+ $forwardings = $app->db->queryAllRecords("SELECT * FROM mail_forwarding WHERE source like ? OR destination like ?", '%@' . $old_domain, '%@' . $old_domain);
if(is_array($forwardings)) {
foreach($forwardings as $rec) {
- $destination = str_replace($this->oldDataRecord['domain'], $domain, $rec['destination']);
- $source = str_replace($this->oldDataRecord['domain'], $domain, $rec['source']);
+ $destination = str_replace($old_domain, $domain, $rec['destination']);
+ $source = str_replace($old_domain, $domain, $rec['source']);
+
+ // update spamfilter_users and spamfilter_wblist if source email changes
+ $skip_spamfilter_users_update = false;
+ if(strpos($rec['source'],'@'.$old_domain) && $source != $rec['source']) {
+ $tmp_olduser = $app->db->queryOneRecord("SELECT id,fullname FROM spamfilter_users WHERE email = ?", $rec['source']);
+ if($tmp_olduser['id'] > 0) {
+ $tmp_newuser = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = ?", $source);
+ if($tmp_newuser['id'] > 0) {
+ // There is a spamfilter_users for both old and new email, we'll update old wblist entries
+ $tmp_wblist = $app->db->queryAllRecords("SELECT wblist_id FROM spamfilter_wblist WHERE rid = ?", $tmp_olduser['id']);
+ foreach ($tmp_wblist as $tmp) {
+ $update_data = array(
+ 'rid' => $tmp_newuser['id'],
+ 'sys_userid' => $client_user_id,
+ 'sys_groupid' => $sys_groupid,
+ );
+ $app->db->datalogUpdate('spamfilter_wblist', $update_data, 'wblist_id', $tmp['wblist_id']);
+ }
+
+ // now delete old spamfilter_users entry
+ $app->db->datalogDelete('spamfilter_users', 'id', $tmp_olduser['id']);
+ } else {
+ $update_data = array(
+ 'email' => $source,
+ 'sys_userid' => $client_user_id,
+ 'sys_groupid' => $sys_groupid,
+ );
+ if($tmp_olduser['fullname'] == $app->functions->idn_decode($rec['source'])) {
+ $update_data['fullname'] = $app->functions->idn_decode($source);
+ }
+ $app->db->datalogUpdate('spamfilter_users', $update_data, 'id', $tmp_olduser['id']);
+ $skip_spamfilter_users_update = true;
+
+ $tmp_wblist = $app->db->queryAllRecords("SELECT wblist_id FROM spamfilter_wblist WHERE rid = ?", $tmp_olduser['id']);
+ $update_data = array(
+ 'sys_userid' => $client_user_id,
+ 'sys_groupid' => $sys_groupid,
+ );
+ foreach ($tmp_wblist as $tmp) {
+ $app->db->datalogUpdate('spamfilter_wblist', $update_data, 'wblist_id', $tmp['wblist_id']);
+ }
+ }
+ }
+
+
+ $tmp_user = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = ?", $source);
+ if($tmp_user["id"] > 0) {
+ // There is already a record that we will update
+ if(!$skip_spamfilter_users_update) {
+ $update_data = array(
+ 'sys_userid' => $client_user_id,
+ 'sys_groupid' => $sys_groupid,
+ );
+ $app->db->datalogUpdate('spamfilter_users', $update_data, 'id', $tmp_user['id']);
+ }
+ /*
+ * should we insert spamfilter_users with policy_id = 0 for mail_forwardings?
+ * I think no (see https://git.ispconfig.org/ispconfig/ispconfig3/-/issues/6201)
+ *
+ } else {
+ // We create a new record
+ $insert_data = array(
+ "sys_userid" => $client_user_id,
+ "sys_groupid" => $sys_groupid,
+ "sys_perm_user" => 'riud',
+ "sys_perm_group" => 'riud',
+ "sys_perm_other" => '',
+ "server_id" => $this->dataRecord["server_id"],
+ "priority" => 5,
+ "policy_id" => 0,
+ "email" => $source,
+ "fullname" => $app->functions->idn_decode($source),
+ "local" => 'Y'
+ );
+ $app->db->datalogInsert('spamfilter_users', $insert_data, 'id');
+ */
+ }
+
+ }
+
$app->db->datalogUpdate('mail_forwarding', array("source" => $source, "destination" => $destination, "sys_userid" => $client_user_id, "sys_groupid" => $sys_groupid), 'forwarding_id', $rec['forwarding_id']);
}
}
//* Update the mailinglist
- $app->db->query("UPDATE mail_mailinglist SET sys_userid = ?, sys_groupid = ? WHERE domain = ?", $client_user_id, $sys_groupid, $this->oldDataRecord['domain']);
+ $mailinglists = $app->db->queryAllRecords("SELECT * FROM mail_mailinglist WHERE domain = ?", $old_domain);
+ if(is_array($mailinglists)) {
+ foreach($mailinglists as $rec) {
+ $update_data = array(
+ 'sys_userid' => $client_user_id,
+ 'sys_groupid' => $sys_groupid,
+ 'domain' => $domain,
+ 'email' => str_replace($old_domain, $domain, $rec['email']),
+ );
+ $app->db->datalogUpdate('mail_mailinglist', $update_data, 'mailinglist_id', $rec['mailinglist_id']);
+ }
+ }
//* Update fetchmail accounts
- $fetchmail = $app->db->queryAllRecords("SELECT * FROM mail_get WHERE destination like ?", '%@' . $this->oldDataRecord['domain']);
+ $fetchmail = $app->db->queryAllRecords("SELECT * FROM mail_get WHERE destination like ?", '%@' . $old_domain);
if(is_array($fetchmail)) {
foreach($fetchmail as $rec) {
- $destination = str_replace($this->oldDataRecord['domain'], $domain, $rec['destination']);
+ $destination = str_replace($old_domain, $domain, $rec['destination']);
$app->db->datalogUpdate('mail_get', array("destination" => $destination, "sys_userid" => $client_user_id, "sys_groupid" => $sys_groupid), 'mailget_id', $rec['mailget_id']);
}
}
-
- //* Delete the old spamfilter record
- $tmp = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = ?", '@' . $this->oldDataRecord["domain"]);
- $app->db->datalogDelete('spamfilter_users', 'id', $tmp["id"]);
- unset($tmp);
-
} // end if domain name changed
//* update dns-record when the dkim record was changed
@@ -559,4 +744,3 @@ class page_action extends tform_actions {
$page = new page_action;
$page->onLoad();
-?>
diff --git a/interface/web/mail/mail_user_del.php b/interface/web/mail/mail_user_del.php
index 1f19166ef7c64de361b0bdf0a91d69ddd8403974..d301f5008573892c5c5527907d10de9dbaa1b44d 100644
--- a/interface/web/mail/mail_user_del.php
+++ b/interface/web/mail/mail_user_del.php
@@ -65,6 +65,8 @@ class page_action extends tform_actions {
}
$app->db->datalogDelete('spamfilter_users', 'id', $tmp_user["id"]);
+ // delete mail_forwardings with destination == email ?
+
$tmp_filters = $app->db->queryAllRecords("SELECT filter_id FROM mail_user_filter WHERE mailuser_id = ?", $this->id);
if(is_array($tmp_filters)) {
foreach($tmp_filters as $tmp) {
diff --git a/interface/web/mail/mail_user_edit.php b/interface/web/mail/mail_user_edit.php
index 1dca1db848b93ff78ce9f8c2a9c143579bdf98f7..d8730fa2ebe78c3885af10f785a276e016b7ecfe 100644
--- a/interface/web/mail/mail_user_edit.php
+++ b/interface/web/mail/mail_user_edit.php
@@ -94,20 +94,20 @@ class page_action extends tform_actions {
unset($domains);
unset($domain_select);
- // Get the spamfilter policys for the user
+ // Get the spamfilter policies for the user
$tmp_user = $app->db->queryOneRecord("SELECT policy_id FROM spamfilter_users WHERE email = ?", $this->dataRecord["email"]);
if (isset($_POST['policy'])) $tmp_user['policy_id'] = intval($_POST['policy']);
$sql = "SELECT id, policy_name FROM spamfilter_policy WHERE ".$app->tform->getAuthSQL('r') . " ORDER BY policy_name";
- $policys = $app->db->queryAllRecords($sql);
- $policy_select = "";
- if(is_array($policys)) {
- foreach( $policys as $p) {
+ $policies = $app->db->queryAllRecords($sql);
+ $policy_select = "";
+ if(is_array($policies)) {
+ foreach( $policies as $p) {
$selected = ($p["id"] == $tmp_user["policy_id"])?'SELECTED':'';
$policy_select .= "\r\n";
}
}
$app->tpl->setVar("policy", $policy_select);
- unset($policys);
+ unset($policies);
unset($policy_select);
unset($tmp_user);
@@ -281,42 +281,40 @@ class page_action extends tform_actions {
// Spamfilter policy
$policy_id = $app->functions->intval($this->dataRecord["policy"]);
- if($policy_id > 0) {
- $tmp_user = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = ?", $this->dataRecord["email"]);
- if($tmp_user["id"] > 0) {
- // There is already a record that we will update
+ $tmp_user = $app->db->queryOneRecord("SELECT id, policy_id FROM spamfilter_users WHERE email = ?", $this->dataRecord["email"]);
+ if($tmp_user["id"] > 0) {
+ // There is already a record that we will update
+ if($policy_id != $tmp_user['policy_id']) {
$app->db->datalogUpdate('spamfilter_users', array("policy_id" => $policy_id), 'id', $tmp_user["id"]);
- } else {
- // We create a new record
- $insert_data = array(
- "sys_userid" => $_SESSION["s"]["user"]["userid"],
- "sys_groupid" => $domain["sys_groupid"],
- "sys_perm_user" => 'riud',
- "sys_perm_group" => 'riud',
- "sys_perm_other" => '',
- "server_id" => $domain["server_id"],
- "priority" => 10,
- "policy_id" => $policy_id,
- "email" => $this->dataRecord["email"],
- "fullname" => $app->functions->idn_decode($this->dataRecord["email"]),
- "local" => 'Y'
- );
- $app->db->datalogInsert('spamfilter_users', $insert_data, 'id');
}
- } // endif spamfilter policy
+ } else {
+ // We create a new record
+ $insert_data = array(
+ "sys_userid" => $_SESSION["s"]["user"]["userid"],
+ "sys_groupid" => $domain["sys_groupid"],
+ "sys_perm_user" => 'riud',
+ "sys_perm_group" => 'riud',
+ "sys_perm_other" => '',
+ "server_id" => $domain["server_id"],
+ "priority" => 7,
+ "policy_id" => $policy_id,
+ "email" => $this->dataRecord["email"],
+ "fullname" => $app->functions->idn_decode($this->dataRecord["email"]),
+ "local" => 'Y'
+ );
+ $app->db->datalogInsert('spamfilter_users', $insert_data, 'id');
+ }
// Set the fields for dovecot
- if(isset($this->dataRecord["email"])) {
- $disableimap = ($this->dataRecord["disableimap"])?'y':'n';
- $disablepop3 = ($this->dataRecord["disablepop3"])?'y':'n';
- $disablesmtp = ($this->dataRecord["disablesmtp"])?'y':'n';
- $disabledeliver = ($this->dataRecord["disabledeliver"])?'y':'n';
-
- $app->db->query($sql, $disableimap, $disableimap, $disablepop3, $disablesmtp, $disabledeliver, $disabledeliver, $this->id);
- $sql = "UPDATE mail_user SET disableimap = ?, disablesieve = ?, disablepop3 = ?, disablesmtp = ?, disabledeliver = ?, disablelda = ?, disablelmtp = ? WHERE mailuser_id = ?";
- $app->db->query($sql, $disableimap, $disableimap, $disablepop3, $disablesmtp, $disabledeliver, $disabledeliver, $disabledeliver, $this->id);
- }
+ $disableimap = ($this->dataRecord["disableimap"])?'y':'n';
+ $disablepop3 = ($this->dataRecord["disablepop3"])?'y':'n';
+ $disablesmtp = ($this->dataRecord["disablesmtp"])?'y':'n';
+ $disabledeliver = ($this->dataRecord["disabledeliver"])?'y':'n';
+
+ $app->db->query($sql, $disableimap, $disableimap, $disablepop3, $disablesmtp, $disabledeliver, $disabledeliver, $this->id);
+ $sql = "UPDATE mail_user SET disableimap = ?, disablesieve = ?, disablepop3 = ?, disablesmtp = ?, disabledeliver = ?, disablelda = ?, disablelmtp = ? WHERE mailuser_id = ?";
+ $app->db->query($sql, $disableimap, $disableimap, $disablepop3, $disablesmtp, $disabledeliver, $disabledeliver, $disabledeliver, $this->id);
}
function onAfterUpdate() {
@@ -326,65 +324,104 @@ class page_action extends tform_actions {
if(isset($_POST["email_domain"])) {
$domain = $app->db->queryOneRecord("SELECT sys_groupid, server_id FROM mail_domain WHERE domain = ? AND ".$app->tform->getAuthSQL('r'), $app->functions->idn_encode($_POST["email_domain"]));
$app->db->query("UPDATE mail_user SET sys_groupid = ? WHERE mailuser_id = ?", $domain["sys_groupid"], $this->id);
-
- // Spamfilter policy
- $policy_id = $app->functions->intval($this->dataRecord["policy"]);
- $tmp_user = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = ?", $this->dataRecord["email"]);
- if($policy_id > 0) {
- if($tmp_user["id"] > 0) {
- // There is already a record that we will update
- $app->db->datalogUpdate('spamfilter_users', array("policy_id" => $policy_id), 'id', $tmp_user["id"]);
- } else {
- // We create a new record
- $insert_data = array(
- "sys_userid" => $_SESSION["s"]["user"]["userid"],
- "sys_groupid" => $domain["sys_groupid"],
- "sys_perm_user" => 'riud',
- "sys_perm_group" => 'riud',
- "sys_perm_other" => '',
- "server_id" => $domain["server_id"],
- "priority" => 10,
- "policy_id" => $policy_id,
- "email" => $this->dataRecord["email"],
- "fullname" => $app->functions->idn_decode($this->dataRecord["email"]),
- "local" => 'Y'
- );
- $app->db->datalogInsert('spamfilter_users', $insert_data, 'id');
- }
- }else {
- if($tmp_user["id"] > 0) {
- // There is already a record but the user shall have no policy, so we delete it
- $app->db->datalogDelete('spamfilter_users', 'id', $tmp_user["id"]);
- }
- } // endif spamfilter policy
}
// Set the fields for dovecot
- if(isset($this->dataRecord["email"])) {
- $disableimap = (isset($this->dataRecord["disableimap"]) && $this->dataRecord["disableimap"])?'y':'n';
- $disablepop3 = (isset($this->dataRecord["disablepop3"]) && $this->dataRecord["disablepop3"])?'y':'n';
- $disablesmtp = (isset($this->dataRecord["disablesmtp"]) && $this->dataRecord["disablesmtp"])?'y':'n';
- $disabledeliver = (isset($this->dataRecord["disabledeliver"]) && $this->dataRecord["disabledeliver"])?'y':'n';
-
- $sql = "UPDATE mail_user SET disableimap = ?, disablesieve = ?, `disablesieve-filter` = ?, disablepop3 = ?, disablesmtp = ?, disabledeliver = ?, disablelda = ?, disablelmtp = ? WHERE mailuser_id = ?";
- $app->db->query($sql, $disableimap, $disableimap, $disableimap, $disablepop3, $disablesmtp, $disabledeliver, $disabledeliver, $disabledeliver, $this->id);
- }
+ $disableimap = (isset($this->dataRecord["disableimap"]) && $this->dataRecord["disableimap"])?'y':'n';
+ $disablepop3 = (isset($this->dataRecord["disablepop3"]) && $this->dataRecord["disablepop3"])?'y':'n';
+ $disablesmtp = (isset($this->dataRecord["disablesmtp"]) && $this->dataRecord["disablesmtp"])?'y':'n';
+ $disabledeliver = (isset($this->dataRecord["disabledeliver"]) && $this->dataRecord["disabledeliver"])?'y':'n';
+
+ $sql = "UPDATE mail_user SET disableimap = ?, disablesieve = ?, `disablesieve-filter` = ?, disablepop3 = ?, disablesmtp = ?, disabledeliver = ?, disablelda = ?, disablelmtp = ? WHERE mailuser_id = ?";
+ $app->db->query($sql, $disableimap, $disableimap, $disableimap, $disablepop3, $disablesmtp, $disabledeliver, $disabledeliver, $disabledeliver, $this->id);
+
+ // Spamfilter policy
+ $policy_id = $app->functions->intval($this->dataRecord["policy"]);
+ $skip_spamfilter_users_update = false;
- //** If the email address has been changed, change it in all aliases too
+ //** Handle email address change
if(isset($this->dataRecord['email']) && $this->oldDataRecord['email'] != $this->dataRecord['email']) {
- //if($this->oldDataRecord['email'] != $this->dataRecord['email']) {
+ //** Update spamfilter_users and spamfilter_wblist
+ $tmp_olduser = $app->db->queryOneRecord("SELECT id,fullname FROM spamfilter_users WHERE email = ?", $this->oldDataRecord['email']);
+ if($tmp_olduser["id"] > 0) {
+ $tmp_newuser = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = ?", $this->dataRecord['email']);
+ if($tmp_newuser['id'] > 0) {
+ // There is a spamfilter_users for both old and new email, we'll update old wblist entries
+ $update_data = array(
+ 'rid' => $tmp_newuser['id'],
+ );
+ if (isset($domain['sys_groupid'])) {
+ $update_data['sys_groupid'] = $domain['sys_groupid'];
+ }
+ $tmp_wblist = $app->db->queryAllRecords("SELECT wblist_id FROM spamfilter_wblist WHERE rid = ?", $tmp_olduser['id']);
+ foreach ($tmp_wblist as $tmp) {
+ $app->db->datalogUpdate('spamfilter_wblist', $update_data, 'wblist_id', $tmp['wblist_id']);
+ }
+
+ // now delete old spamfilter_users entry
+ $app->db->datalogDelete('spamfilter_users', 'id', $tmp_olduser['id']);
+
+ // we update spamfilter_users for new id below
+ } else {
+ $update_data = array(
+ 'email' => $this->dataRecord['email'],
+ 'policy_id' => $policy_id,
+ );
+ if (isset($domain['sys_groupid'])) {
+ $update_data['sys_groupid'] = $domain['sys_groupid'];
+ }
+ if($tmp_olduser['fullname'] == $app->functions->idn_decode($this->oldDataRecord['email'])) {
+ $update_data['fullname'] = $app->functions->idn_decode($this->dataRecord['email']);
+ }
+ $app->db->datalogUpdate('spamfilter_users', $update_data, 'id', $tmp_olduser['id']);
+ $skip_spamfilter_users_update = true;
+ }
+ }
//* Update the aliases
$forwardings = $app->db->queryAllRecords("SELECT * FROM mail_forwarding WHERE destination = ?", $this->oldDataRecord['email']);
if(is_array($forwardings)) {
foreach($forwardings as $rec) {
$destination = $this->dataRecord['email'];
- $app->db->datalogUpdate('mail_forwarding', array("destination" => $destination), 'forwarding_id', $rec['forwarding_id']);
+ $update_data = array(
+ 'destination' => $destination,
+ );
+ $app->db->datalogUpdate('mail_forwarding', $update_data, 'forwarding_id', $rec['forwarding_id']);
}
}
} // end if email addess changed
+ $tmp_user = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = ?", $this->dataRecord['email']);
+ if($tmp_user["id"] > 0) {
+ // There is already a record that we will update
+ if(!$skip_spamfilter_users_update) {
+ $update_data = array(
+ 'policy_id' => $policy_id,
+ );
+ if (isset($domain['sys_groupid'])) {
+ $update_data['sys_groupid'] = $domain['sys_groupid'];
+ }
+ $app->db->datalogUpdate('spamfilter_users', $update_data, 'id', $tmp_user['id']);
+ }
+ } else {
+ // We create a new record
+ $insert_data = array(
+ "sys_userid" => $_SESSION["s"]["user"]["userid"],
+ "sys_groupid" => $domain["sys_groupid"],
+ "sys_perm_user" => 'riud',
+ "sys_perm_group" => 'riud',
+ "sys_perm_other" => '',
+ "server_id" => $domain["server_id"],
+ "priority" => 7,
+ "policy_id" => $policy_id,
+ "email" => $this->dataRecord["email"],
+ "fullname" => $app->functions->idn_decode($this->dataRecord["email"]),
+ "local" => 'Y'
+ );
+ $app->db->datalogInsert('spamfilter_users', $insert_data, 'id');
+ }
+
//* Change backup options when user mail backup options have been changed
if(isset($this->dataRecord['backup_interval']) && ($this->dataRecord['backup_interval'] != $this->oldDataRecord['backup_interval'] || $this->dataRecord['backup_copies'] != $this->oldDataRecord['backup_copies'])) {
$backup_interval = $this->dataRecord['backup_interval'];
@@ -401,4 +438,3 @@ class page_action extends tform_actions {
$app->tform_actions = new page_action;
$app->tform_actions->onLoad();
-?>
diff --git a/interface/web/mail/spamfilter_blacklist_edit.php b/interface/web/mail/spamfilter_blacklist_edit.php
index b76334b387728ef65e2daaa350a08ff37645d916..c304dafd2b3767ec966361c82372b5e748776c66 100644
--- a/interface/web/mail/spamfilter_blacklist_edit.php
+++ b/interface/web/mail/spamfilter_blacklist_edit.php
@@ -84,7 +84,7 @@ class page_action extends tform_actions {
}
} // end if user is not admin
- // Select and set the server_id so it matches the server_id of the spa,filter_users record
+ // Select and set the server_id so it matches the server_id of the spamfilter_users record
$tmp = $app->db->queryOneRecord("SELECT server_id FROM spamfilter_users WHERE id = ?", $this->dataRecord["rid"]);
$this->dataRecord["server_id"] = $tmp["server_id"];
unset($tmp);
diff --git a/interface/web/mail/spamfilter_policy_edit.php b/interface/web/mail/spamfilter_policy_edit.php
index 8b15f2fac6637e167a4e266232f1cfb21b4d8c55..e8dd7f74736487f5f105cf345392a5aff2b66796 100644
--- a/interface/web/mail/spamfilter_policy_edit.php
+++ b/interface/web/mail/spamfilter_policy_edit.php
@@ -113,16 +113,9 @@ class page_action extends tform_actions {
// check if this is an email domain
if(substr($spamfilter_user['email'],0,1) == '@') {
$domain = substr($spamfilter_user['email'],1);
- $forwardings = $app->db->queryAllRecords("SELECT * FROM mail_forwarding WHERE source LIKE ? OR destination LIKE ?", "%@" . $domain, "%@" . $domain);
-
- // Force-update aliases and forwards
- if(is_array($forwardings)) {
- foreach($forwardings as $rec) {
- $app->db->datalogUpdate('mail_forwarding', array("source" => $rec['source']), 'forwarding_id', $rec['forwarding_id'],true);
- }
- }
- }
+ // Nothing special to do for a domain
+ }
}
}
}
diff --git a/interface/web/mail/spamfilter_users_edit.php b/interface/web/mail/spamfilter_users_edit.php
index b8bc9316c5fffdadff123f8bbf81ef951275e406..c06e31fc72559f1ea7ad9e4d98d37cbb7fa8236f 100644
--- a/interface/web/mail/spamfilter_users_edit.php
+++ b/interface/web/mail/spamfilter_users_edit.php
@@ -65,6 +65,29 @@ class page_action extends tform_actions {
parent::onShowNew();
}
+ function onShowEnd() {
+ global $app, $conf;
+
+ // Get the spamfilter policies for the user
+ $tmp_user = $app->db->queryOneRecord("SELECT policy_id FROM spamfilter_users WHERE email = ?", $this->dataRecord["email"]);
+ if (isset($_POST['policy_id'])) $tmp_user['policy_id'] = intval($_POST['policy_id']);
+ $sql = "SELECT id, policy_name FROM spamfilter_policy WHERE ".$app->tform->getAuthSQL('r') . " ORDER BY policy_name";
+ $policies = $app->db->queryAllRecords($sql);
+ $policy_select = "";
+ if(is_array($policies)) {
+ foreach( $policies as $p) {
+ $selected = ($p["id"] == $tmp_user["policy_id"])?'SELECTED':'';
+ $policy_select .= "\r\n";
+ }
+ }
+ $app->tpl->setVar("policy_id", $policy_select);
+ unset($policies);
+ unset($policy_select);
+ unset($tmp_user);
+
+ parent::onShowEnd();
+ }
+
function onBeforeUpdate() {
global $app, $conf;
@@ -90,7 +113,7 @@ class page_action extends tform_actions {
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
$client = $app->db->queryOneRecord("SELECT limit_spamfilter_user FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id);
- // Check if the user may add another mailbox.
+ // Check if the user may add another spamfilter user.
if($this->id == 0 && $client["limit_spamfilter_user"] >= 0) {
$tmp = $app->db->queryOneRecord("SELECT count(id) as number FROM spamfilter_users WHERE sys_groupid = ?", $client_group_id);
if($tmp["number"] >= $client["limit_spamfilter_user"]) {
@@ -103,10 +126,21 @@ class page_action extends tform_actions {
parent::onSubmit();
}
+
+ function onAfterUpdate() {
+ global $app, $conf;
+
+ // If email changes fire spamfilter_wblist_update events so rspamd files are rewritten
+ if(isset($this->dataRecord['email']) && $this->oldDataRecord['email'] != $this->dataRecord['email']) {
+ $tmp_wblist = $app->db->queryAllRecords("SELECT wblist_id FROM spamfilter_wblist WHERE rid = ?", $this->dataRecord['id']);
+ foreach ($tmp_wblist as $tmp) {
+ $app->db->datalogUpdate('spamfilter_wblist', array('rid' => $this->dataRecord['id']), 'wblist_id', $tmp['wblist_id']);
+ }
+ }
+ }
+
}
$app->tform_actions = new page_action;
$app->tform_actions->onLoad();
-
-?>
diff --git a/interface/web/mail/spamfilter_whitelist_edit.php b/interface/web/mail/spamfilter_whitelist_edit.php
index a404db0ef1008c7eba45ea9a9be8d7e6951d09bd..bc161e6e554a639ec93a0e669f31cb10503c662a 100644
--- a/interface/web/mail/spamfilter_whitelist_edit.php
+++ b/interface/web/mail/spamfilter_whitelist_edit.php
@@ -84,7 +84,7 @@ class page_action extends tform_actions {
}
} // end if user is not admin
- // Select and set the server_id so it matches the server_id of the spa,filter_users record
+ // Select and set the server_id so it matches the server_id of the spamfilter_users record
$tmp = $app->db->queryOneRecord("SELECT server_id FROM spamfilter_users WHERE id = ?", $this->dataRecord["rid"]);
$this->dataRecord["server_id"] = $tmp["server_id"];
unset($tmp);
diff --git a/interface/web/mailuser/mail_user_spamfilter_edit.php b/interface/web/mailuser/mail_user_spamfilter_edit.php
index 8d1e70ba203c5eaf9603b141ea180561897c8912..2c8759b7954de6304b02a97e45c2dc7e3f450ad9 100644
--- a/interface/web/mailuser/mail_user_spamfilter_edit.php
+++ b/interface/web/mailuser/mail_user_spamfilter_edit.php
@@ -79,32 +79,25 @@ class page_action extends tform_actions {
// Spamfilter policy
$policy_id = $app->functions->intval($this->dataRecord["policy"]);
$tmp_user = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = ?", $rec["email"]);
- if($policy_id > 0) {
- if($tmp_user["id"] > 0) {
- // There is already a record that we will update
- $app->db->datalogUpdate('spamfilter_users', array("policy_id" => $policy_id), 'id', $tmp_user["id"]);
- } else {
- // We create a new record
- $insert_data = array(
- "sys_userid" => $domain["sys_userid"],
- "sys_groupid" => $domain["sys_groupid"],
- "sys_perm_user" => 'riud',
- "sys_perm_group" => 'riud',
- "sys_perm_other" => '',
- "server_id" => $domain["server_id"],
- "priority" => 10,
- "policy_id" => $policy_id,
- "email" => $rec["email"],
- "fullname" => $rec["email"],
- "local" => 'Y'
- );
- $app->db->datalogInsert('spamfilter_users', $insert_data, 'id');
- }
- }else {
- if($tmp_user["id"] > 0) {
- // There is already a record but the user shall have no policy, so we delete it
- $app->db->datalogDelete('spamfilter_users', 'id', $tmp_user["id"]);
- }
+ if($tmp_user["id"] > 0) {
+ // There is already a record that we will update
+ $app->db->datalogUpdate('spamfilter_users', array("policy_id" => $policy_id), 'id', $tmp_user["id"]);
+ } else {
+ // We create a new record
+ $insert_data = array(
+ "sys_userid" => $domain["sys_userid"],
+ "sys_groupid" => $domain["sys_groupid"],
+ "sys_perm_user" => 'riud',
+ "sys_perm_group" => 'riud',
+ "sys_perm_other" => '',
+ "server_id" => $domain["server_id"],
+ "priority" => 7,
+ "policy_id" => $policy_id,
+ "email" => $rec["email"],
+ "fullname" => $rec["email"],
+ "local" => 'Y'
+ );
+ $app->db->datalogInsert('spamfilter_users', $insert_data, 'id');
} // endif spamfilter policy
}
@@ -114,26 +107,25 @@ class page_action extends tform_actions {
$rec = $app->tform->getDataRecord($this->id);
$app->tpl->setVar("email", $app->functions->idn_decode($rec['email']), true);
- // Get the spamfilter policys for the user
+ // Get the spamfilter policies for the user
$tmp_user = $app->db->queryOneRecord("SELECT policy_id FROM spamfilter_users WHERE email = ?", $rec['email']);
$sql = "SELECT id, policy_name FROM spamfilter_policy WHERE ".$app->tform->getAuthSQL('r');
- $policys = $app->db->queryAllRecords($sql);
- $policy_select = "";
- if(is_array($policys)) {
- foreach( $policys as $p) {
+ $policies = $app->db->queryAllRecords($sql);
+ $policy_select = "";
+ if(is_array($policies)) {
+ foreach( $policies as $p) {
$selected = ($p["id"] == $tmp_user["policy_id"])?'SELECTED':'';
$policy_select .= "\r\n";
}
}
$app->tpl->setVar("policy", $policy_select);
- unset($policys);
+ unset($policies);
unset($policy_select);
unset($tmp_user);
parent::onShowEnd();
}
-
}
$app->tform_actions = new page_action;
diff --git a/interface/web/tools/resync.php b/interface/web/tools/resync.php
index ec947421b7bea0044291e94fedb69e3ae82bbd93..0aa6677ac3497d92b95f77377d0243428dbadba7 100644
--- a/interface/web/tools/resync.php
+++ b/interface/web/tools/resync.php
@@ -93,34 +93,34 @@ class page_action extends tform_actions {
if($type == 'mail') {
$server_data = array (
- 'mail_domain' => array (
- 'index_field' => 'domain_id',
- 'server_type' => 'mail',
+ 'mail_domain' => array (
+ 'index_field' => 'domain_id',
+ 'server_type' => 'mail',
'server_id' => $server_id,
- ),
+ ),
'mail_get' => array (
'index_field' => 'mailget_id',
'server_type' => 'mail',
'server_id' => $server_id,
),
- 'mail_mailinglist' => array (
- 'index_field' => 'mailinglist_id',
- 'server_type' => 'mail',
+ 'mail_mailinglist' => array (
+ 'index_field' => 'mailinglist_id',
+ 'server_type' => 'mail',
'server_id' => $server_id,
- ),
- 'mail_user' => array (
- 'index_field' => 'mailuser_id',
- 'server_type' => 'mail',
+ ),
+ 'mail_user' => array (
+ 'index_field' => 'mailuser_id',
+ 'server_type' => 'mail',
'server_id' => $server_id,
),
- 'mail_transport' => array (
- 'index_field' => 'transport_id',
- 'server_type' => 'mail',
+ 'mail_transport' => array (
+ 'index_field' => 'transport_id',
+ 'server_type' => 'mail',
'server_id' => $server_id,
),
- 'mail_relay' => array (
- 'index_field' => 'relay_recipient_id',
- 'server_type' => 'mail',
+ 'mail_relay' => array (
+ 'index_field' => 'relay_recipient_id',
+ 'server_type' => 'mail',
'server_id' => $server_id,
),
);
@@ -129,17 +129,17 @@ class page_action extends tform_actions {
$server_data = array (
'mail_access' => array (
'index_field' => 'access_id',
- 'server_type' => 'mail',
+ 'server_type' => 'mail',
'server_id' => $server_id,
- ),
+ ),
'mail_content_filter' => array (
'index_field' => 'content_filter_id',
- 'server_type' => 'mail',
- ),
+ 'server_type' => 'mail',
+ ),
'mail_user_filter' => array (
'index_field' => 'filter_id',
- 'server_type' => 'mail',
- ),
+ 'server_type' => 'mail',
+ ),
'spamfilter_policy' => array (
'index_field' => 'id',
'server_type' => 'mail',
@@ -158,26 +158,26 @@ class page_action extends tform_actions {
}
if($type == 'web' ) {
$server_data = array (
- 'web_domain' => array (
- 'index_field' => 'domain_id',
- 'server_type' => 'web',
+ 'web_domain' => array (
+ 'index_field' => 'domain_id',
+ 'server_type' => 'web',
'server_id' => $server_id,
- ),
- 'shell_user' => array (
- 'index_field' => 'shell_user_id',
- 'server_type' => 'web',
+ ),
+ 'shell_user' => array (
+ 'index_field' => 'shell_user_id',
+ 'server_type' => 'web',
'server_id' => $server_id,
- ),
- 'cron' => array (
- 'index_field' => 'id',
- 'server_type' => 'cron',
+ ),
+ 'cron' => array (
+ 'index_field' => 'id',
+ 'server_type' => 'cron',
'server_id' => $server_id,
- ),
- 'ftp_user' => array (
- 'index_field' => 'ftp_user_id',
- 'server_type' => 'web',
+ ),
+ 'ftp_user' => array (
+ 'index_field' => 'ftp_user_id',
+ 'server_type' => 'web',
'server_id' => $server_id,
- ),
+ ),
);
}
if($type == 'dns' ) {
@@ -191,11 +191,11 @@ class page_action extends tform_actions {
}
if($type == 'file' ) {
$server_data = array (
- 'webdav_user' => array (
- 'index_field' => 'webdav_user_id',
- 'server_type' => 'file',
+ 'webdav_user' => array (
+ 'index_field' => 'webdav_user_id',
+ 'server_type' => 'file',
'server_id' => $server_id,
- ),
+ ),
);
}
if($type == 'db' ) {
diff --git a/server/lib/classes/cron.d/600-file_cleanup.inc.php b/server/lib/classes/cron.d/600-file_cleanup.inc.php
new file mode 100644
index 0000000000000000000000000000000000000000..765b0910414bc588b59af5148a7112bfcdb139ee
--- /dev/null
+++ b/server/lib/classes/cron.d/600-file_cleanup.inc.php
@@ -0,0 +1,143 @@
+db->queryAllRecords($sql, $server_id);
+ if(is_array($records)) {
+ foreach($records as $rec){
+ $mail_access[$rec['id']] = $rec['id'];
+ }
+ }
+
+ $spamfilter_wblist = array();
+ $sql = "SELECT wblist_id as id FROM spamfilter_wblist WHERE active = 'y' AND server_id = ?";
+ $records = $app->db->queryAllRecords($sql, $server_id);
+ if(is_array($records)) {
+ foreach($records as $rec){
+ $spamfilter_wblist[$rec['id']] = $rec['id'];
+ }
+ }
+
+ $spamfilter_users = array();
+ $sql = "SELECT id FROM spamfilter_users WHERE policy_id != 0 AND server_id = ?";
+ $records = $app->db->queryAllRecords($sql, $server_id);
+ if(is_array($records)) {
+ foreach($records as $rec){
+ $spamfilter_users[$rec['id']] = $rec['id'];
+ }
+ }
+
+ $mail_user = array();
+ $sql = "SELECT mailuser_id as id FROM mail_user WHERE postfix = 'y' AND server_id = ?";
+ $records = $app->db->queryAllRecords($sql, $server_id);
+ if(is_array($records)) {
+ foreach($records as $rec){
+ $mail_user[$rec['id']] = $rec['id'];
+ }
+ }
+
+ $mail_forwarding = array();
+ $sql = "SELECT forwarding_id as id FROM mail_forwarding WHERE active = 'y' AND server_id = ?";
+ $records = $app->db->queryAllRecords($sql, $server_id);
+ if(is_array($records)) {
+ foreach($records as $rec){
+ $mail_forwarding[$rec['id']] = $rec['id'];
+ }
+ }
+
+ foreach (glob('/etc/rspamd/local.d/users/*.conf') as $file) {
+ if($handle = fopen($file, 'r')) {
+ if(($line = fgets($handle)) !== false) {
+ if(preg_match('/^((?:global|spamfilter)_wblist|ispc_(spamfilter_user|mail_user|mail_forwarding))[_-](\d+)\s/', $line, $matches)) {
+ switch($matches[1]) {
+ case 'global_wblist':
+ $remove = isset($mail_access[$matches[3]]) ? false : true;
+ break;
+ case 'spamfilter_wblist':
+ $remove = isset($spamfilter_wblist[$matches[3]]) ? false : true;
+ break;
+ case 'ispc_spamfilter_user':
+ $remove = isset($spamfilter_users[$matches[3]]) ? false : true;
+ break;
+ case 'ispc_mail_user':
+ $remove = isset($mail_user[$matches[3]]) ? false : true;
+ break;
+ case 'ispc_mail_forwarding':
+ $remove = isset($mail_forwarding[$matches[3]]) ? false : true;
+ break;
+ default:
+ $app->log("conf file has unhandled rule naming convention, ignoring: $file", LOGLEVEL_DEBUG);
+ $remove = false;
+ }
+ if($remove) {
+ $app->log("$matches[1] id $matches[3] not found, removing $file", LOGLEVEL_DEBUG);
+ unlink($file);
+ $this->restartServiceDelayed('rspamd', 'reload');
+ }
+ } else {
+ $app->log("conf file has unknown rule naming convention, ignoring: $file", LOGLEVEL_DEBUG);
+ }
+ }
+
+ fclose($handle);
+ }
+ }
+ }
+
+ parent::onRunJob();
+ }
+
+}
+
diff --git a/server/lib/classes/cronjob.inc.php b/server/lib/classes/cronjob.inc.php
index 61d45749a841fb2d8826b0a82dd96588fd816f49..df410042db0c5be4afff122a08747858a42154e1 100644
--- a/server/lib/classes/cronjob.inc.php
+++ b/server/lib/classes/cronjob.inc.php
@@ -43,6 +43,9 @@ class cronjob {
protected $_next_run = null;
private $_running = false;
+ // services for delayed restart/reload
+ private $_delayed_restart_services = array();
+
/** return schedule */
@@ -178,6 +181,12 @@ class cronjob {
global $app, $conf;
if($conf['log_priority'] <= LOGLEVEL_DEBUG) print "Called onAfterRun() for class " . get_class($this) . "\n";
+
+ if(is_array($this->_delayed_restart_services)) {
+ foreach ($this->_delayed_restart_services as $service => $mode) {
+ $this->restartService($service, $mode);
+ }
+ }
}
// child classes may NOT override this!
@@ -188,6 +197,29 @@ class cronjob {
$app->db->query("UPDATE `sys_cron` SET `running` = 0 WHERE `name` = ?", get_class($this));
}
+ // child classes may NOT override this!
+ protected function restartService($service, $action='restart') {
+ global $app;
+
+ $app->uses('system');
+
+ $retval = array('output' => '', 'retval' => 0);
+ if($action == 'reload') {
+ exec($app->system->getinitcommand($service, 'reload').' 2>&1', $retval['output'], $retval['retval']);
+ } else {
+ exec($app->system->getinitcommand($service, 'restart').' 2>&1', $retval['output'], $retval['retval']);
+ }
+ return $retval;
+ }
+
+ // child classes may NOT override this!
+ protected function restartServiceDelayed($service, $action='restart') {
+ $action = ($action == 'reload' ? 'reload' : 'restart');
+
+ if (is_array($this->_delayed_restart_services)) {
+ $this->_delayed_restart_services[$service] = $action;
+ }
+ }
+
}
-?>
diff --git a/server/plugins-available/mail_plugin.inc.php b/server/plugins-available/mail_plugin.inc.php
index 0d2e52c4fcae3042047f4aa68ae338f8912e12d6..2baf07ec7dd07ad69f7203b77924bb166cf1f8f9 100644
--- a/server/plugins-available/mail_plugin.inc.php
+++ b/server/plugins-available/mail_plugin.inc.php
@@ -364,7 +364,7 @@ class mail_plugin {
$app->log('Moved invalid maildir to corrupted Maildirs folder: '.$data['new']['maildir'], LOGLEVEL_WARN);
}
- //* Create the maildir, if it doesn not exist, set permissions, set quota.
+ //* Create the maildir, if it does not exist, set permissions, set quota.
if(!empty($maildomain_path) && !is_dir($maildomain_path.'/new')) {
$app->system->maildirmake($maildomain_path, $user, '', $group);
diff --git a/server/plugins-available/rspamd_plugin.inc.php b/server/plugins-available/rspamd_plugin.inc.php
index 9d34ac8a36fdd6b14a907881623c949067342121..112020deb7119f6c1c99dc018737239dfc148274 100644
--- a/server/plugins-available/rspamd_plugin.inc.php
+++ b/server/plugins-available/rspamd_plugin.inc.php
@@ -243,17 +243,7 @@ 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') {
- $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)) {
+ if(is_file($settings_file)) {
unlink($settings_file);
}
} else {
@@ -265,7 +255,12 @@ class rspamd_plugin {
// get policy for entry
if($type === 'spamfilter_user') {
- $policy = $app->db->queryOneRecord("SELECT * FROM spamfilter_policy WHERE id = ?", intval($data['new']['policy_id']));
+ if (intval($data['new']['policy_id']) > 0) {
+ $policy = $app->db->queryOneRecord("SELECT * FROM spamfilter_policy WHERE id = ?", intval($data['new']['policy_id']));
+ } else {
+ $domain = substr($data['new']['email'], strpos($data['new']['email'], '@'));
+ $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 = ?", $conf['server_id'], $domain);
+ }
$check = $app->db->queryOneRecord('SELECT `greylisting` FROM `mail_user` WHERE `server_id` = ? AND `email` = ? UNION SELECT `greylisting` FROM `mail_forwarding` WHERE `server_id` = ? AND `source` = ? ORDER BY (`greylisting` = ?) DESC', $conf['server_id'], $email_address, $conf['server_id'], $email_address, 'y');
if($check) {
@@ -286,7 +281,7 @@ class rspamd_plugin {
$app->system->mkdirpath($this->users_config_dir);
}
- if(!$this->isValidEmail($app->functions->idn_encode($email_address))) {
+ if((!$this->isValidEmail($app->functions->idn_encode($email_address))) || intval($data['new']['policy_id']) == 0) {
if(is_file($settings_file)) {
unlink($settings_file);
}
@@ -310,11 +305,13 @@ class rspamd_plugin {
} else {
$tpl->setVar('from_email', $app->functions->idn_encode($email_address));
}
+ // unneded? $spamfilter appears unused
$spamfilter = $data[$use_data];
} else {
$tpl->setVar('to_email', $app->functions->idn_encode($email_address));
// need to get matching spamfilter user if any
+ // unneded? $spamfilter appears unused
$spamfilter = $app->db->queryOneRecord('SELECT * FROM spamfilter_users WHERE `email` = ?', $email_address);
}
@@ -399,6 +396,7 @@ class rspamd_plugin {
} else {
$record_id = intval($data['new']['wblist_id']);
$wblist_file = $this->users_config_dir.'spamfilter_wblist_'.$record_id.'.conf';
+
$tmp = $app->db->queryOneRecord("SELECT email FROM spamfilter_users WHERE id = ?", intval($data['new']['rid']));
if($tmp && !empty($tmp)) {
$filter = array(