@@ -221,6 +221,8 @@ function onAfterUpdate() {
221221 if ($ this ->oldDataRecord ['domain ' ] != $ this ->dataRecord ['domain ' ]) {
222222 $ app ->uses ('getconf ' );
223223 $ mail_config = $ app ->getconf ->get_server_config ($ this ->dataRecord ["server_id " ],'mail ' );
224+
225+ //* Update the mailboxes
224226 $ mailusers = $ app ->db ->queryAllRecords ("SELECT * FROM mail_user WHERE email like '%@ " .addslashes ($ this ->oldDataRecord ['domain ' ])."' " );
225227 if (is_array ($ mailusers )) {
226228 foreach ($ mailusers as $ rec ) {
@@ -229,11 +231,21 @@ function onAfterUpdate() {
229231 $ maildir = str_replace ("[domain] " ,$ this ->dataRecord ['domain ' ],$ mail_config ["maildir_path " ]);
230232 $ maildir = str_replace ("[localpart] " ,$ mail_parts [0 ],$ maildir );
231233 $ maildir = addslashes ($ maildir );
232- //$app->db->query("UPDATE mail_user SET maildir = '$maildir' WHERE mailuser_id = ".$rec['mailuser_id']);
233- //$rec_new = $app->db->queryOneRecord("SELECT * FROM mail_user WHERE mailuser_id = ".$rec['mailuser_id']);
234- $ app ->db ->datalogUpdate ('mail_user ' , "maildir = ' $ maildir' " , 'mailuser_id ' , $ rec ['mailuser_id ' ]);
234+ $ email = addslashes ($ mail_parts [0 ].'@ ' .$ this ->dataRecord ['domain ' ]);
235+ $ app ->db ->datalogUpdate ('mail_user ' , "maildir = ' $ maildir', email = ' $ email' " , 'mailuser_id ' , $ rec ['mailuser_id ' ]);
235236 }
236237 }
238+
239+ //* Update the aliases
240+ $ forwardings = $ app ->db ->queryAllRecords ("SELECT * FROM mail_forwarding WHERE source like '%@ " .addslashes ($ this ->oldDataRecord ['domain ' ])."' OR destination like '%@ " .addslashes ($ this ->oldDataRecord ['domain ' ])."' " );
241+ if (is_array ($ forwardings )) {
242+ foreach ($ forwardings as $ rec ) {
243+ $ destination = addslashes (str_replace ($ this ->oldDataRecord ['domain ' ],$ this ->dataRecord ['domain ' ],$ rec ['destination ' ]));
244+ $ source = addslashes (str_replace ($ this ->oldDataRecord ['domain ' ],$ this ->dataRecord ['domain ' ],$ rec ['source ' ]));
245+ $ app ->db ->datalogUpdate ('mail_forwarding ' , "source = ' $ source', destination = ' $ destination' " , 'forwarding_id ' , $ rec ['forwarding_id ' ]);
246+ }
247+ }
248+
237249 } // end if domain name changed
238250
239251 }
0 commit comments