Skip to content

Commit a4aab7f

Browse files
author
Till Brehm
committed
Update 500-clean_mailboxes.inc.php
1 parent 70c4945 commit a4aab7f

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

server/lib/classes/cron.d/500-clean_mailboxes.inc.php

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
class cronjob_clean_mailboxes extends cronjob {
3232

3333
// should run before quota notify and backup
34-
// quota notify and backup is both '0 0 * * *'
35-
34+
// quota notify and backup is both '0 0 * * *'
35+
3636
// job schedule
3737
protected $_schedule = '00 22 * * *';
3838

@@ -77,7 +77,7 @@ private function purge_junk_thrash() {
7777
WHERE maildir_format = 'maildir' AND disableimap = 'n' AND server_id = ?
7878
AND (purge_trash_days > 0 OR purge_junk_days > 0)",
7979
$server_id);
80-
80+
8181
if(is_array($records) && !empty($records)) {
8282
foreach($records as $email) {
8383

@@ -115,22 +115,25 @@ private function purge_soft_deleted_maildir() {
115115
global $app, $conf;
116116
$mail_config = $app->getconf->get_server_config($conf["server_id"], 'mail');
117117

118-
// Convert old values in mailbox_soft_delete field.
118+
// Convert old values in mailbox_soft_delete field
119119
if(isset($mail_config['mailbox_soft_delete']) && $mail_config['mailbox_soft_delete'] == 'n') $mail_config['mailbox_soft_delete'] = 0;
120120
if(isset($mail_config['mailbox_soft_delete']) && $mail_config['mailbox_soft_delete'] == 'y') $mail_config['mailbox_soft_delete'] = 7;
121121
$mail_config['mailbox_soft_delete'] = intval($mail_config['mailbox_soft_delete']);
122122

123+
123124
if ($mail_config['mailbox_soft_delete'] > 0) {
124-
$matched_dirs = glob($mail_config['homedir_path'] . "/*/[a-z0-9.-]*-deleted-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]");
125-
126-
if (!empty($matched_dirs)) {
127-
$delay_days = $mail_config['mailbox_soft_delete'];
128-
foreach($matched_dirs as $dir) {
129-
if (is_dir($dir)) {
130-
$mtime = filemtime($dir);
131-
if ($mtime < strtotime("-$delay_days days")) {
132-
// do remove
133-
$app->system->exec_safe('rm -rf ?', $dir);
125+
if(isset($mail_config['homedir_path']) || strlen($mail_config['homedir_path']) > 4) {
126+
$matched_dirs = glob($mail_config['homedir_path'] . "/*/[a-z0-9.-]*-deleted-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]");
127+
128+
if (!empty($matched_dirs)) {
129+
$delay_days = $mail_config['mailbox_soft_delete'];
130+
foreach($matched_dirs as $dir) {
131+
if (is_dir($dir)) {
132+
$mtime = filemtime($dir);
133+
if ($mtime < strtotime("-$delay_days days")) {
134+
// do remove
135+
$app->system->exec_safe('sudo -u vmail rm -rf ?', $dir);
136+
}
134137
}
135138
}
136139
}

0 commit comments

Comments
 (0)