|
31 | 31 | class cronjob_clean_mailboxes extends cronjob { |
32 | 32 |
|
33 | 33 | // 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 | + |
36 | 36 | // job schedule |
37 | 37 | protected $_schedule = '00 22 * * *'; |
38 | 38 |
|
@@ -77,7 +77,7 @@ private function purge_junk_thrash() { |
77 | 77 | WHERE maildir_format = 'maildir' AND disableimap = 'n' AND server_id = ? |
78 | 78 | AND (purge_trash_days > 0 OR purge_junk_days > 0)", |
79 | 79 | $server_id); |
80 | | - |
| 80 | + |
81 | 81 | if(is_array($records) && !empty($records)) { |
82 | 82 | foreach($records as $email) { |
83 | 83 |
|
@@ -115,22 +115,25 @@ private function purge_soft_deleted_maildir() { |
115 | 115 | global $app, $conf; |
116 | 116 | $mail_config = $app->getconf->get_server_config($conf["server_id"], 'mail'); |
117 | 117 |
|
118 | | - // Convert old values in mailbox_soft_delete field. |
| 118 | + // Convert old values in mailbox_soft_delete field |
119 | 119 | if(isset($mail_config['mailbox_soft_delete']) && $mail_config['mailbox_soft_delete'] == 'n') $mail_config['mailbox_soft_delete'] = 0; |
120 | 120 | if(isset($mail_config['mailbox_soft_delete']) && $mail_config['mailbox_soft_delete'] == 'y') $mail_config['mailbox_soft_delete'] = 7; |
121 | 121 | $mail_config['mailbox_soft_delete'] = intval($mail_config['mailbox_soft_delete']); |
122 | 122 |
|
| 123 | + |
123 | 124 | 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 | + } |
134 | 137 | } |
135 | 138 | } |
136 | 139 | } |
|
0 commit comments