@@ -106,8 +106,10 @@ function user_insert($event_name,$data) {
106106 }
107107
108108 //* Set the maildir quota
109- exec ("su -c 'maildirmake -q " .$ data ['new ' ]['quota ' ]."S " .escapeshellcmd ($ data ['new ' ]['maildir ' ])."' " .$ mail_config ['mailuser_name ' ]);
110- $ app ->log ('Set Maildir quota: ' ."su -c 'maildirmake -q " .$ data ['new ' ]['quota ' ]."S " .escapeshellcmd ($ data ['new ' ]['maildir ' ])."' " .$ mail_config ['mailuser_name ' ],LOGLEVEL_DEBUG );
109+ if (is_dir ($ data ['new ' ]['maildir ' ].'new ' )) {
110+ exec ("su -c 'maildirmake -q " .$ data ['new ' ]['quota ' ]."S " .escapeshellcmd ($ data ['new ' ]['maildir ' ])."' " .$ mail_config ['mailuser_name ' ]);
111+ $ app ->log ('Set Maildir quota: ' ."su -c 'maildirmake -q " .$ data ['new ' ]['quota ' ]."S " .escapeshellcmd ($ data ['new ' ]['maildir ' ])."' " .$ mail_config ['mailuser_name ' ],LOGLEVEL_DEBUG );
112+ }
111113 }
112114
113115 function user_update ($ event_name ,$ data ) {
@@ -118,11 +120,35 @@ function user_update($event_name,$data) {
118120 $ mail_config = $ app ->getconf ->get_server_config ($ conf ["server_id " ], 'mail ' );
119121
120122 // Create the maildir, if it does not exist
123+ /*
121124 if(!is_dir($data['new']['maildir'])) {
122125 exec('mkdir -p '.escapeshellcmd($data['new']['maildir']));
123126 exec('chown '.$mail_config['mailuser_name'].':'.$mail_config['mailuser_group'].' '.escapeshellcmd($data['new']['maildir']));
124127 $app->log('Created Maildir: '.$data['new']['maildir'],LOGLEVEL_DEBUG);
125128 }
129+ */
130+
131+ $ maildomain_path = $ data ['new ' ]['maildir ' ];
132+ $ tmp_basepath = $ data ['new ' ]['maildir ' ];
133+ $ tmp_basepath_parts = explode ('/ ' ,$ tmp_basepath );
134+ unset($ tmp_basepath_parts [count ($ tmp_basepath_parts )-1 ]);
135+ $ base_path = implode ('/ ' ,$ tmp_basepath_parts );
136+
137+ //* Create the mail domain directory, if it does not exist
138+ if (!empty ($ base_path ) && !is_dir ($ base_path )) {
139+ exec ("su -c 'mkdir -p " .escapeshellcmd ($ base_path )."' " .$ mail_config ['mailuser_name ' ]);
140+ $ app ->log ('Created Directory: ' .$ base_path ,LOGLEVEL_DEBUG );
141+ }
142+
143+ //* Create the maildir, if it doesn not exist, set permissions, set quota.
144+ if (!empty ($ maildomain_path ) && !is_dir ($ maildomain_path .'new ' )) {
145+ exec ("su -c 'maildirmake " .escapeshellcmd ($ maildomain_path )."' " .$ mail_config ['mailuser_name ' ]);
146+ exec ('chown -R ' .$ mail_config ['mailuser_name ' ].': ' .$ mail_config ['mailuser_group ' ].' ' .escapeshellcmd ($ data ['new ' ]['maildir ' ]));
147+ $ app ->log ("Set ownership on " .escapeshellcmd ($ data ['new ' ]['maildir ' ]),LOGLEVEL_DEBUG );
148+ //* This is to fix the maildrop quota not being rebuilt after the quota is changed.
149+ 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 );
151+ }
126152
127153 // Move mailbox, if domain has changed and delete old mailbox
128154 if ($ data ['new ' ]['maildir ' ] != $ data ['old ' ]['maildir ' ] && is_dir ($ data ['old ' ]['maildir ' ])) {
@@ -137,8 +163,10 @@ function user_update($event_name,$data) {
137163 $ app ->log ('Moved Maildir from: ' .$ data ['old ' ]['maildir ' ].' to ' .$ data ['new ' ]['maildir ' ],LOGLEVEL_DEBUG );
138164 }
139165 //This is to fix the maildrop quota not being rebuilt after the quota is changed.
140- exec ("su -c 'maildirmake -q " .$ data ['new ' ]['quota ' ]."S " .escapeshellcmd ($ data ['new ' ]['maildir ' ])."' " .$ mail_config ['mailuser_name ' ]);
141- $ app ->log ('Created Maildir: ' ."su -c 'maildirmake -q " .$ data ['new ' ]['quota ' ]."S " .escapeshellcmd ($ data ['new ' ]['maildir ' ])."' " .$ mail_config ['mailuser_name ' ],LOGLEVEL_DEBUG );
166+ if (is_dir ($ data ['new ' ]['maildir ' ].'new ' )) {
167+ 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 );
169+ }
142170 }
143171
144172 function user_delete ($ event_name ,$ data ) {
0 commit comments