@@ -130,74 +130,67 @@ function user_insert($event_name, $data) {
130130 $ app ->log ('Created Directory: ' .$ base_path , LOGLEVEL_DEBUG );
131131 }
132132
133- // Dovecot can create its Maildir on its own and can create the correct mailbox-format-type
133+ // Dovecot uses a different mail layout with a separate 'Maildir' subdirectory.
134134 if ($ mail_config ['pop3_imap_daemon ' ] == 'dovecot ' ) {
135- exec ("su -c 'doveadm mailbox create -u \"" .$ data ["new " ]["email " ]."\" INBOX' " );
136- exec ("su -c 'doveadm mailbox create -u \"" .$ data ["new " ]["email " ]."\" Sent' " );
137- exec ("su -c 'doveadm mailbox create -u \"" .$ data ["new " ]["email " ]."\" Trash' " );
138- exec ("su -c 'doveadm mailbox create -u \"" .$ data ["new " ]["email " ]."\" Junk' " );
139- exec ("su -c 'doveadm mailbox create -u \"" .$ data ["new " ]["email " ]."\" Drafts' " );
140-
141- exec ("su -c 'doveadm mailbox subscribe -u \"" .$ data ["new " ]["email " ]."\" INBOX' " );
142- exec ("su -c 'doveadm mailbox subscribe -u \"" .$ data ["new " ]["email " ]."\" Sent' " );
143- exec ("su -c 'doveadm mailbox subscribe -u \"" .$ data ["new " ]["email " ]."\" Trash' " );
144- exec ("su -c 'doveadm mailbox subscribe -u \"" .$ data ["new " ]["email " ]."\" Junk' " );
145- exec ("su -c 'doveadm mailbox subscribe -u \"" .$ data ["new " ]["email " ]."\" Drafts' " );
135+ //exec("su -c 'mkdir -p ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
136+ $ app ->system ->mkdirpath ($ maildomain_path , 0700 , $ user , $ group );
137+ $ app ->log ('Created Directory: ' .$ maildomain_path , LOGLEVEL_DEBUG );
138+ $ maildomain_path .= '/Maildir ' ;
146139 }
147- else {
148- //* When the mail user dir exists but it is not a valid maildir, move it to corrupted maildir folder
149- if (!empty ($ maildomain_path ) && is_dir ($ maildomain_path ) && !is_dir ($ maildomain_path .'/new ' ) && !is_dir ($ maildomain_path .'/cur ' )) {
150- 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 ' ]);
151- exec ("su -c 'mv -f " .escapeshellcmd ($ data ['new ' ]['maildir ' ])." " .$ mail_config ['homedir_path ' ].'/corrupted/ ' .$ data ['new ' ]['mailuser_id ' ]."' vmail " );
152- $ app ->log ('Moved invalid maildir to corrupted Maildirs folder: ' .escapeshellcmd ($ data ['new ' ]['maildir ' ]), LOGLEVEL_WARN );
153- }
154-
155- //* Create the maildir, if it doesn not exist, set permissions, set quota.
156- if (!empty ($ maildomain_path ) && !is_dir ($ maildomain_path )) {
157-
158- //exec("su -c 'maildirmake ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
159- $ app ->system ->maildirmake ($ maildomain_path , $ user , '' , $ group );
160-
161- //* This is to fix the maildrop quota not being rebuilt after the quota is changed.
162- if ($ mail_config ['pop3_imap_daemon ' ] != 'dovecot ' ) {
163- if (is_dir ($ maildomain_path )) exec ("su -c 'maildirmake -q " .$ data ['new ' ]['quota ' ]."S " .escapeshellcmd ($ maildomain_path )."' " .$ user ); // Avoid maildirmake quota bug, see debian bug #214911
164- $ app ->log ('Created Maildir: ' ."su -c 'maildirmake -q " .$ data ['new ' ]['quota ' ]."S " .escapeshellcmd ($ maildomain_path )."' " .$ user , LOGLEVEL_DEBUG );
165- }
166- }
167-
168- if (!is_dir ($ data ['new ' ]['maildir ' ].'/.Sent ' )) {
169- //exec("su -c 'maildirmake -f Sent ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
170- //$app->log('Created submaildir Sent: '."su -c 'maildirmake -f Sent ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG);
171- $ app ->system ->maildirmake ($ maildomain_path , $ user , 'Sent ' , $ group );
172- }
173- if (!is_dir ($ data ['new ' ]['maildir ' ].'/.Drafts ' )) {
174- //exec("su -c 'maildirmake -f Drafts ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
175- //$app->log('Created submaildir Drafts: '."su -c 'maildirmake -f Drafts ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG);
176- $ app ->system ->maildirmake ($ maildomain_path , $ user , 'Drafts ' , $ group );
177- }
178- if (!is_dir ($ data ['new ' ]['maildir ' ].'/.Trash ' )) {
179- //exec("su -c 'maildirmake -f Trash ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
180- //$app->log('Created submaildir Trash: '."su -c 'maildirmake -f Trash ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG);
181- $ app ->system ->maildirmake ($ maildomain_path , $ user , 'Trash ' , $ group );
182- }
183- if (!is_dir ($ data ['new ' ]['maildir ' ].'/.Junk ' )) {
184- //exec("su -c 'maildirmake -f Junk ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
185- //$app->log('Created submaildir Junk: '."su -c 'maildirmake -f Junk ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG);
186- $ app ->system ->maildirmake ($ maildomain_path , $ user , 'Junk ' , $ group );
140+
141+ //* When the mail user dir exists but it is not a valid maildir, move it to corrupted maildir folder
142+ if (!empty ($ maildomain_path ) && is_dir ($ maildomain_path ) && !is_dir ($ maildomain_path .'/new ' ) && !is_dir ($ maildomain_path .'/cur ' )) {
143+ 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 ' ]);
144+ exec ("su -c 'mv -f " .escapeshellcmd ($ data ['new ' ]['maildir ' ])." " .$ mail_config ['homedir_path ' ].'/corrupted/ ' .$ data ['new ' ]['mailuser_id ' ]."' vmail " );
145+ $ app ->log ('Moved invalid maildir to corrupted Maildirs folder: ' .escapeshellcmd ($ data ['new ' ]['maildir ' ]), LOGLEVEL_WARN );
146+ }
147+
148+ //* Create the maildir, if it doesn not exist, set permissions, set quota.
149+ if (!empty ($ maildomain_path ) && !is_dir ($ maildomain_path )) {
150+
151+ //exec("su -c 'maildirmake ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
152+ $ app ->system ->maildirmake ($ maildomain_path , $ user , '' , $ group );
153+
154+ //* This is to fix the maildrop quota not being rebuilt after the quota is changed.
155+ if ($ mail_config ['pop3_imap_daemon ' ] != 'dovecot ' ) {
156+ if (is_dir ($ maildomain_path )) exec ("su -c 'maildirmake -q " .$ data ['new ' ]['quota ' ]."S " .escapeshellcmd ($ maildomain_path )."' " .$ user ); // Avoid maildirmake quota bug, see debian bug #214911
157+ $ app ->log ('Created Maildir: ' ."su -c 'maildirmake -q " .$ data ['new ' ]['quota ' ]."S " .escapeshellcmd ($ maildomain_path )."' " .$ user , LOGLEVEL_DEBUG );
187158 }
188-
189- // Set permissions now recursive
190- exec ('chown -R ' .$ user .': ' .$ group .' ' .escapeshellcmd ($ data ['new ' ]['maildir ' ]));
191- $ app ->log ('Set ownership on ' .escapeshellcmd ($ data ['new ' ]['maildir ' ]), LOGLEVEL_DEBUG );
192-
193- //* Set the maildir quota
194- if (is_dir ($ data ['new ' ]['maildir ' ].'/new ' ) && $ mail_config ['pop3_imap_daemon ' ] != 'dovecot ' ) {
195- if ($ data ['new ' ]['quota ' ] > 0 ) {
196- if (is_dir ($ data ['new ' ]['maildir ' ])) exec ("su -c 'maildirmake -q " .$ data ['new ' ]['quota ' ]."S " .escapeshellcmd ($ data ['new ' ]['maildir ' ])."' " .$ user );
197- $ app ->log ('Set Maildir quota: ' ."su -c 'maildirmake -q " .$ data ['new ' ]['quota ' ]."S " .escapeshellcmd ($ data ['new ' ]['maildir ' ])."' " .$ user , LOGLEVEL_DEBUG );
198- }
159+ }
160+
161+ if (!is_dir ($ data ['new ' ]['maildir ' ].'/.Sent ' )) {
162+ //exec("su -c 'maildirmake -f Sent ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
163+ //$app->log('Created submaildir Sent: '."su -c 'maildirmake -f Sent ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG);
164+ $ app ->system ->maildirmake ($ maildomain_path , $ user , 'Sent ' , $ group );
165+ }
166+ if (!is_dir ($ data ['new ' ]['maildir ' ].'/.Drafts ' )) {
167+ //exec("su -c 'maildirmake -f Drafts ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
168+ //$app->log('Created submaildir Drafts: '."su -c 'maildirmake -f Drafts ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG);
169+ $ app ->system ->maildirmake ($ maildomain_path , $ user , 'Drafts ' , $ group );
170+ }
171+ if (!is_dir ($ data ['new ' ]['maildir ' ].'/.Trash ' )) {
172+ //exec("su -c 'maildirmake -f Trash ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
173+ //$app->log('Created submaildir Trash: '."su -c 'maildirmake -f Trash ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG);
174+ $ app ->system ->maildirmake ($ maildomain_path , $ user , 'Trash ' , $ group );
175+ }
176+ if (!is_dir ($ data ['new ' ]['maildir ' ].'/.Junk ' )) {
177+ //exec("su -c 'maildirmake -f Junk ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']);
178+ //$app->log('Created submaildir Junk: '."su -c 'maildirmake -f Junk ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG);
179+ $ app ->system ->maildirmake ($ maildomain_path , $ user , 'Junk ' , $ group );
180+ }
181+
182+ // Set permissions now recursive
183+ exec ('chown -R ' .$ user .': ' .$ group .' ' .escapeshellcmd ($ data ['new ' ]['maildir ' ]));
184+ $ app ->log ('Set ownership on ' .escapeshellcmd ($ data ['new ' ]['maildir ' ]), LOGLEVEL_DEBUG );
185+
186+ //* Set the maildir quota
187+ if (is_dir ($ data ['new ' ]['maildir ' ].'/new ' ) && $ mail_config ['pop3_imap_daemon ' ] != 'dovecot ' ) {
188+ if ($ data ['new ' ]['quota ' ] > 0 ) {
189+ if (is_dir ($ data ['new ' ]['maildir ' ])) exec ("su -c 'maildirmake -q " .$ data ['new ' ]['quota ' ]."S " .escapeshellcmd ($ data ['new ' ]['maildir ' ])."' " .$ user );
190+ $ app ->log ('Set Maildir quota: ' ."su -c 'maildirmake -q " .$ data ['new ' ]['quota ' ]."S " .escapeshellcmd ($ data ['new ' ]['maildir ' ])."' " .$ user , LOGLEVEL_DEBUG );
199191 }
200192 }
193+
201194
202195 //* Send the welcome email message
203196 if (file_exists ($ conf ['rootpath ' ].'/conf-custom/mail/welcome_email_ ' .$ conf ['language ' ].'.txt ' )) {
0 commit comments