@@ -94,6 +94,12 @@ function user_insert($event_name,$data) {
9494 exec ("su -c 'mkdir -p " .escapeshellcmd ($ base_path )."' " .$ mail_config ['mailuser_name ' ]);
9595 $ app ->log ('Created Directory: ' .$ base_path ,LOGLEVEL_DEBUG );
9696 }
97+
98+ //* When the mail user dir exists but it is not a valid maildir, remove it
99+ if (!empty ($ maildomain_path ) && is_dir ($ maildomain_path ) && !is_dir ($ maildomain_path .'/new ' ) && !is_dir ($ maildomain_path .'/cur ' )) {
100+ exec ("su -c 'rm -rf " .escapeshellcmd ($ data ['new ' ]['maildir ' ])."' vmail " );
101+ $ app ->log ("Removed invalid maildir and rebuild it: " .escapeshellcmd ($ data ['new ' ]['maildir ' ]),LOGLEVEL_WARN );
102+ }
97103
98104 //* Create the maildir, if it doesn not exist, set permissions, set quota.
99105 if (!empty ($ maildomain_path ) && !is_dir ($ maildomain_path )) {
@@ -106,7 +112,7 @@ function user_insert($event_name,$data) {
106112 }
107113
108114 //* Set the maildir quota
109- if (is_dir ($ data ['new ' ]['maildir ' ].'new ' )) {
115+ if (is_dir ($ data ['new ' ]['maildir ' ].'/ new ' )) {
110116 exec ("su -c 'maildirmake -q " .$ data ['new ' ]['quota ' ]."S " .escapeshellcmd ($ data ['new ' ]['maildir ' ])."' " .$ mail_config ['mailuser_name ' ]);
111117 $ app ->log ('Set Maildir quota: ' ."su -c 'maildirmake -q " .$ data ['new ' ]['quota ' ]."S " .escapeshellcmd ($ data ['new ' ]['maildir ' ])."' " .$ mail_config ['mailuser_name ' ],LOGLEVEL_DEBUG );
112118 }
@@ -139,15 +145,22 @@ function user_update($event_name,$data) {
139145 exec ("su -c 'mkdir -p " .escapeshellcmd ($ base_path )."' " .$ mail_config ['mailuser_name ' ]);
140146 $ app ->log ('Created Directory: ' .$ base_path ,LOGLEVEL_DEBUG );
141147 }
148+
149+ //* When the mail user dir exists but it is not a valid maildir, remove it
150+ if (!empty ($ maildomain_path ) && is_dir ($ maildomain_path ) && !is_dir ($ maildomain_path .'/new ' ) && !is_dir ($ maildomain_path .'/cur ' )) {
151+ exec ("su -c 'rm -rf " .escapeshellcmd ($ data ['new ' ]['maildir ' ])."' vmail " );
152+ $ app ->log ("Removed invalid maildir and rebuild it: " .escapeshellcmd ($ data ['new ' ]['maildir ' ]),LOGLEVEL_WARN );
153+ }
142154
143155 //* Create the maildir, if it doesn not exist, set permissions, set quota.
144- if (!empty ($ maildomain_path ) && !is_dir ($ maildomain_path .'new ' )) {
156+ if (!empty ($ maildomain_path ) && !is_dir ($ maildomain_path .'/ new ' )) {
145157 exec ("su -c 'maildirmake " .escapeshellcmd ($ maildomain_path )."' " .$ mail_config ['mailuser_name ' ]);
158+ $ app ->log ("Created Maildir " ."su -c 'maildirmake " .escapeshellcmd ($ maildomain_path )."' " .$ mail_config ['mailuser_name ' ],LOGLEVEL_DEBUG );
146159 exec ('chown -R ' .$ mail_config ['mailuser_name ' ].': ' .$ mail_config ['mailuser_group ' ].' ' .escapeshellcmd ($ data ['new ' ]['maildir ' ]));
147160 $ app ->log ("Set ownership on " .escapeshellcmd ($ data ['new ' ]['maildir ' ]),LOGLEVEL_DEBUG );
148161 //* This is to fix the maildrop quota not being rebuilt after the quota is changed.
149162 exec ("su -c 'maildirmake -q " .$ data ['new ' ]['quota ' ]."S " .escapeshellcmd ($ maildomain_path )."' " .$ mail_config ['mailuser_name ' ]); // Avoid maildirmake quota bug, see debian bug #214911
150- $ app ->log ('Created Maildir: ' ."su -c 'maildirmake -q " .$ data ['new ' ]['quota ' ]."S " .escapeshellcmd ($ maildomain_path )."' " .$ mail_config ['mailuser_name ' ],LOGLEVEL_DEBUG );
163+ $ app ->log ('Updated Maildir quota : ' ."su -c 'maildirmake -q " .$ data ['new ' ]['quota ' ]."S " .escapeshellcmd ($ maildomain_path )."' " .$ mail_config ['mailuser_name ' ],LOGLEVEL_DEBUG );
151164 }
152165
153166 // Move mailbox, if domain has changed and delete old mailbox
@@ -163,9 +176,9 @@ function user_update($event_name,$data) {
163176 $ app ->log ('Moved Maildir from: ' .$ data ['old ' ]['maildir ' ].' to ' .$ data ['new ' ]['maildir ' ],LOGLEVEL_DEBUG );
164177 }
165178 //This is to fix the maildrop quota not being rebuilt after the quota is changed.
166- if (is_dir ($ data ['new ' ]['maildir ' ].'new ' )) {
179+ if (is_dir ($ data ['new ' ]['maildir ' ].'/ new ' )) {
167180 exec ("su -c 'maildirmake -q " .$ data ['new ' ]['quota ' ]."S " .escapeshellcmd ($ data ['new ' ]['maildir ' ])."' " .$ mail_config ['mailuser_name ' ]);
168- $ app ->log ('Created Maildir: ' ."su -c 'maildirmake -q " .$ data ['new ' ]['quota ' ]."S " .escapeshellcmd ($ data ['new ' ]['maildir ' ])."' " .$ mail_config ['mailuser_name ' ],LOGLEVEL_DEBUG );
181+ $ app ->log ('Updated Maildir quota : ' ."su -c 'maildirmake -q " .$ data ['new ' ]['quota ' ]."S " .escapeshellcmd ($ data ['new ' ]['maildir ' ])."' " .$ mail_config ['mailuser_name ' ],LOGLEVEL_DEBUG );
169182 }
170183 }
171184
0 commit comments