Skip to content

Commit 090607b

Browse files
author
Till Brehm
committed
Fixes #5410 rspamd mail aliases don't get updated when policy is changed
1 parent 81e8ec2 commit 090607b

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

interface/lib/plugins/mail_mail_domain_plugin.inc.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@ function mail_mail_domain_edit($event_name, $page_form) {
116116
$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']);
117117

118118
} // end if domain name changed
119+
120+
//* Force-update the aliases (required for spamfilter changes)
121+
$forwardings = $app->db->queryAllRecords("SELECT * FROM mail_forwarding WHERE source LIKE ? OR destination LIKE ?", "%@" . $domain, "%@" . $domain);
122+
123+
if(is_array($forwardings)) {
124+
foreach($forwardings as $rec) {
125+
$app->db->datalogUpdate('mail_forwarding', array("source" => $rec['source']), 'forwarding_id', $rec['forwarding_id'],true);
126+
}
127+
}
128+
119129
}
120130

121131
}

interface/web/mail/spamfilter_policy_edit.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,20 @@ function onAfterUpdate() {
105105
if(is_array($spamfilter_users) && !empty($spamfilter_users)){
106106
foreach($spamfilter_users as $spamfilter_user){
107107
$app->db->datalogUpdate('spamfilter_users', $spamfilter_user, 'id', $spamfilter_user["id"], true);
108+
109+
// check if this is an email domain
110+
if(substr($spamfilter_user['email'],0,1) == '@') {
111+
$domain = substr($spamfilter_user['email'],1);
112+
$forwardings = $app->db->queryAllRecords("SELECT * FROM mail_forwarding WHERE source LIKE ? OR destination LIKE ?", "%@" . $domain, "%@" . $domain);
113+
114+
// Force-update aliases and forwards
115+
if(is_array($forwardings)) {
116+
foreach($forwardings as $rec) {
117+
$app->db->datalogUpdate('mail_forwarding', array("source" => $rec['source']), 'forwarding_id', $rec['forwarding_id'],true);
118+
}
119+
}
120+
}
121+
108122
}
109123
}
110124
}

0 commit comments

Comments
 (0)