@@ -280,14 +280,14 @@ function onAfterUpdate() {
280280 $ app ->db ->datalogDelete ('spamfilter_users ' , 'id ' , $ tmp_user ["id " ]);
281281 }
282282 } // endif spamfilter policy
283-
284- //** If the domain name has been changed, change the domain in all mailbox records
285- if ($ this ->oldDataRecord ['domain ' ] != $ this ->dataRecord ['domain ' ]) {
283+ //** If the domain name or owner has been changed, change the domain and owner in all mailbox records
284+ if ($ this ->oldDataRecord ['domain ' ] != $ this ->dataRecord ['domain ' ] || (isset ($ this ->dataRecord ['client_group_id ' ]) && $ this ->oldDataRecord ['sys_groupid ' ] != $ this ->dataRecord ['client_group_id ' ])) {
286285 $ app ->uses ('getconf ' );
287286 $ mail_config = $ app ->getconf ->get_server_config ($ this ->dataRecord ["server_id " ],'mail ' );
288287
289288 //* Update the mailboxes
290289 $ mailusers = $ app ->db ->queryAllRecords ("SELECT * FROM mail_user WHERE email like '%@ " .mysql_real_escape_string ($ this ->oldDataRecord ['domain ' ])."' " );
290+ $ sys_groupid = (isset ($ this ->dataRecord ['client_group_id ' ]))?$ this ->dataRecord ['client_group_id ' ]:$ this ->oldDataRecord ['sys_groupid ' ];
291291 if (is_array ($ mailusers )) {
292292 foreach ($ mailusers as $ rec ) {
293293 // setting Maildir, Homedir, UID and GID
@@ -296,7 +296,7 @@ function onAfterUpdate() {
296296 $ maildir = str_replace ("[localpart] " ,$ mail_parts [0 ],$ maildir );
297297 $ maildir = mysql_real_escape_string ($ maildir );
298298 $ email = mysql_real_escape_string ($ mail_parts [0 ].'@ ' .$ this ->dataRecord ['domain ' ]);
299- $ app ->db ->datalogUpdate ('mail_user ' , "maildir = ' $ maildir', email = ' $ email' " , 'mailuser_id ' , $ rec ['mailuser_id ' ]);
299+ $ app ->db ->datalogUpdate ('mail_user ' , "maildir = ' $ maildir', email = ' $ email', sys_groupid = ' $ sys_groupid ' " , 'mailuser_id ' , $ rec ['mailuser_id ' ]);
300300 }
301301 }
302302
@@ -306,7 +306,7 @@ function onAfterUpdate() {
306306 foreach ($ forwardings as $ rec ) {
307307 $ destination = mysql_real_escape_string (str_replace ($ this ->oldDataRecord ['domain ' ],$ this ->dataRecord ['domain ' ],$ rec ['destination ' ]));
308308 $ source = mysql_real_escape_string (str_replace ($ this ->oldDataRecord ['domain ' ],$ this ->dataRecord ['domain ' ],$ rec ['source ' ]));
309- $ app ->db ->datalogUpdate ('mail_forwarding ' , "source = ' $ source', destination = ' $ destination' " , 'forwarding_id ' , $ rec ['forwarding_id ' ]);
309+ $ app ->db ->datalogUpdate ('mail_forwarding ' , "source = ' $ source', destination = ' $ destination', sys_groupid = ' $ sys_groupid ' " , 'forwarding_id ' , $ rec ['forwarding_id ' ]);
310310 }
311311 }
312312
0 commit comments