commit | author | age
|
b5a23a
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
|
4 |
Copyright (c) 2007, Till Brehm, projektfarm Gmbh |
|
5 |
All rights reserved. |
|
6 |
|
|
7 |
Redistribution and use in source and binary forms, with or without modification, |
|
8 |
are permitted provided that the following conditions are met: |
|
9 |
|
|
10 |
* Redistributions of source code must retain the above copyright notice, |
|
11 |
this list of conditions and the following disclaimer. |
|
12 |
* Redistributions in binary form must reproduce the above copyright notice, |
|
13 |
this list of conditions and the following disclaimer in the documentation |
|
14 |
and/or other materials provided with the distribution. |
|
15 |
* Neither the name of ISPConfig nor the names of its contributors |
|
16 |
may be used to endorse or promote products derived from this software without |
|
17 |
specific prior written permission. |
|
18 |
|
|
19 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
|
20 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
21 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
22 |
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
|
23 |
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
24 |
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
25 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
26 |
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
27 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
|
28 |
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
29 |
*/ |
|
30 |
|
|
31 |
class mail_plugin { |
7fe908
|
32 |
|
b5a23a
|
33 |
var $plugin_name = 'mail_plugin'; |
T |
34 |
var $class_name = 'mail_plugin'; |
7fe908
|
35 |
|
392450
|
36 |
//* This function is called during ispconfig installation to determine |
T |
37 |
// if a symlink shall be created for this plugin. |
|
38 |
function onInstall() { |
|
39 |
global $conf; |
7fe908
|
40 |
|
392450
|
41 |
if($conf['services']['mail'] == true) { |
T |
42 |
return true; |
|
43 |
} else { |
|
44 |
return false; |
|
45 |
} |
7fe908
|
46 |
|
392450
|
47 |
} |
7fe908
|
48 |
|
MC |
49 |
|
b5a23a
|
50 |
/* |
T |
51 |
This function is called when the plugin is loaded |
|
52 |
*/ |
7fe908
|
53 |
|
b5a23a
|
54 |
function onLoad() { |
T |
55 |
global $app; |
7fe908
|
56 |
|
b5a23a
|
57 |
/* |
T |
58 |
Register for the events |
|
59 |
*/ |
7fe908
|
60 |
|
4585cf
|
61 |
//* Mailboxes |
7fe908
|
62 |
$app->plugins->registerEvent('mail_user_insert', $this->plugin_name, 'user_insert'); |
MC |
63 |
$app->plugins->registerEvent('mail_user_update', $this->plugin_name, 'user_update'); |
|
64 |
$app->plugins->registerEvent('mail_user_delete', $this->plugin_name, 'user_delete'); |
|
65 |
|
4585cf
|
66 |
//* Mail Domains |
T |
67 |
//$app->plugins->registerEvent('mail_domain_insert',$this->plugin_name,'domain_insert'); |
|
68 |
//$app->plugins->registerEvent('mail_domain_update',$this->plugin_name,'domain_update'); |
7fe908
|
69 |
$app->plugins->registerEvent('mail_domain_delete', $this->plugin_name, 'domain_delete'); |
MC |
70 |
|
9234cc
|
71 |
//* Mail transports |
7fe908
|
72 |
$app->plugins->registerEvent('mail_transport_insert', $this->plugin_name, 'transport_update'); |
MC |
73 |
$app->plugins->registerEvent('mail_transport_update', $this->plugin_name, 'transport_update'); |
|
74 |
$app->plugins->registerEvent('mail_transport_delete', $this->plugin_name, 'transport_update'); |
|
75 |
|
b5a23a
|
76 |
} |
7fe908
|
77 |
|
MC |
78 |
|
|
79 |
function user_insert($event_name, $data) { |
b5a23a
|
80 |
global $app, $conf; |
7fe908
|
81 |
|
f12a6c
|
82 |
//* get the config |
663caf
|
83 |
$app->uses('getconf,system'); |
J |
84 |
$mail_config = $app->getconf->get_server_config($conf['server_id'], 'mail'); |
06303b
|
85 |
|
T |
86 |
// convert to lower case - it could cause problems if some directory above has upper case name |
7fe908
|
87 |
// $data['new']['maildir'] = strtolower($data['new']['maildir']); |
MC |
88 |
|
f12a6c
|
89 |
$maildomain_path = $data['new']['maildir']; |
T |
90 |
$tmp_basepath = $data['new']['maildir']; |
7fe908
|
91 |
$tmp_basepath_parts = explode('/', $tmp_basepath); |
f12a6c
|
92 |
unset($tmp_basepath_parts[count($tmp_basepath_parts)-1]); |
7fe908
|
93 |
$base_path = implode('/', $tmp_basepath_parts); |
f12a6c
|
94 |
|
T |
95 |
//* Create the mail domain directory, if it does not exist |
|
96 |
if(!empty($base_path) && !is_dir($base_path)) { |
355efb
|
97 |
//exec("su -c 'mkdir -p ".escapeshellcmd($base_path)."' ".$mail_config['mailuser_name']); |
T |
98 |
$app->system->mkdirpath($base_path, 0700, $mail_config['mailuser_name'], $mail_config['mailuser_group']); |
7fe908
|
99 |
$app->log('Created Directory: '.$base_path, LOGLEVEL_DEBUG); |
6cc49f
|
100 |
} |
7fe908
|
101 |
|
6cc49f
|
102 |
// Dovecot uses a different mail layout with a separate 'Maildir' subdirectory. |
T |
103 |
if($mail_config['pop3_imap_daemon'] == 'dovecot') { |
355efb
|
104 |
//exec("su -c 'mkdir -p ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']); |
T |
105 |
$app->system->mkdirpath($maildomain_path, 0700, $mail_config['mailuser_name'], $mail_config['mailuser_group']); |
7fe908
|
106 |
$app->log('Created Directory: '.$maildomain_path, LOGLEVEL_DEBUG); |
6cc49f
|
107 |
$maildomain_path .= '/Maildir'; |
b5a23a
|
108 |
} |
7fe908
|
109 |
|
a6a997
|
110 |
//* When the mail user dir exists but it is not a valid maildir, move it to corrupted maildir folder |
b6b793
|
111 |
if(!empty($maildomain_path) && is_dir($maildomain_path) && !is_dir($maildomain_path.'/new') && !is_dir($maildomain_path.'/cur')) { |
a6a997
|
112 |
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']); |
TB |
113 |
exec("su -c 'mv -f ".escapeshellcmd($data['new']['maildir'])." ".$mail_config['homedir_path'].'/corrupted/'.$data['new']['mailuser_id']."' vmail"); |
|
114 |
$app->log('Moved invalid maildir to corrupted Maildirs folder: '.escapeshellcmd($data['new']['maildir']), LOGLEVEL_WARN); |
b6b793
|
115 |
} |
f12a6c
|
116 |
|
T |
117 |
//* Create the maildir, if it doesn not exist, set permissions, set quota. |
|
118 |
if(!empty($maildomain_path) && !is_dir($maildomain_path)) { |
06303b
|
119 |
|
fdb514
|
120 |
//exec("su -c 'maildirmake ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']); |
7fe908
|
121 |
$app->system->maildirmake($maildomain_path, $mail_config['mailuser_name']); |
06303b
|
122 |
|
f12a6c
|
123 |
exec('chown -R '.$mail_config['mailuser_name'].':'.$mail_config['mailuser_group'].' '.escapeshellcmd($data['new']['maildir'])); |
7fe908
|
124 |
$app->log('Set ownership on '.escapeshellcmd($data['new']['maildir']), LOGLEVEL_DEBUG); |
06303b
|
125 |
|
f12a6c
|
126 |
//* This is to fix the maildrop quota not being rebuilt after the quota is changed. |
2b7e04
|
127 |
if($mail_config['pop3_imap_daemon'] != 'dovecot') { |
0be7e1
|
128 |
if(is_dir($maildomain_path)) exec("su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']); // Avoid maildirmake quota bug, see debian bug #214911 |
7fe908
|
129 |
$app->log('Created Maildir: '."su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'], LOGLEVEL_DEBUG); |
2b7e04
|
130 |
} |
0ca0b8
|
131 |
} |
7fe908
|
132 |
|
0ca0b8
|
133 |
if(!is_dir($data['new']['maildir'].'/.Sent')) { |
T |
134 |
//exec("su -c 'maildirmake -f Sent ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']); |
|
135 |
//$app->log('Created submaildir Sent: '."su -c 'maildirmake -f Sent ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG); |
7fe908
|
136 |
$app->system->maildirmake($maildomain_path, $mail_config['mailuser_name'], 'Sent'); |
0ca0b8
|
137 |
} |
T |
138 |
if(!is_dir($data['new']['maildir'].'/.Drafts')) { |
|
139 |
//exec("su -c 'maildirmake -f Drafts ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']); |
|
140 |
//$app->log('Created submaildir Drafts: '."su -c 'maildirmake -f Drafts ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG); |
7fe908
|
141 |
$app->system->maildirmake($maildomain_path, $mail_config['mailuser_name'], 'Drafts'); |
0ca0b8
|
142 |
} |
T |
143 |
if(!is_dir($data['new']['maildir'].'/.Trash')) { |
|
144 |
//exec("su -c 'maildirmake -f Trash ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']); |
|
145 |
//$app->log('Created submaildir Trash: '."su -c 'maildirmake -f Trash ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG); |
7fe908
|
146 |
$app->system->maildirmake($maildomain_path, $mail_config['mailuser_name'], 'Trash'); |
0ca0b8
|
147 |
} |
T |
148 |
if(!is_dir($data['new']['maildir'].'/.Junk')) { |
|
149 |
//exec("su -c 'maildirmake -f Junk ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']); |
|
150 |
//$app->log('Created submaildir Junk: '."su -c 'maildirmake -f Junk ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG); |
7fe908
|
151 |
$app->system->maildirmake($maildomain_path, $mail_config['mailuser_name'], 'Junk'); |
a3e2d2
|
152 |
} |
7fe908
|
153 |
|
a3e2d2
|
154 |
//* Set the maildir quota |
2b7e04
|
155 |
if(is_dir($data['new']['maildir'].'/new') && $mail_config['pop3_imap_daemon'] != 'dovecot') { |
1ca823
|
156 |
if($data['new']['quota'] > 0) { |
0be7e1
|
157 |
if(is_dir($data['new']['maildir'])) exec("su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($data['new']['maildir'])."' ".$mail_config['mailuser_name']); |
7fe908
|
158 |
$app->log('Set Maildir quota: '."su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($data['new']['maildir'])."' ".$mail_config['mailuser_name'], LOGLEVEL_DEBUG); |
1ca823
|
159 |
} |
f42df0
|
160 |
} |
7fe908
|
161 |
|
92e509
|
162 |
//* Send the welcome email message |
T |
163 |
if(file_exists($conf['rootpath'].'/conf-custom/mail/welcome_email_'.$conf['language'].'.txt')) { |
355efb
|
164 |
$lines = file($conf['rootpath'].'/conf-custom/mail/welcome_email_'.$conf['language'].'.txt'); |
92e509
|
165 |
} elseif(file_exists($conf['rootpath'].'/conf-custom/mail/welcome_email_en.txt')) { |
355efb
|
166 |
$lines = file($conf['rootpath'].'/conf-custom/mail/welcome_email_en.txt'); |
92e509
|
167 |
} elseif(file_exists($conf['rootpath'].'/conf/mail/welcome_email_'.$conf['language'].'.txt')) { |
355efb
|
168 |
$lines = file($conf['rootpath'].'/conf/mail/welcome_email_'.$conf['language'].'.txt'); |
92e509
|
169 |
} else { |
355efb
|
170 |
$lines = file($conf['rootpath'].'/conf/mail/welcome_email_en.txt'); |
92e509
|
171 |
} |
7fe908
|
172 |
|
355efb
|
173 |
//* Get from address |
7fe908
|
174 |
$parts = explode(':', trim($lines[0])); |
355efb
|
175 |
unset($parts[0]); |
7fe908
|
176 |
$welcome_mail_from = implode(':', $parts); |
355efb
|
177 |
unset($lines[0]); |
7fe908
|
178 |
|
355efb
|
179 |
//* Get subject |
7fe908
|
180 |
$parts = explode(':', trim($lines[1])); |
355efb
|
181 |
unset($parts[0]); |
7fe908
|
182 |
$welcome_mail_subject = implode(':', $parts); |
355efb
|
183 |
unset($lines[1]); |
7fe908
|
184 |
|
355efb
|
185 |
//* Get message |
T |
186 |
$welcome_mail_message = trim(implode($lines)); |
|
187 |
unset($tmp); |
7fe908
|
188 |
|
92e509
|
189 |
$mailHeaders = "MIME-Version: 1.0" . "\n"; |
T |
190 |
$mailHeaders .= "Content-type: text/plain; charset=utf-8" . "\n"; |
|
191 |
$mailHeaders .= "Content-Transfer-Encoding: 8bit" . "\n"; |
6d49fc
|
192 |
$mailHeaders .= "From: $welcome_mail_from" . "\n"; |
T |
193 |
$mailHeaders .= "Reply-To: $welcome_mail_from" . "\n"; |
92e509
|
194 |
$mailTarget = $data["new"]["email"]; |
f682c3
|
195 |
$mailSubject = "=?utf-8?B?".base64_encode($welcome_mail_subject)."?="; |
92e509
|
196 |
|
992797
|
197 |
//* Send the welcome email only on the "master" mail server to avoid duplicate emails |
MC |
198 |
if($conf['mirror_server_id'] == 0) mail($mailTarget, $mailSubject, $welcome_mail_message, $mailHeaders); |
7fe908
|
199 |
|
b5a23a
|
200 |
} |
7fe908
|
201 |
|
MC |
202 |
function user_update($event_name, $data) { |
b5a23a
|
203 |
global $app, $conf; |
7fe908
|
204 |
|
b5a23a
|
205 |
// get the config |
663caf
|
206 |
$app->uses('getconf,system'); |
J |
207 |
$mail_config = $app->getconf->get_server_config($conf['server_id'], 'mail'); |
06303b
|
208 |
|
T |
209 |
// convert to lower case - it could cause problems if some directory above has upper case name |
|
210 |
// $data['new']['maildir'] = strtolower($data['new']['maildir']); |
7fe908
|
211 |
|
b5a23a
|
212 |
// Create the maildir, if it does not exist |
f42df0
|
213 |
/* |
be40ba
|
214 |
if(!is_dir($data['new']['maildir'])) { |
663caf
|
215 |
mkdir(escapeshellcmd($data['new']['maildir']), 0, true); |
J |
216 |
chown(escapeshellcmd($data['new']['maildir']), $mail_config['mailuser_name']); |
|
217 |
chgrp(escapeshellcmd($data['new']['maildir']), $mail_config['mailuser_group']); |
b5a23a
|
218 |
$app->log('Created Maildir: '.$data['new']['maildir'],LOGLEVEL_DEBUG); |
f42df0
|
219 |
} |
T |
220 |
*/ |
7fe908
|
221 |
|
f42df0
|
222 |
$maildomain_path = $data['new']['maildir']; |
T |
223 |
$tmp_basepath = $data['new']['maildir']; |
7fe908
|
224 |
$tmp_basepath_parts = explode('/', $tmp_basepath); |
f42df0
|
225 |
unset($tmp_basepath_parts[count($tmp_basepath_parts)-1]); |
7fe908
|
226 |
$base_path = implode('/', $tmp_basepath_parts); |
f42df0
|
227 |
|
T |
228 |
//* Create the mail domain directory, if it does not exist |
|
229 |
if(!empty($base_path) && !is_dir($base_path)) { |
355efb
|
230 |
//exec("su -c 'mkdir -p ".escapeshellcmd($base_path)."' ".$mail_config['mailuser_name']); |
T |
231 |
$app->system->mkdirpath($base_path, 0700, $mail_config['mailuser_name'], $mail_config['mailuser_group']); |
7fe908
|
232 |
$app->log('Created Directory: '.$base_path, LOGLEVEL_DEBUG); |
f42df0
|
233 |
} |
7fe908
|
234 |
|
6cc49f
|
235 |
// Dovecot uses a different mail layout with a separate 'Maildir' subdirectory. |
T |
236 |
if($mail_config['pop3_imap_daemon'] == 'dovecot') { |
355efb
|
237 |
$app->system->mkdirpath($maildomain_path, 0700, $mail_config['mailuser_name'], $mail_config['mailuser_group']); |
7fe908
|
238 |
$app->log('Created Directory: '.$base_path, LOGLEVEL_DEBUG); |
6cc49f
|
239 |
$maildomain_path .= '/Maildir'; |
T |
240 |
} |
7fe908
|
241 |
|
a6a997
|
242 |
//* When the mail user dir exists but it is not a valid maildir, move it to corrupted maildir folder |
b6b793
|
243 |
if(!empty($maildomain_path) && is_dir($maildomain_path) && !is_dir($maildomain_path.'/new') && !is_dir($maildomain_path.'/cur')) { |
a6a997
|
244 |
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']); |
TB |
245 |
exec("su -c 'mv -f ".escapeshellcmd($data['new']['maildir'])." ".$mail_config['homedir_path'].'/corrupted/'.$data['new']['mailuser_id']."' vmail"); |
|
246 |
$app->log('Moved invalid maildir to corrupted Maildirs folder: '.escapeshellcmd($data['new']['maildir']), LOGLEVEL_WARN); |
b6b793
|
247 |
} |
f42df0
|
248 |
|
T |
249 |
//* Create the maildir, if it doesn not exist, set permissions, set quota. |
b6b793
|
250 |
if(!empty($maildomain_path) && !is_dir($maildomain_path.'/new')) { |
fdb514
|
251 |
//exec("su -c 'maildirmake ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']); |
T |
252 |
//$app->log("Created Maildir "."su -c 'maildirmake ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG); |
7fe908
|
253 |
$app->system->maildirmake($maildomain_path, $mail_config['mailuser_name']); |
06303b
|
254 |
|
f42df0
|
255 |
exec('chown -R '.$mail_config['mailuser_name'].':'.$mail_config['mailuser_group'].' '.escapeshellcmd($data['new']['maildir'])); |
7fe908
|
256 |
$app->log('Set ownership on '.escapeshellcmd($data['new']['maildir']), LOGLEVEL_DEBUG); |
f42df0
|
257 |
//* This is to fix the maildrop quota not being rebuilt after the quota is changed. |
2b7e04
|
258 |
if($mail_config['pop3_imap_daemon'] != 'dovecot') { |
1ca823
|
259 |
if($data['new']['quota'] > 0) { |
0be7e1
|
260 |
if(is_dir($maildomain_path)) exec("su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']); // Avoid maildirmake quota bug, see debian bug #214911 |
7fe908
|
261 |
$app->log('Updated Maildir quota: '."su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'], LOGLEVEL_DEBUG); |
1ca823
|
262 |
} else { |
T |
263 |
if(file_exists($data['new']['maildir'].'/maildirsize')) unlink($data['new']['maildir'].'/maildirsize'); |
7fe908
|
264 |
$app->log('Set Maildir quota to unlimited.', LOGLEVEL_DEBUG); |
1ca823
|
265 |
} |
2b7e04
|
266 |
} |
b5a23a
|
267 |
} |
7fe908
|
268 |
|
0ca0b8
|
269 |
if(!is_dir($data['new']['maildir'].'/.Sent')) { |
T |
270 |
//exec("su -c 'maildirmake -f Sent ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']); |
|
271 |
//$app->log('Created submaildir Sent: '."su -c 'maildirmake -f Sent ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG); |
7fe908
|
272 |
$app->system->maildirmake($maildomain_path, $mail_config['mailuser_name'], 'Sent'); |
0ca0b8
|
273 |
} |
T |
274 |
if(!is_dir($data['new']['maildir'].'/.Drafts')) { |
|
275 |
//exec("su -c 'maildirmake -f Drafts ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']); |
|
276 |
//$app->log('Created submaildir Drafts: '."su -c 'maildirmake -f Drafts ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG); |
7fe908
|
277 |
$app->system->maildirmake($maildomain_path, $mail_config['mailuser_name'], 'Drafts'); |
0ca0b8
|
278 |
} |
T |
279 |
if(!is_dir($data['new']['maildir'].'/.Trash')) { |
|
280 |
//exec("su -c 'maildirmake -f Trash ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']); |
|
281 |
//$app->log('Created submaildir Trash: '."su -c 'maildirmake -f Trash ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG); |
7fe908
|
282 |
$app->system->maildirmake($maildomain_path, $mail_config['mailuser_name'], 'Trash'); |
0ca0b8
|
283 |
} |
T |
284 |
if(!is_dir($data['new']['maildir'].'/.Junk')) { |
|
285 |
//exec("su -c 'maildirmake -f Junk ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name']); |
|
286 |
//$app->log('Created submaildir Junk: '."su -c 'maildirmake -f Junk ".escapeshellcmd($maildomain_path)."' ".$mail_config['mailuser_name'],LOGLEVEL_DEBUG); |
7fe908
|
287 |
$app->system->maildirmake($maildomain_path, $mail_config['mailuser_name'], 'Junk'); |
0ca0b8
|
288 |
} |
7fe908
|
289 |
|
b5a23a
|
290 |
// Move mailbox, if domain has changed and delete old mailbox |
T |
291 |
if($data['new']['maildir'] != $data['old']['maildir'] && is_dir($data['old']['maildir'])) { |
f12a6c
|
292 |
if(is_dir($data['new']['maildir'])) { |
6f8175
|
293 |
exec("rm -fr ".escapeshellcmd($data['new']['maildir'])); |
F |
294 |
//rmdir($data['new']['maildir']); |
f12a6c
|
295 |
} |
T |
296 |
exec('mv -f '.escapeshellcmd($data['old']['maildir']).' '.escapeshellcmd($data['new']['maildir'])); |
|
297 |
// exec('mv -f '.escapeshellcmd($data['old']['maildir']).'/* '.escapeshellcmd($data['new']['maildir'])); |
|
298 |
// if(is_file($data['old']['maildir'].'.ispconfig_mailsize'))exec('mv -f '.escapeshellcmd($data['old']['maildir']).'.ispconfig_mailsize '.escapeshellcmd($data['new']['maildir'])); |
|
299 |
// rmdir($data['old']['maildir']); |
7fe908
|
300 |
$app->log('Moved Maildir from: '.$data['old']['maildir'].' to '.$data['new']['maildir'], LOGLEVEL_DEBUG); |
b5a23a
|
301 |
} |
7cba4d
|
302 |
//This is to fix the maildrop quota not being rebuilt after the quota is changed. |
6cc49f
|
303 |
// Courier Layout |
2b7e04
|
304 |
if(is_dir($data['new']['maildir'].'/new') && $mail_config['pop3_imap_daemon'] != 'dovecot') { |
1ca823
|
305 |
if($data['new']['quota'] > 0) { |
0be7e1
|
306 |
if(is_dir($data['new']['maildir'])) exec("su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($data['new']['maildir'])."' ".$mail_config['mailuser_name']); |
7fe908
|
307 |
$app->log('Updated Maildir quota: '."su -c 'maildirmake -q ".$data['new']['quota']."S ".escapeshellcmd($data['new']['maildir'])."' ".$mail_config['mailuser_name'], LOGLEVEL_DEBUG); |
1ca823
|
308 |
} else { |
T |
309 |
if(file_exists($data['new']['maildir'].'/maildirsize')) unlink($data['new']['maildir'].'/maildirsize'); |
7fe908
|
310 |
$app->log('Set Maildir quota to unlimited.', LOGLEVEL_DEBUG); |
1ca823
|
311 |
} |
6cc49f
|
312 |
} |
b5a23a
|
313 |
} |
7fe908
|
314 |
|
MC |
315 |
function user_delete($event_name, $data) { |
b5a23a
|
316 |
global $app, $conf; |
7fe908
|
317 |
|
26c0fc
|
318 |
// get the config |
T |
319 |
$app->uses("getconf"); |
|
320 |
$mail_config = $app->getconf->get_server_config($conf['server_id'], 'mail'); |
7fe908
|
321 |
|
b5a23a
|
322 |
$old_maildir_path = escapeshellcmd($data['old']['maildir']); |
7fe908
|
323 |
if($old_maildir_path != $mail_config['homedir_path'] && strlen($old_maildir_path) > strlen($mail_config['homedir_path']) && !stristr($old_maildir_path, '//') && !stristr($old_maildir_path, '..') && !stristr($old_maildir_path, '*') && strlen($old_maildir_path) >= 10) { |
958705
|
324 |
exec('rm -rf '.escapeshellcmd($old_maildir_path)); |
7fe908
|
325 |
$app->log('Deleted the Maildir: '.$data['old']['maildir'], LOGLEVEL_DEBUG); |
b5a23a
|
326 |
} else { |
7fe908
|
327 |
$app->log('Possible security violation when deleting the maildir: '.$data['old']['maildir'], LOGLEVEL_ERROR); |
b5a23a
|
328 |
} |
T |
329 |
} |
7fe908
|
330 |
|
MC |
331 |
function domain_delete($event_name, $data) { |
0c4be7
|
332 |
global $app, $conf; |
7fe908
|
333 |
|
0c4be7
|
334 |
// get the config |
T |
335 |
$app->uses("getconf"); |
663caf
|
336 |
$mail_config = $app->getconf->get_server_config($conf['server_id'], 'mail'); |
7fe908
|
337 |
|
06303b
|
338 |
//* Delete maildomain path |
0c4be7
|
339 |
$old_maildomain_path = escapeshellcmd($mail_config['homedir_path'].'/'.$data['old']['domain']); |
7fe908
|
340 |
if($old_maildomain_path != $mail_config['homedir_path'] && !stristr($old_maildomain_path, '//') && !stristr($old_maildomain_path, '..') && !stristr($old_maildomain_path, '*') && !stristr($old_maildomain_path, '&') && strlen($old_maildomain_path) >= 10 && !empty($data['old']['domain'])) { |
0c4be7
|
341 |
exec('rm -rf '.escapeshellcmd($old_maildomain_path)); |
7fe908
|
342 |
$app->log('Deleted the mail domain directory: '.$old_maildomain_path, LOGLEVEL_DEBUG); |
0c4be7
|
343 |
} else { |
7fe908
|
344 |
$app->log('Possible security violation when deleting the mail domain directory: '.$old_maildomain_path, LOGLEVEL_ERROR); |
0c4be7
|
345 |
} |
7fe908
|
346 |
|
06303b
|
347 |
//* Delete mailfilter path |
T |
348 |
$old_maildomain_path = escapeshellcmd($mail_config['homedir_path'].'/mailfilters/'.$data['old']['domain']); |
7fe908
|
349 |
if($old_maildomain_path != $mail_config['homedir_path'].'/mailfilters/' && !stristr($old_maildomain_path, '//') && !stristr($old_maildomain_path, '..') && !stristr($old_maildomain_path, '*') && !stristr($old_maildomain_path, '&') && strlen($old_maildomain_path) >= 10 && !empty($data['old']['domain'])) { |
06303b
|
350 |
exec('rm -rf '.escapeshellcmd($old_maildomain_path)); |
7fe908
|
351 |
$app->log('Deleted the mail domain mailfilter directory: '.$old_maildomain_path, LOGLEVEL_DEBUG); |
06303b
|
352 |
} else { |
7fe908
|
353 |
$app->log('Possible security violation when deleting the mail domain mailfilter directory: '.$old_maildomain_path, LOGLEVEL_ERROR); |
06303b
|
354 |
} |
0c4be7
|
355 |
} |
7fe908
|
356 |
|
MC |
357 |
function transport_update($event_name, $data) { |
9234cc
|
358 |
global $app, $conf; |
7fe908
|
359 |
|
663caf
|
360 |
exec($conf['init_scripts'] . '/' . 'postfix reload &> /dev/null'); |
7fe908
|
361 |
$app->log('Postfix config reloaded ', LOGLEVEL_DEBUG); |
MC |
362 |
|
9234cc
|
363 |
} |
7fe908
|
364 |
|
MC |
365 |
|
|
366 |
|
b5a23a
|
367 |
|
T |
368 |
} // end class |
|
369 |
|
663caf
|
370 |
?> |