@@ -135,7 +135,7 @@ function user_insert($event_name, $data) {
135135 $ app ->system ->exec_safe ("su -c 'doveadm mailbox create -u ? Trash' " , $ data ["new " ]["email " ]);
136136 $ app ->system ->exec_safe ("su -c 'doveadm mailbox create -u ? Junk' " , $ data ["new " ]["email " ]);
137137 $ app ->system ->exec_safe ("su -c 'doveadm mailbox create -u ? Drafts' " , $ data ["new " ]["email " ]);
138-
138+
139139 $ app ->system ->exec_safe ("su -c 'doveadm mailbox subscribe -u ? INBOX' " , $ data ["new " ]["email " ]);
140140 $ app ->system ->exec_safe ("su -c 'doveadm mailbox subscribe -u ? Sent' " , $ data ["new " ]["email " ]);
141141 $ app ->system ->exec_safe ("su -c 'doveadm mailbox subscribe -u ? Trash' " , $ data ["new " ]["email " ]);
@@ -149,26 +149,26 @@ function user_insert($event_name, $data) {
149149 $ app ->log ('Created Directory: ' .$ maildomain_path , LOGLEVEL_DEBUG );
150150 $ maildomain_path .= '/Maildir ' ;
151151 }
152-
152+
153153 //* When the mail user dir exists but it is not a valid maildir, move it to corrupted maildir folder
154154 if (!empty ($ maildomain_path ) && is_dir ($ maildomain_path ) && !is_dir ($ maildomain_path .'/new ' ) && !is_dir ($ maildomain_path .'/cur ' )) {
155155 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 ' ]);
156156 $ app ->system ->exec_safe ("su -c ? vmail " , "mv -f " . $ data ['new ' ]['maildir ' ]." " .$ mail_config ['homedir_path ' ].'/corrupted/ ' .$ data ['new ' ]['mailuser_id ' ]);
157157 $ app ->log ('Moved invalid maildir to corrupted Maildirs folder: ' .$ data ['new ' ]['maildir ' ], LOGLEVEL_WARN );
158158 }
159-
159+
160160 //* Create the maildir, if it doesn not exist, set permissions, set quota.
161161 if (!empty ($ maildomain_path ) && !is_dir ($ maildomain_path )) {
162-
162+
163163 $ app ->system ->maildirmake ($ maildomain_path , $ user , '' , $ group );
164-
164+
165165 //* This is to fix the maildrop quota not being rebuilt after the quota is changed.
166166 if ($ mail_config ['pop3_imap_daemon ' ] != 'dovecot ' ) {
167167 if (is_dir ($ maildomain_path )) $ app ->system ->exec_safe ("su -c ? ? " , "maildirmake -q " .$ data ['new ' ]['quota ' ]."S " .$ maildomain_path , $ user ); // Avoid maildirmake quota bug, see debian bug #214911
168168 $ app ->log ('Created Maildir: ' ."su -c 'maildirmake -q " .$ data ['new ' ]['quota ' ]."S " .$ maildomain_path ."' " .$ user , LOGLEVEL_DEBUG );
169169 }
170170 }
171-
171+
172172 if (!is_dir ($ data ['new ' ]['maildir ' ].'/.Sent ' )) {
173173 $ app ->system ->maildirmake ($ maildomain_path , $ user , 'Sent ' , $ group );
174174 }
@@ -181,11 +181,11 @@ function user_insert($event_name, $data) {
181181 if (!is_dir ($ data ['new ' ]['maildir ' ].'/.Junk ' )) {
182182 $ app ->system ->maildirmake ($ maildomain_path , $ user , 'Junk ' , $ group );
183183 }
184-
184+
185185 // Set permissions now recursive
186186 $ app ->system ->exec_safe ('chown -R ?:? ? ' , $ user , $ group , $ data ['new ' ]['maildir ' ]);
187187 $ app ->log ('Set ownership on ' .$ data ['new ' ]['maildir ' ], LOGLEVEL_DEBUG );
188-
188+
189189 //* Set the maildir quota
190190 if (is_dir ($ data ['new ' ]['maildir ' ].'/new ' ) && $ mail_config ['pop3_imap_daemon ' ] != 'dovecot ' ) {
191191 if ($ data ['new ' ]['quota ' ] > 0 ) {
@@ -195,63 +195,61 @@ function user_insert($event_name, $data) {
195195 }
196196 }
197197
198- $ global_config = $ app ->getconf ->get_global_config ('mail ' );
199- if ($ global_config ['enable_welcome_mail ' ] == 'y ' ) {
200- //* Send the welcome email message
201- $ tmp = explode ('@ ' , $ data ["new " ]["email " ]);
202- $ domain = $ tmp [1 ];
203- unset($ tmp );
204- $ html = false ;
205- if (file_exists ($ conf ['rootpath ' ].'/conf-custom/mail/welcome_email_ ' .$ domain .'.html ' )) {
206- $ lines = file ($ conf ['rootpath ' ].'/conf-custom/mail/welcome_email_ ' .$ domain .'.html ' );
207- $ html = true ;
208- } elseif (file_exists ($ conf ['rootpath ' ].'/conf-custom/mail/welcome_email_ ' .$ conf ['language ' ].'.html ' )) {
209- $ lines = file ($ conf ['rootpath ' ].'/conf-custom/mail/welcome_email_ ' .$ conf ['language ' ].'.html ' );
210- $ html = true ;
211- } elseif (file_exists ($ conf ['rootpath ' ].'/conf-custom/mail/welcome_email_ ' .$ domain .'.txt ' )) {
212- $ lines = file ($ conf ['rootpath ' ].'/conf-custom/mail/welcome_email_ ' .$ domain .'.txt ' );
213- } elseif (file_exists ($ conf ['rootpath ' ].'/conf-custom/mail/welcome_email_ ' .$ conf ['language ' ].'.txt ' )) {
214- $ lines = file ($ conf ['rootpath ' ].'/conf-custom/mail/welcome_email_ ' .$ conf ['language ' ].'.txt ' );
215- } elseif (file_exists ($ conf ['rootpath ' ].'/conf-custom/mail/welcome_email_en.txt ' )) {
216- $ lines = file ($ conf ['rootpath ' ].'/conf-custom/mail/welcome_email_en.txt ' );
217- } elseif (file_exists ($ conf ['rootpath ' ].'/conf/mail/welcome_email_ ' .$ conf ['language ' ].'.txt ' )) {
218- $ lines = file ($ conf ['rootpath ' ].'/conf/mail/welcome_email_ ' .$ conf ['language ' ].'.txt ' );
219- } else {
220- $ lines = file ($ conf ['rootpath ' ].'/conf/mail/welcome_email_en.txt ' );
221- }
222-
223- //* Get from address
224- $ parts = explode (': ' , trim ($ lines [0 ]));
225- unset($ parts [0 ]);
226- $ welcome_mail_from = implode (': ' , $ parts );
227- unset($ lines [0 ]);
228-
229- //* Get subject
230- $ parts = explode (': ' , trim ($ lines [1 ]));
231- unset($ parts [0 ]);
232- $ welcome_mail_subject = implode (': ' , $ parts );
233- unset($ lines [1 ]);
234-
235- //* Get message
236- $ welcome_mail_message = trim (implode ($ lines ));
237- unset($ tmp );
238-
239- $ mailHeaders = "MIME-Version: 1.0 " . "\n" ;
240- if ($ html ) {
241- $ mailHeaders .= "Content-Type: text/html; charset=utf-8 " . "\n" ;
242- $ mailHeaders .= "Content-Transfer-Encoding: quoted-printable " . "\n" ;
243- } else {
244- $ mailHeaders .= "Content-Type: text/plain; charset=utf-8 " . "\n" ;
245- $ mailHeaders .= "Content-Transfer-Encoding: 8bit " . "\n" ;
246- }
247- $ mailHeaders .= "From: $ welcome_mail_from " . "\n" ;
248- $ mailHeaders .= "Reply-To: $ welcome_mail_from " . "\n" ;
249- $ mailTarget = $ data ["new " ]["email " ];
250- $ mailSubject = "=?utf-8?B? " .base64_encode ($ welcome_mail_subject )."?= " ;
198+ //* Send the welcome email message
199+ $ tmp = explode ('@ ' , $ data ["new " ]["email " ]);
200+ $ domain = $ tmp [1 ];
201+ unset($ tmp );
202+ $ html = false ;
203+ if (file_exists ($ conf ['rootpath ' ].'/conf-custom/mail/welcome_email_ ' .$ domain .'.html ' )) {
204+ $ lines = file ($ conf ['rootpath ' ].'/conf-custom/mail/welcome_email_ ' .$ domain .'.html ' );
205+ $ html = true ;
206+ } elseif (file_exists ($ conf ['rootpath ' ].'/conf-custom/mail/welcome_email_ ' .$ conf ['language ' ].'.html ' )) {
207+ $ lines = file ($ conf ['rootpath ' ].'/conf-custom/mail/welcome_email_ ' .$ conf ['language ' ].'.html ' );
208+ $ html = true ;
209+ } elseif (file_exists ($ conf ['rootpath ' ].'/conf-custom/mail/welcome_email_ ' .$ domain .'.txt ' )) {
210+ $ lines = file ($ conf ['rootpath ' ].'/conf-custom/mail/welcome_email_ ' .$ domain .'.txt ' );
211+ } elseif (file_exists ($ conf ['rootpath ' ].'/conf-custom/mail/welcome_email_ ' .$ conf ['language ' ].'.txt ' )) {
212+ $ lines = file ($ conf ['rootpath ' ].'/conf-custom/mail/welcome_email_ ' .$ conf ['language ' ].'.txt ' );
213+ } elseif (file_exists ($ conf ['rootpath ' ].'/conf-custom/mail/welcome_email_en.txt ' )) {
214+ $ lines = file ($ conf ['rootpath ' ].'/conf-custom/mail/welcome_email_en.txt ' );
215+ } elseif (file_exists ($ conf ['rootpath ' ].'/conf/mail/welcome_email_ ' .$ conf ['language ' ].'.txt ' )) {
216+ $ lines = file ($ conf ['rootpath ' ].'/conf/mail/welcome_email_ ' .$ conf ['language ' ].'.txt ' );
217+ } else {
218+ $ lines = file ($ conf ['rootpath ' ].'/conf/mail/welcome_email_en.txt ' );
219+ }
251220
252- //* Send the welcome email only on the "master" mail server to avoid duplicate emails
253- if ($ conf ['mirror_server_id ' ] == 0 ) mail ($ mailTarget , $ mailSubject , $ welcome_mail_message , $ mailHeaders );
221+ //* Get from address
222+ $ parts = explode (': ' , trim ($ lines [0 ]));
223+ unset($ parts [0 ]);
224+ $ welcome_mail_from = implode (': ' , $ parts );
225+ unset($ lines [0 ]);
226+
227+ //* Get subject
228+ $ parts = explode (': ' , trim ($ lines [1 ]));
229+ unset($ parts [0 ]);
230+ $ welcome_mail_subject = implode (': ' , $ parts );
231+ unset($ lines [1 ]);
232+
233+ //* Get message
234+ $ welcome_mail_message = trim (implode ($ lines ));
235+ unset($ tmp );
236+
237+ $ mailHeaders = "MIME-Version: 1.0 " . "\n" ;
238+ if ($ html ) {
239+ $ mailHeaders .= "Content-Type: text/html; charset=utf-8 " . "\n" ;
240+ $ mailHeaders .= "Content-Transfer-Encoding: quoted-printable " . "\n" ;
241+ } else {
242+ $ mailHeaders .= "Content-Type: text/plain; charset=utf-8 " . "\n" ;
243+ $ mailHeaders .= "Content-Transfer-Encoding: 8bit " . "\n" ;
254244 }
245+ $ mailHeaders .= "From: $ welcome_mail_from " . "\n" ;
246+ $ mailHeaders .= "Reply-To: $ welcome_mail_from " . "\n" ;
247+ $ mailTarget = $ data ["new " ]["email " ];
248+ $ mailSubject = "=?utf-8?B? " .base64_encode ($ welcome_mail_subject )."?= " ;
249+
250+ //* Send the welcome email only on the "master" mail server to avoid duplicate emails
251+ if ($ conf ['mirror_server_id ' ] == 0 ) mail ($ mailTarget , $ mailSubject , $ welcome_mail_message , $ mailHeaders );
252+
255253 }
256254
257255 function user_update ($ event_name , $ data ) {
@@ -263,7 +261,7 @@ function user_update($event_name, $data) {
263261
264262 // Maildir-Format must not be changed on this way !!
265263 $ data ['new ' ]['maildir_format ' ] = $ data ['old ' ]['maildir_format ' ];
266-
264+
267265 $ maildomain_path = $ data ['new ' ]['maildir ' ];
268266 $ tmp_basepath = $ data ['new ' ]['maildir ' ];
269267 $ tmp_basepath_parts = explode ('/ ' , $ tmp_basepath );
@@ -317,15 +315,15 @@ function user_update($event_name, $data) {
317315 $ app ->system ->exec_safe ('mv -f ? ? ' . $ data ['old ' ]['maildir ' ], $ data ['new ' ]['maildir ' ]);
318316 $ app ->log ('Moved Maildir from: ' .$ data ['old ' ]['maildir ' ].' to ' .$ data ['new ' ]['maildir ' ], LOGLEVEL_DEBUG );
319317 }
320-
318+
321319 //* Create the maildir, if it doesn not exist, set permissions, set quota.
322320 if (!is_dir ($ data ['new ' ]['maildir ' ].'/mdbox ' )) {
323321 $ app ->system ->exec_safe ("su -c 'doveadm mailbox create -u ? INBOX' " , $ data ["new " ]["email " ]);
324322 $ app ->system ->exec_safe ("su -c 'doveadm mailbox create -u ? Sent' " , $ data ["new " ]["email " ]);
325323 $ app ->system ->exec_safe ("su -c 'doveadm mailbox create -u ? Trash' " , $ data ["new " ]["email " ]);
326324 $ app ->system ->exec_safe ("su -c 'doveadm mailbox create -u ? Junk' " , $ data ["new " ]["email " ]);
327325 $ app ->system ->exec_safe ("su -c 'doveadm mailbox create -u ? Drafts' " , $ data ["new " ]["email " ]);
328-
326+
329327 $ app ->system ->exec_safe ("su -c 'doveadm mailbox subscribe -u ? INBOX' " , $ data ["new " ]["email " ]);
330328 $ app ->system ->exec_safe ("su -c 'doveadm mailbox subscribe -u ? Sent' " , $ data ["new " ]["email " ]);
331329 $ app ->system ->exec_safe ("su -c 'doveadm mailbox subscribe -u ? Trash' " , $ data ["new " ]["email " ]);
@@ -340,18 +338,18 @@ function user_update($event_name, $data) {
340338 $ app ->log ('Created Directory: ' .$ base_path , LOGLEVEL_DEBUG );
341339 $ maildomain_path .= '/Maildir ' ;
342340 }
343-
341+
344342 //* When the mail user dir exists but it is not a valid maildir, move it to corrupted maildir folder
345343 if (!empty ($ maildomain_path ) && is_dir ($ maildomain_path ) && !is_dir ($ maildomain_path .'/new ' ) && !is_dir ($ maildomain_path .'/cur ' )) {
346344 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 ' ]);
347345 $ app ->system ->exec_safe ("su -c ? ? " , "mv -f " .$ data ['new ' ]['maildir ' ]." " .$ mail_config ['homedir_path ' ].'/corrupted/ ' .$ data ['new ' ]['mailuser_id ' ], 'vmail ' );
348346 $ app ->log ('Moved invalid maildir to corrupted Maildirs folder: ' .$ data ['new ' ]['maildir ' ], LOGLEVEL_WARN );
349347 }
350-
348+
351349 //* Create the maildir, if it doesn not exist, set permissions, set quota.
352350 if (!empty ($ maildomain_path ) && !is_dir ($ maildomain_path .'/new ' )) {
353351 $ app ->system ->maildirmake ($ maildomain_path , $ user , '' , $ group );
354-
352+
355353 //* This is to fix the maildrop quota not being rebuilt after the quota is changed.
356354 if ($ mail_config ['pop3_imap_daemon ' ] != 'dovecot ' ) {
357355 if ($ data ['new ' ]['quota ' ] > 0 ) {
@@ -363,7 +361,7 @@ function user_update($event_name, $data) {
363361 }
364362 }
365363 }
366-
364+
367365 if (!is_dir ($ data ['new ' ]['maildir ' ].'/.Sent ' )) {
368366 $ app ->system ->maildirmake ($ maildomain_path , $ user , 'Sent ' , $ group );
369367 }
@@ -376,11 +374,11 @@ function user_update($event_name, $data) {
376374 if (!is_dir ($ data ['new ' ]['maildir ' ].'/.Junk ' )) {
377375 $ app ->system ->maildirmake ($ maildomain_path , $ user , 'Junk ' , $ group );
378376 }
379-
377+
380378 // Set permissions now recursive
381379 $ app ->system ->exec_safe ('chown -R ?:? ? ' , $ user , $ group , $ data ['new ' ]['maildir ' ]);
382380 $ app ->log ('Set ownership on ' .$ data ['new ' ]['maildir ' ], LOGLEVEL_DEBUG );
383-
381+
384382 // Move mailbox, if domain has changed and delete old mailbox
385383 if ($ data ['new ' ]['maildir ' ] != $ data ['old ' ]['maildir ' ] && is_dir ($ data ['old ' ]['maildir ' ])) {
386384 if (is_dir ($ data ['new ' ]['maildir ' ])) {
@@ -472,7 +470,7 @@ function domain_delete($event_name, $data) {
472470 } else {
473471 $ app ->log ('Possible security violation when deleting the mail domain mailfilter directory: ' .$ old_maildomain_path , LOGLEVEL_ERROR );
474472 }
475-
473+
476474 //* Delete the mail-backups
477475 $ server_config = $ app ->getconf ->get_server_config ($ conf ['server_id ' ], 'server ' );
478476 $ backup_dir = $ server_config ['backup_dir ' ];
0 commit comments