Skip to content

Commit 3caef95

Browse files
author
Till Brehm
committed
Merge branch '1804-welcome-email' into 'stable-3.1'
Add option to disable email welcome messages in server settings. See merge request ispconfig/ispconfig3!1076
2 parents 1e4f8d0 + ebcbdbb commit 3caef95

File tree

3 files changed

+83
-77
lines changed

3 files changed

+83
-77
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: 73 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -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,61 +195,63 @@ function user_insert($event_name, $data) {
195195
}
196196
}
197197

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-
}
220-
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";
244-
}
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)."?=";
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+
}
249222

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);
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)."?=";
252251

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);
254+
}
253255
}
254256

255257
function user_update($event_name, $data) {
@@ -261,7 +263,7 @@ function user_update($event_name, $data) {
261263

262264
// Maildir-Format must not be changed on this way !!
263265
$data['new']['maildir_format'] = $data['old']['maildir_format'];
264-
266+
265267
$maildomain_path = $data['new']['maildir'];
266268
$tmp_basepath = $data['new']['maildir'];
267269
$tmp_basepath_parts = explode('/', $tmp_basepath);
@@ -315,15 +317,15 @@ function user_update($event_name, $data) {
315317
$app->system->exec_safe('mv -f ? ?'. $data['old']['maildir'], $data['new']['maildir']);
316318
$app->log('Moved Maildir from: '.$data['old']['maildir'].' to '.$data['new']['maildir'], LOGLEVEL_DEBUG);
317319
}
318-
320+
319321
//* Create the maildir, if it doesn not exist, set permissions, set quota.
320322
if(!is_dir($data['new']['maildir'].'/mdbox')) {
321323
$app->system->exec_safe("su -c 'doveadm mailbox create -u ? INBOX'", $data["new"]["email"]);
322324
$app->system->exec_safe("su -c 'doveadm mailbox create -u ? Sent'", $data["new"]["email"]);
323325
$app->system->exec_safe("su -c 'doveadm mailbox create -u ? Trash'", $data["new"]["email"]);
324326
$app->system->exec_safe("su -c 'doveadm mailbox create -u ? Junk'", $data["new"]["email"]);
325327
$app->system->exec_safe("su -c 'doveadm mailbox create -u ? Drafts'", $data["new"]["email"]);
326-
328+
327329
$app->system->exec_safe("su -c 'doveadm mailbox subscribe -u ? INBOX'", $data["new"]["email"]);
328330
$app->system->exec_safe("su -c 'doveadm mailbox subscribe -u ? Sent'", $data["new"]["email"]);
329331
$app->system->exec_safe("su -c 'doveadm mailbox subscribe -u ? Trash'", $data["new"]["email"]);
@@ -338,18 +340,18 @@ function user_update($event_name, $data) {
338340
$app->log('Created Directory: '.$base_path, LOGLEVEL_DEBUG);
339341
$maildomain_path .= '/Maildir';
340342
}
341-
343+
342344
//* When the mail user dir exists but it is not a valid maildir, move it to corrupted maildir folder
343345
if(!empty($maildomain_path) && is_dir($maildomain_path) && !is_dir($maildomain_path.'/new') && !is_dir($maildomain_path.'/cur')) {
344346
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']);
345347
$app->system->exec_safe("su -c ? ?", "mv -f ".$data['new']['maildir']." ".$mail_config['homedir_path'].'/corrupted/'.$data['new']['mailuser_id'], 'vmail');
346348
$app->log('Moved invalid maildir to corrupted Maildirs folder: '.$data['new']['maildir'], LOGLEVEL_WARN);
347349
}
348-
350+
349351
//* Create the maildir, if it doesn not exist, set permissions, set quota.
350352
if(!empty($maildomain_path) && !is_dir($maildomain_path.'/new')) {
351353
$app->system->maildirmake($maildomain_path, $user, '', $group);
352-
354+
353355
//* This is to fix the maildrop quota not being rebuilt after the quota is changed.
354356
if($mail_config['pop3_imap_daemon'] != 'dovecot') {
355357
if($data['new']['quota'] > 0) {
@@ -361,7 +363,7 @@ function user_update($event_name, $data) {
361363
}
362364
}
363365
}
364-
366+
365367
if(!is_dir($data['new']['maildir'].'/.Sent')) {
366368
$app->system->maildirmake($maildomain_path, $user, 'Sent', $group);
367369
}
@@ -374,11 +376,11 @@ function user_update($event_name, $data) {
374376
if(!is_dir($data['new']['maildir'].'/.Junk')) {
375377
$app->system->maildirmake($maildomain_path, $user, 'Junk', $group);
376378
}
377-
379+
378380
// Set permissions now recursive
379381
$app->system->exec_safe('chown -R ?:? ?', $user, $group, $data['new']['maildir']);
380382
$app->log('Set ownership on '.$data['new']['maildir'], LOGLEVEL_DEBUG);
381-
383+
382384
// Move mailbox, if domain has changed and delete old mailbox
383385
if($data['new']['maildir'] != $data['old']['maildir'] && is_dir($data['old']['maildir'])) {
384386
if(is_dir($data['new']['maildir'])) {
@@ -470,7 +472,7 @@ function domain_delete($event_name, $data) {
470472
} else {
471473
$app->log('Possible security violation when deleting the mail domain mailfilter directory: '.$old_maildomain_path, LOGLEVEL_ERROR);
472474
}
473-
475+
474476
//* Delete the mail-backups
475477
$server_config = $app->getconf->get_server_config($conf['server_id'], 'server');
476478
$backup_dir = $server_config['backup_dir'];

server/plugins-available/mailman_plugin.inc.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,12 @@ function onLoad() {
7171
function insert($event_name, $data) {
7272
global $app, $conf;
7373

74+
$global_config = $app->getconf->get_global_config('mail');
75+
$opt_quiet = ($global_config['enable_welcome_mail'] == 'n') ? "-q" : "";
76+
7477
$this->update_config();
7578

76-
$pid = $app->system->exec_safe("nohup /usr/lib/mailman/bin/newlist -u ? -e ? ? ? ? >/dev/null 2>&1 & echo $!;", $data["new"]["domain"], $data["new"]["domain"], $data["new"]["listname"], $data["new"]["email"], $data["new"]["password"]);
79+
$pid = $app->system->exec_safe("nohup /usr/lib/mailman/bin/newlist ? -u ? -e ? ? ? ? >/dev/null 2>&1 & echo $!;", $opt_quiet, $data["new"]["domain"], $data["new"]["domain"], $data["new"]["listname"], $data["new"]["email"], $data["new"]["password"]);
7780
// wait for /usr/lib/mailman/bin/newlist-call
7881
$running = true;
7982
do {
@@ -87,9 +90,9 @@ function insert($event_name, $data) {
8790
}
8891
if(is_file('/var/lib/mailman/data/virtual-mailman')) exec('postmap /var/lib/mailman/data/virtual-mailman');
8992
if(is_file('/var/lib/mailman/data/transport-mailman')) exec('postmap /var/lib/mailman/data/transport-mailman');
90-
93+
9194
exec('nohup '.$conf['init_scripts'] . '/' . 'mailman reload >/dev/null 2>&1 &');
92-
95+
9396
// Fix list URL
9497
$app->system->exec_safe('/usr/sbin/withlist -l -r fix_url ?', $data["new"]["listname"]);
9598

@@ -100,15 +103,15 @@ function insert($event_name, $data) {
100103
// The purpose of this plugin is to rewrite the main.cf file
101104
function update($event_name, $data) {
102105
global $app, $conf;
103-
106+
104107
$this->update_config();
105108

106109
if($data["new"]["password"] != $data["old"]["password"] && $data["new"]["password"] != '') {
107110
$app->system->exec_safe("nohup /usr/lib/mailman/bin/change_pw -l ? -p ? >/dev/null 2>&1 &", $data["new"]["listname"], $data["new"]["password"]);
108111
exec('nohup '.$conf['init_scripts'] . '/' . 'mailman reload >/dev/null 2>&1 &');
109112
$app->db->query("UPDATE mail_mailinglist SET password = '' WHERE mailinglist_id = ?", $data["new"]['mailinglist_id']);
110113
}
111-
114+
112115
if(is_file('/var/lib/mailman/data/virtual-mailman')) exec('postmap /var/lib/mailman/data/virtual-mailman');
113116
if(is_file('/var/lib/mailman/data/transport-mailman')) exec('postmap /var/lib/mailman/data/transport-mailman');
114117
}
@@ -121,7 +124,7 @@ function delete($event_name, $data) {
121124
$app->system->exec_safe("nohup /usr/lib/mailman/bin/rmlist -a ? >/dev/null 2>&1 &", $data["old"]["listname"]);
122125

123126
exec('nohup '.$conf['init_scripts'] . '/' . 'mailman reload >/dev/null 2>&1 &');
124-
127+
125128
if(is_file('/var/lib/mailman/data/virtual-mailman')) exec('postmap /var/lib/mailman/data/virtual-mailman');
126129
if(is_file('/var/lib/mailman/data/transport-mailman')) exec('postmap /var/lib/mailman/data/transport-mailman');
127130

0 commit comments

Comments
 (0)