@@ -107,10 +107,11 @@ function user_insert($event_name, $data) {
107107 $ maildomain_path .= '/Maildir ' ;
108108 }
109109
110- //* When the mail user dir exists but it is not a valid maildir, remove it
110+ //* When the mail user dir exists but it is not a valid maildir, move it to corrupted maildir folder
111111 if (!empty ($ maildomain_path ) && is_dir ($ maildomain_path ) && !is_dir ($ maildomain_path .'/new ' ) && !is_dir ($ maildomain_path .'/cur ' )) {
112- exec ("su -c 'rm -rf " .escapeshellcmd ($ data ['new ' ]['maildir ' ])."' vmail " );
113- $ app ->log ('Removed invalid maildir and rebuild it: ' .escapeshellcmd ($ data ['new ' ]['maildir ' ]), LOGLEVEL_WARN );
112+ if (!is_dir ($ mail_config ['homedir_path ' ].'/corrupted/ ' .$ data ['new ' ]['mailuser_id ' ])) $ app ->system ->mkdirpath ($ mail_config ['homedir_path ' ].'/corrupted/ ' .$ data ['new ' ]['mailuser_id ' ], 0700 , $ mail_config ['mailuser_name ' ], $ mail_config ['mailuser_group ' ]);
113+ exec ("su -c 'mv -f " .escapeshellcmd ($ data ['new ' ]['maildir ' ])." " .$ mail_config ['homedir_path ' ].'/corrupted/ ' .$ data ['new ' ]['mailuser_id ' ]."' vmail " );
114+ $ app ->log ('Moved invalid maildir to corrupted Maildirs folder: ' .escapeshellcmd ($ data ['new ' ]['maildir ' ]), LOGLEVEL_WARN );
114115 }
115116
116117 //* Create the maildir, if it doesn not exist, set permissions, set quota.
@@ -238,10 +239,11 @@ function user_update($event_name, $data) {
238239 $ maildomain_path .= '/Maildir ' ;
239240 }
240241
241- //* When the mail user dir exists but it is not a valid maildir, remove it
242+ //* When the mail user dir exists but it is not a valid maildir, move it to corrupted maildir folder
242243 if (!empty ($ maildomain_path ) && is_dir ($ maildomain_path ) && !is_dir ($ maildomain_path .'/new ' ) && !is_dir ($ maildomain_path .'/cur ' )) {
243- exec ("su -c 'rm -rf " .escapeshellcmd ($ data ['new ' ]['maildir ' ])."' vmail " );
244- $ app ->log ('Removed invalid maildir and rebuild it: ' .escapeshellcmd ($ data ['new ' ]['maildir ' ]), LOGLEVEL_WARN );
244+ if (!is_dir ($ mail_config ['homedir_path ' ].'/corrupted/ ' .$ data ['new ' ]['mailuser_id ' ])) $ app ->system ->mkdirpath ($ mail_config ['homedir_path ' ].'/corrupted/ ' .$ data ['new ' ]['mailuser_id ' ], 0700 , $ mail_config ['mailuser_name ' ], $ mail_config ['mailuser_group ' ]);
245+ exec ("su -c 'mv -f " .escapeshellcmd ($ data ['new ' ]['maildir ' ])." " .$ mail_config ['homedir_path ' ].'/corrupted/ ' .$ data ['new ' ]['mailuser_id ' ]."' vmail " );
246+ $ app ->log ('Moved invalid maildir to corrupted Maildirs folder: ' .escapeshellcmd ($ data ['new ' ]['maildir ' ]), LOGLEVEL_WARN );
245247 }
246248
247249 //* Create the maildir, if it doesn not exist, set permissions, set quota.
0 commit comments