@@ -327,43 +327,70 @@ function onAfterUpdate() {
327327 $ 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 " ]));
328328 $ app ->db ->query ("UPDATE mail_user SET sys_groupid = ? WHERE mailuser_id = ? " , $ domain ["sys_groupid " ], $ this ->id );
329329
330+ }
331+
332+ // Set the fields for dovecot
333+ if (isset ($ this ->dataRecord ["email " ])) {
334+ $ disableimap = (isset ($ this ->dataRecord ["disableimap " ]) && $ this ->dataRecord ["disableimap " ])?'y ' :'n ' ;
335+ $ disablepop3 = (isset ($ this ->dataRecord ["disablepop3 " ]) && $ this ->dataRecord ["disablepop3 " ])?'y ' :'n ' ;
336+ $ disablesmtp = (isset ($ this ->dataRecord ["disablesmtp " ]) && $ this ->dataRecord ["disablesmtp " ])?'y ' :'n ' ;
337+ $ disabledeliver = (isset ($ this ->dataRecord ["disabledeliver " ]) && $ this ->dataRecord ["disabledeliver " ])?'y ' :'n ' ;
338+
339+ $ sql = "UPDATE mail_user SET disableimap = ?, disablesieve = ?, `disablesieve-filter` = ?, disablepop3 = ?, disablesmtp = ?, disabledeliver = ?, disablelda = ?, disablelmtp = ? WHERE mailuser_id = ? " ;
340+ $ app ->db ->query ($ sql , $ disableimap , $ disableimap , $ disableimap , $ disablepop3 , $ disablesmtp , $ disabledeliver , $ disabledeliver , $ disabledeliver , $ this ->id );
341+ }
342+
343+ //** Handle email address change
344+ if (isset ($ this ->dataRecord ['email ' ]) && $ this ->oldDataRecord ['email ' ] != $ this ->dataRecord ['email ' ]) {
330345 // Spamfilter policy
331346 $ policy_id = $ app ->functions ->intval ($ this ->dataRecord ["policy " ]);
332- // Handle email change
347+
348+ //** Update spamfilter_users and spamfilter_wblist
333349 $ skip_spamfilter_users_update = false ;
334- if (isset ($ this ->dataRecord ['email ' ]) && $ this ->oldDataRecord ['email ' ] != $ this ->dataRecord ['email ' ]) {
335- $ tmp_olduser = $ app ->db ->queryOneRecord ("SELECT id,fullname FROM spamfilter_users WHERE email = ? " , $ this ->oldDataRecord ['email ' ]);
336- if ($ tmp_olduser ["id " ] > 0 ) {
337- $ tmp_newuser = $ app ->db ->queryOneRecord ("SELECT id FROM spamfilter_users WHERE email = ? " , $ this ->dataRecord ['email ' ]);
338- if ($ tmp_newuser ['id ' ] > 0 ) {
339- // There is a spamfilter_users for both old and new email, we'll update old wblist entries
340- $ tmp_wblist = $ app ->db ->queryAllRecords ("SELECT wblist_id FROM spamfilter_users WHERE rid = ? " , $ tmp_olduser ['id ' ]);
341- foreach ($ tmp_wblist as $ tmp ) {
342- $ app ->db ->datalogUpdate ('spamfilter_wblist ' , array ('rid ' => $ tmp_newuser ['id ' ]), 'wblist_id ' , $ tmp ['wblist_id ' ]);
343- }
350+ $ tmp_olduser = $ app ->db ->queryOneRecord ("SELECT id,fullname FROM spamfilter_users WHERE email = ? " , $ this ->oldDataRecord ['email ' ]);
351+ if ($ tmp_olduser ["id " ] > 0 ) {
352+ $ tmp_newuser = $ app ->db ->queryOneRecord ("SELECT id FROM spamfilter_users WHERE email = ? " , $ this ->dataRecord ['email ' ]);
353+ if ($ tmp_newuser ['id ' ] > 0 ) {
354+ // There is a spamfilter_users for both old and new email, we'll update old wblist entries
355+ $ update_date = array ('rid ' => $ tmp_newuser ['id ' ]);
356+ if (isset ($ domain ['sys_groupid ' ])) {
357+ $ update_data ['sys_groupid ' ] = $ domain ['sys_groupid ' ];
358+ }
359+ $ tmp_wblist = $ app ->db ->queryAllRecords ("SELECT wblist_id FROM spamfilter_users WHERE rid = ? " , $ tmp_olduser ['id ' ]);
360+ foreach ($ tmp_wblist as $ tmp ) {
361+ $ app ->db ->datalogUpdate ('spamfilter_wblist ' , $ update_data , 'wblist_id ' , $ tmp ['wblist_id ' ]);
362+ }
344363
345- // now delete old spamfilter_users entry
346- $ app ->db ->datalogDelete ('spamfilter_users ' , 'id ' , $ tmp_olduser ['id ' ]);
347- } else {
348- $ update_data = array (
349- 'email ' => $ this ->dataRecord ['email ' ],
350- 'policy_id ' => $ policy_id ,
351- );
352- if ( $ tmp_olduser [ ' fullname ' ] == $ app -> functions -> idn_decode ( $ this -> oldDataRecord [ " email " ])) {
353- $ update_data ['fullname ' ] = $ app -> functions -> idn_decode ( $ this -> dataRecord [ " email " ]) ;
354- }
355- $ app ->db -> datalogUpdate ( ' spamfilter_users ' , $ update_data , ' id ' , $ tmp_olduser [ ' id ' ]);
356- $ skip_spamfilter_users_update = true ;
364+ // now delete old spamfilter_users entry
365+ $ app ->db ->datalogDelete ('spamfilter_users ' , 'id ' , $ tmp_olduser ['id ' ]);
366+ } else {
367+ $ update_data = array (
368+ 'email ' => $ this ->dataRecord ['email ' ],
369+ 'policy_id ' => $ policy_id ,
370+ );
371+ if ( isset ( $ domain [ ' sys_groupid ' ])) {
372+ $ update_data ['sys_groupid ' ] = $ domain [ ' sys_groupid ' ] ;
373+ }
374+ if ( $ tmp_olduser [ ' fullname ' ] == $ app ->functions -> idn_decode ( $ this -> oldDataRecord [ ' email ' ])) {
375+ $ update_data [ ' fullname ' ] = $ app -> functions -> idn_decode ( $ this -> dataRecord [ ' email ' ]) ;
357376 }
377+ $ app ->db ->datalogUpdate ('spamfilter_users ' , $ update_data , 'id ' , $ tmp_olduser ['id ' ]);
378+ $ skip_spamfilter_users_update = true ;
358379 }
359380 }
360381
361- $ tmp_user = $ app ->db ->queryOneRecord ("SELECT id FROM spamfilter_users WHERE email = ? " , $ this ->dataRecord [" email " ]);
382+ $ tmp_user = $ app ->db ->queryOneRecord ("SELECT id FROM spamfilter_users WHERE email = ? " , $ this ->dataRecord [' email ' ]);
362383 if ($ policy_id > 0 ) {
363384 if ($ tmp_user ["id " ] > 0 ) {
364385 // There is already a record that we will update
365386 if (!$ skip_spamfilter_users_update ) {
366- $ app ->db ->datalogUpdate ('spamfilter_users ' , array ("policy_id " => $ policy_id ), 'id ' , $ tmp_user ["id " ]);
387+ $ update_data = array (
388+ 'policy_id ' => $ policy_id ,
389+ );
390+ if (isset ($ domain ['sys_groupid ' ])) {
391+ $ update_data ['sys_groupid ' ] = $ domain ['sys_groupid ' ];
392+ }
393+ $ app ->db ->datalogUpdate ('spamfilter_users ' , $ update_data , 'id ' , $ tmp_user ['id ' ]);
367394 }
368395 } else {
369396 // We create a new record
@@ -390,27 +417,19 @@ function onAfterUpdate() {
390417 $ app ->db ->datalogDelete ('spamfilter_users ' , 'id ' , $ tmp_user ["id " ]);
391418 }
392419 } // endif spamfilter policy
393- }
394-
395- // Set the fields for dovecot
396- if (isset ($ this ->dataRecord ["email " ])) {
397- $ disableimap = (isset ($ this ->dataRecord ["disableimap " ]) && $ this ->dataRecord ["disableimap " ])?'y ' :'n ' ;
398- $ disablepop3 = (isset ($ this ->dataRecord ["disablepop3 " ]) && $ this ->dataRecord ["disablepop3 " ])?'y ' :'n ' ;
399- $ disablesmtp = (isset ($ this ->dataRecord ["disablesmtp " ]) && $ this ->dataRecord ["disablesmtp " ])?'y ' :'n ' ;
400- $ disabledeliver = (isset ($ this ->dataRecord ["disabledeliver " ]) && $ this ->dataRecord ["disabledeliver " ])?'y ' :'n ' ;
401420
402- $ sql = "UPDATE mail_user SET disableimap = ?, disablesieve = ?, `disablesieve-filter` = ?, disablepop3 = ?, disablesmtp = ?, disabledeliver = ?, disablelda = ?, disablelmtp = ? WHERE mailuser_id = ? " ;
403- $ app ->db ->query ($ sql , $ disableimap , $ disableimap , $ disableimap , $ disablepop3 , $ disablesmtp , $ disabledeliver , $ disabledeliver , $ disabledeliver , $ this ->id );
404- }
405-
406- //** If the email address has been changed, change it in all aliases too
407- if (isset ($ this ->dataRecord ['email ' ]) && $ this ->oldDataRecord ['email ' ] != $ this ->dataRecord ['email ' ]) {
408421 //* Update the aliases
409422 $ forwardings = $ app ->db ->queryAllRecords ("SELECT * FROM mail_forwarding WHERE destination = ? " , $ this ->oldDataRecord ['email ' ]);
410423 if (is_array ($ forwardings )) {
411424 foreach ($ forwardings as $ rec ) {
412425 $ destination = $ this ->dataRecord ['email ' ];
413- $ app ->db ->datalogUpdate ('mail_forwarding ' , array ("destination " => $ destination ), 'forwarding_id ' , $ rec ['forwarding_id ' ]);
426+ $ update_data = array (
427+ 'destination ' => $ destination ,
428+ );
429+ if (isset ($ domain ['sys_groupid ' ])) {
430+ $ update_data ['sys_groupid ' ] = $ domain ['sys_groupid ' ];
431+ }
432+ $ app ->db ->datalogUpdate ('mail_forwarding ' , $ update_data , 'forwarding_id ' , $ rec ['forwarding_id ' ]);
414433 }
415434 }
416435
0 commit comments