@@ -82,6 +82,9 @@ function user_insert($event_name,$data) {
8282 //* get the config
8383 $ app ->uses ("getconf " );
8484 $ mail_config = $ app ->getconf ->get_server_config ($ conf ["server_id " ], 'mail ' );
85+
86+ // convert to lower case - it could cause problems if some directory above has upper case name
87+ // $data['new']['maildir'] = strtolower($data['new']['maildir']);
8588
8689 $ maildomain_path = $ data ['new ' ]['maildir ' ];
8790 $ tmp_basepath = $ data ['new ' ]['maildir ' ];
@@ -94,7 +97,7 @@ function user_insert($event_name,$data) {
9497 exec ("su -c 'mkdir -p " .escapeshellcmd ($ base_path )."' " .$ mail_config ['mailuser_name ' ]);
9598 $ app ->log ('Created Directory: ' .$ base_path ,LOGLEVEL_DEBUG );
9699 }
97-
100+
98101 //* When the mail user dir exists but it is not a valid maildir, remove it
99102 if (!empty ($ maildomain_path ) && is_dir ($ maildomain_path ) && !is_dir ($ maildomain_path .'/new ' ) && !is_dir ($ maildomain_path .'/cur ' )) {
100103 exec ("su -c 'rm -rf " .escapeshellcmd ($ data ['new ' ]['maildir ' ])."' vmail " );
@@ -103,9 +106,29 @@ function user_insert($event_name,$data) {
103106
104107 //* Create the maildir, if it doesn not exist, set permissions, set quota.
105108 if (!empty ($ maildomain_path ) && !is_dir ($ maildomain_path )) {
109+
106110 exec ("su -c 'maildirmake " .escapeshellcmd ($ maildomain_path )."' " .$ mail_config ['mailuser_name ' ]);
111+
112+ if (!is_dir ($ data ['new ' ]['maildir ' ].'/.Sent ' )) {
113+ exec ("su -c 'maildirmake -f Sent " .escapeshellcmd ($ maildomain_path )."' " .$ mail_config ['mailuser_name ' ]);
114+ $ app ->log ('Created submaildir Sent: ' ."su -c 'maildirmake -f Sent " .escapeshellcmd ($ maildomain_path )."' " .$ mail_config ['mailuser_name ' ],LOGLEVEL_DEBUG );
115+ }
116+ if (!is_dir ($ data ['new ' ]['maildir ' ].'/.Drafts ' )) {
117+ exec ("su -c 'maildirmake -f Drafts " .escapeshellcmd ($ maildomain_path )."' " .$ mail_config ['mailuser_name ' ]);
118+ $ app ->log ('Created submaildir Drafts: ' ."su -c 'maildirmake -f Drafts " .escapeshellcmd ($ maildomain_path )."' " .$ mail_config ['mailuser_name ' ],LOGLEVEL_DEBUG );
119+ }
120+ if (!is_dir ($ data ['new ' ]['maildir ' ].'/.Trash ' )) {
121+ exec ("su -c 'maildirmake -f Trash " .escapeshellcmd ($ maildomain_path )."' " .$ mail_config ['mailuser_name ' ]);
122+ $ app ->log ('Created submaildir Trash: ' ."su -c 'maildirmake -f Trash " .escapeshellcmd ($ maildomain_path )."' " .$ mail_config ['mailuser_name ' ],LOGLEVEL_DEBUG );
123+ }
124+ if (!is_dir ($ data ['new ' ]['maildir ' ].'/.Junk ' )) {
125+ exec ("su -c 'maildirmake -f Junk " .escapeshellcmd ($ maildomain_path )."' " .$ mail_config ['mailuser_name ' ]);
126+ $ app ->log ('Created submaildir Junk: ' ."su -c 'maildirmake -f Junk " .escapeshellcmd ($ maildomain_path )."' " .$ mail_config ['mailuser_name ' ],LOGLEVEL_DEBUG );
127+ }
128+
107129 exec ('chown -R ' .$ mail_config ['mailuser_name ' ].': ' .$ mail_config ['mailuser_group ' ].' ' .escapeshellcmd ($ data ['new ' ]['maildir ' ]));
108130 $ app ->log ("Set ownership on " .escapeshellcmd ($ data ['new ' ]['maildir ' ]),LOGLEVEL_DEBUG );
131+
109132 //* This is to fix the maildrop quota not being rebuilt after the quota is changed.
110133 exec ("su -c 'maildirmake -q " .$ data ['new ' ]['quota ' ]."S " .escapeshellcmd ($ maildomain_path )."' " .$ mail_config ['mailuser_name ' ]); // Avoid maildirmake quota bug, see debian bug #214911
111134 $ app ->log ('Created Maildir: ' ."su -c 'maildirmake -q " .$ data ['new ' ]['quota ' ]."S " .escapeshellcmd ($ maildomain_path )."' " .$ mail_config ['mailuser_name ' ],LOGLEVEL_DEBUG );
@@ -124,6 +147,9 @@ function user_update($event_name,$data) {
124147 // get the config
125148 $ app ->uses ("getconf " );
126149 $ mail_config = $ app ->getconf ->get_server_config ($ conf ["server_id " ], 'mail ' );
150+
151+ // convert to lower case - it could cause problems if some directory above has upper case name
152+ // $data['new']['maildir'] = strtolower($data['new']['maildir']);
127153
128154 // Create the maildir, if it does not exist
129155 /*
@@ -156,6 +182,24 @@ function user_update($event_name,$data) {
156182 if (!empty ($ maildomain_path ) && !is_dir ($ maildomain_path .'/new ' )) {
157183 exec ("su -c 'maildirmake " .escapeshellcmd ($ maildomain_path )."' " .$ mail_config ['mailuser_name ' ]);
158184 $ app ->log ("Created Maildir " ."su -c 'maildirmake " .escapeshellcmd ($ maildomain_path )."' " .$ mail_config ['mailuser_name ' ],LOGLEVEL_DEBUG );
185+
186+ if (!is_dir ($ data ['new ' ]['maildir ' ].'/.Sent ' )) {
187+ exec ("su -c 'maildirmake -f Sent " .escapeshellcmd ($ maildomain_path )."' " .$ mail_config ['mailuser_name ' ]);
188+ $ app ->log ('Created submaildir Sent: ' ."su -c 'maildirmake -f Sent " .escapeshellcmd ($ maildomain_path )."' " .$ mail_config ['mailuser_name ' ],LOGLEVEL_DEBUG );
189+ }
190+ if (!is_dir ($ data ['new ' ]['maildir ' ].'/.Drafts ' )) {
191+ exec ("su -c 'maildirmake -f Drafts " .escapeshellcmd ($ maildomain_path )."' " .$ mail_config ['mailuser_name ' ]);
192+ $ app ->log ('Created submaildir Drafts: ' ."su -c 'maildirmake -f Drafts " .escapeshellcmd ($ maildomain_path )."' " .$ mail_config ['mailuser_name ' ],LOGLEVEL_DEBUG );
193+ }
194+ if (!is_dir ($ data ['new ' ]['maildir ' ].'/.Trash ' )) {
195+ exec ("su -c 'maildirmake -f Trash " .escapeshellcmd ($ maildomain_path )."' " .$ mail_config ['mailuser_name ' ]);
196+ $ app ->log ('Created submaildir Trash: ' ."su -c 'maildirmake -f Trash " .escapeshellcmd ($ maildomain_path )."' " .$ mail_config ['mailuser_name ' ],LOGLEVEL_DEBUG );
197+ }
198+ if (!is_dir ($ data ['new ' ]['maildir ' ].'/.Junk ' )) {
199+ exec ("su -c 'maildirmake -f Junk " .escapeshellcmd ($ maildomain_path )."' " .$ mail_config ['mailuser_name ' ]);
200+ $ app ->log ('Created submaildir Junk: ' ."su -c 'maildirmake -f Junk " .escapeshellcmd ($ maildomain_path )."' " .$ mail_config ['mailuser_name ' ],LOGLEVEL_DEBUG );
201+ }
202+
159203 exec ('chown -R ' .$ mail_config ['mailuser_name ' ].': ' .$ mail_config ['mailuser_group ' ].' ' .escapeshellcmd ($ data ['new ' ]['maildir ' ]));
160204 $ app ->log ("Set ownership on " .escapeshellcmd ($ data ['new ' ]['maildir ' ]),LOGLEVEL_DEBUG );
161205 //* This is to fix the maildrop quota not being rebuilt after the quota is changed.
@@ -201,13 +245,23 @@ function domain_delete($event_name,$data) {
201245 $ app ->uses ("getconf " );
202246 $ mail_config = $ app ->getconf ->get_server_config ($ conf ["server_id " ], 'mail ' );
203247
248+ //* Delete maildomain path
204249 $ old_maildomain_path = escapeshellcmd ($ mail_config ['homedir_path ' ].'/ ' .$ data ['old ' ]['domain ' ]);
205250 if (!stristr ($ old_maildomain_path ,'.. ' ) && !stristr ($ old_maildomain_path ,'* ' ) && strlen ($ old_maildomain_path ) >= 10 ) {
206251 exec ('rm -rf ' .escapeshellcmd ($ old_maildomain_path ));
207252 $ app ->log ('Deleted the mail domain directory: ' .$ old_maildomain_path ,LOGLEVEL_DEBUG );
208253 } else {
209254 $ app ->log ('Possible security violation when deleting the mail domain directory: ' .$ old_maildomain_path ,LOGLEVEL_ERROR );
210255 }
256+
257+ //* Delete mailfilter path
258+ $ old_maildomain_path = escapeshellcmd ($ mail_config ['homedir_path ' ].'/mailfilters/ ' .$ data ['old ' ]['domain ' ]);
259+ if (!stristr ($ old_maildomain_path ,'.. ' ) && !stristr ($ old_maildomain_path ,'* ' ) && strlen ($ old_maildomain_path ) >= 10 ) {
260+ exec ('rm -rf ' .escapeshellcmd ($ old_maildomain_path ));
261+ $ app ->log ('Deleted the mail domain mailfilter directory: ' .$ old_maildomain_path ,LOGLEVEL_DEBUG );
262+ } else {
263+ $ app ->log ('Possible security violation when deleting the mail domain mailfilter directory: ' .$ old_maildomain_path ,LOGLEVEL_ERROR );
264+ }
211265 }
212266
213267 function transport_update ($ event_name ,$ data ) {
0 commit comments