Skip to content

Commit 9da76fd

Browse files
author
Thom Pol
committed
Add global option to disable/enable welcome email messages (#1804)
1 parent 07dcf84 commit 9da76fd

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

install/tpl/system.ini.master

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ webmail_url=/webmail
1616
dkim_path=/var/lib/amavis/dkim
1717
smtp_enabled=y
1818
smtp_host=localhost
19+
enable_welcome_mail=y
1920

2021
[monitor]
2122

server/plugins-available/mail_plugin.inc.php

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ function user_insert($event_name, $data) {
136136
$app->system->exec_safe("su -c 'doveadm mailbox create -u ? Trash'", $data["new"]["email"]);
137137
$app->system->exec_safe("su -c 'doveadm mailbox create -u ? Junk'", $data["new"]["email"]);
138138
$app->system->exec_safe("su -c 'doveadm mailbox create -u ? Drafts'", $data["new"]["email"]);
139-
139+
140140
$app->system->exec_safe("su -c 'doveadm mailbox subscribe -u ? INBOX'", $data["new"]["email"]);
141141
$app->system->exec_safe("su -c 'doveadm mailbox subscribe -u ? Sent'", $data["new"]["email"]);
142142
$app->system->exec_safe("su -c 'doveadm mailbox subscribe -u ? Trash'", $data["new"]["email"]);
@@ -150,26 +150,26 @@ function user_insert($event_name, $data) {
150150
$app->log('Created Directory: '.$maildomain_path, LOGLEVEL_DEBUG);
151151
$maildomain_path .= '/Maildir';
152152
}
153-
153+
154154
//* When the mail user dir exists but it is not a valid maildir, move it to corrupted maildir folder
155155
if(!empty($maildomain_path) && is_dir($maildomain_path) && !is_dir($maildomain_path.'/new') && !is_dir($maildomain_path.'/cur')) {
156156
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']);
157157
$app->system->exec_safe("su -c ? vmail", "mv -f " . $data['new']['maildir']." ".$mail_config['homedir_path'].'/corrupted/'.$data['new']['mailuser_id']);
158158
$app->log('Moved invalid maildir to corrupted Maildirs folder: '.$data['new']['maildir'], LOGLEVEL_WARN);
159159
}
160-
160+
161161
//* Create the maildir, if it doesn not exist, set permissions, set quota.
162162
if(!empty($maildomain_path) && !is_dir($maildomain_path)) {
163-
163+
164164
$app->system->maildirmake($maildomain_path, $user, '', $group);
165-
165+
166166
//* This is to fix the maildrop quota not being rebuilt after the quota is changed.
167167
if($mail_config['pop3_imap_daemon'] != 'dovecot') {
168168
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
169169
$app->log('Created Maildir: '."su -c 'maildirmake -q ".$data['new']['quota']."S ".$maildomain_path."' ".$user, LOGLEVEL_DEBUG);
170170
}
171171
}
172-
172+
173173
if(!is_dir($data['new']['maildir'].'/.Sent')) {
174174
$app->system->maildirmake($maildomain_path, $user, 'Sent', $group);
175175
}
@@ -182,11 +182,11 @@ function user_insert($event_name, $data) {
182182
if(!is_dir($data['new']['maildir'].'/.Junk')) {
183183
$app->system->maildirmake($maildomain_path, $user, 'Junk', $group);
184184
}
185-
185+
186186
// Set permissions now recursive
187187
$app->system->exec_safe('chown -R ?:? ?', $user, $group, $data['new']['maildir']);
188188
$app->log('Set ownership on '.$data['new']['maildir'], LOGLEVEL_DEBUG);
189-
189+
190190
//* Set the maildir quota
191191
if(is_dir($data['new']['maildir'].'/new') && $mail_config['pop3_imap_daemon'] != 'dovecot') {
192192
if($data['new']['quota'] > 0) {
@@ -263,9 +263,10 @@ function user_insert($event_name, $data) {
263263
$additionalParameters = '-f '.$matches[1];
264264
}
265265

266-
// Send the welcome email only on a "master" mail server to avoid duplicate emails
266+
// Send the welcome email only on a "master" mail server to avoid duplicate emails, and only send them when welcome emails are enabled.
267267
// (bypass the normal ispcmail class when creating mail accounts)
268-
if($conf['mirror_server_id'] == 0) mail($mailTarget, $mailSubject, $welcome_mail_message, $mailHeaders, $additionalParameters);
268+
$global_config = $app->getconf->get_global_config('mail');
269+
if($conf['mirror_server_id'] == 0 && $global_config['enable_welcome_mail'] == 'y') mail($mailTarget, $mailSubject, $welcome_mail_message, $mailHeaders, $additionalParameters);
269270

270271
}
271272

@@ -278,7 +279,7 @@ function user_update($event_name, $data) {
278279

279280
// Maildir-Format must not be changed on this way !!
280281
$data['new']['maildir_format'] = $data['old']['maildir_format'];
281-
282+
282283
$maildomain_path = $data['new']['maildir'];
283284
$tmp_basepath = $data['new']['maildir'];
284285
$tmp_basepath_parts = explode('/', $tmp_basepath);
@@ -332,15 +333,15 @@ function user_update($event_name, $data) {
332333
$app->system->exec_safe('mv -f ? ?'. $data['old']['maildir'], $data['new']['maildir']);
333334
$app->log('Moved Maildir from: '.$data['old']['maildir'].' to '.$data['new']['maildir'], LOGLEVEL_DEBUG);
334335
}
335-
336+
336337
//* Create the maildir, if it doesn not exist, set permissions, set quota.
337338
if(!is_dir($data['new']['maildir'].'/mdbox')) {
338339
$app->system->exec_safe("su -c 'doveadm mailbox create -u ? INBOX'", $data["new"]["email"]);
339340
$app->system->exec_safe("su -c 'doveadm mailbox create -u ? Sent'", $data["new"]["email"]);
340341
$app->system->exec_safe("su -c 'doveadm mailbox create -u ? Trash'", $data["new"]["email"]);
341342
$app->system->exec_safe("su -c 'doveadm mailbox create -u ? Junk'", $data["new"]["email"]);
342343
$app->system->exec_safe("su -c 'doveadm mailbox create -u ? Drafts'", $data["new"]["email"]);
343-
344+
344345
$app->system->exec_safe("su -c 'doveadm mailbox subscribe -u ? INBOX'", $data["new"]["email"]);
345346
$app->system->exec_safe("su -c 'doveadm mailbox subscribe -u ? Sent'", $data["new"]["email"]);
346347
$app->system->exec_safe("su -c 'doveadm mailbox subscribe -u ? Trash'", $data["new"]["email"]);
@@ -355,18 +356,18 @@ function user_update($event_name, $data) {
355356
$app->log('Created Directory: '.$base_path, LOGLEVEL_DEBUG);
356357
$maildomain_path .= '/Maildir';
357358
}
358-
359+
359360
//* When the mail user dir exists but it is not a valid maildir, move it to corrupted maildir folder
360361
if(!empty($maildomain_path) && is_dir($maildomain_path) && !is_dir($maildomain_path.'/new') && !is_dir($maildomain_path.'/cur')) {
361362
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']);
362363
$app->system->exec_safe("su -c ? ?", "mv -f ".$data['new']['maildir']." ".$mail_config['homedir_path'].'/corrupted/'.$data['new']['mailuser_id'], 'vmail');
363364
$app->log('Moved invalid maildir to corrupted Maildirs folder: '.$data['new']['maildir'], LOGLEVEL_WARN);
364365
}
365-
366+
366367
//* Create the maildir, if it doesn not exist, set permissions, set quota.
367368
if(!empty($maildomain_path) && !is_dir($maildomain_path.'/new')) {
368369
$app->system->maildirmake($maildomain_path, $user, '', $group);
369-
370+
370371
//* This is to fix the maildrop quota not being rebuilt after the quota is changed.
371372
if($mail_config['pop3_imap_daemon'] != 'dovecot') {
372373
if($data['new']['quota'] > 0) {
@@ -378,7 +379,7 @@ function user_update($event_name, $data) {
378379
}
379380
}
380381
}
381-
382+
382383
if(!is_dir($data['new']['maildir'].'/.Sent')) {
383384
$app->system->maildirmake($maildomain_path, $user, 'Sent', $group);
384385
}
@@ -391,11 +392,11 @@ function user_update($event_name, $data) {
391392
if(!is_dir($data['new']['maildir'].'/.Junk')) {
392393
$app->system->maildirmake($maildomain_path, $user, 'Junk', $group);
393394
}
394-
395+
395396
// Set permissions now recursive
396397
$app->system->exec_safe('chown -R ?:? ?', $user, $group, $data['new']['maildir']);
397398
$app->log('Set ownership on '.$data['new']['maildir'], LOGLEVEL_DEBUG);
398-
399+
399400
// Move mailbox, if domain has changed and delete old mailbox
400401
if($data['new']['maildir'] != $data['old']['maildir'] && is_dir($data['old']['maildir'])) {
401402
if(is_dir($data['new']['maildir'])) {
@@ -487,7 +488,7 @@ function domain_delete($event_name, $data) {
487488
} else {
488489
$app->log('Possible security violation when deleting the mail domain mailfilter directory: '.$old_maildomain_path, LOGLEVEL_ERROR);
489490
}
490-
491+
491492
//* Delete the mail-backups
492493
$server_config = $app->getconf->get_server_config($conf['server_id'], 'server');
493494
$backup_dir = $server_config['backup_dir'];

0 commit comments

Comments
 (0)