Skip to content

Commit 1d04112

Browse files
committed
Safe delete for mailboxes
Move it, adding a date based suffix. A cronjob should purge or archive.
1 parent c40198b commit 1d04112

File tree

5 files changed

+23
-2
lines changed

5 files changed

+23
-2
lines changed

install/tpl/server.ini.master

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ relayhost_user=
5252
relayhost_password=
5353
mailbox_size_limit=0
5454
message_size_limit=0
55+
mailbox_safe_delete=y
5556
mailbox_quota_stats=y
5657
realtime_blackhole_list=zen.spamhaus.org
5758
overquota_notify_admin=y

interface/web/admin/form/server_config.tform.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,12 @@
685685
'default' => 'y',
686686
'value' => array(0 => 'n', 1 => 'y')
687687
),
688+
'mailbox_safe_delete' => array (
689+
'datatype' => 'VARCHAR',
690+
'formtype' => 'CHECKBOX',
691+
'default' => 'y',
692+
'value' => array(0 => 'n', 1 => 'y')
693+
),
688694
'mailbox_quota_stats' => array (
689695
'datatype' => 'VARCHAR',
690696
'formtype' => 'CHECKBOX',

interface/web/admin/lib/lang/en_server_config.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,3 +332,4 @@ $wb['tooltip_jailkit_hardlinks_txt'] = 'Using hardlinks is insecure, but saves d
332332
$wb['jailkit_hardlinks_allow_txt'] = 'Allow hardlinks within the jail';
333333
$wb['jailkit_hardlinks_no_txt'] = 'No, remove hardlinked files';
334334
$wb['jailkit_hardlinks_yes_txt'] = 'Yes, use hardlinks if possible';
335+
$wb['mailbox_safe_delete_txt'] = 'Mailbox direct delete';

interface/web/admin/templates/server_config_mail_edit.htm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@
120120
<a data-toggle="tooltip" title="{tmpl_var name='tooltip_stress_adaptive_txt'}">{tmpl_var name="stress_adaptive"}</a>
121121
</div>
122122
</div>
123+
<div class="form-group">
124+
<label class="col-sm-3 control-label">{tmpl_var name='mailbox_safe_delete_txt'}</label>
125+
<div class="col-sm-9">
126+
{tmpl_var name='mailbox_safe_delete'}
127+
</div>
128+
</div>
123129
<div class="form-group">
124130
<label class="col-sm-3 control-label">{tmpl_var name='mailbox_quota_stats_txt'}</label>
125131
<div class="col-sm-9">

server/plugins-available/mail_plugin.inc.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,15 @@ function user_delete($event_name, $data) {
429429
$maildir_path_deleted = false;
430430
$old_maildir_path = $data['old']['maildir'];
431431
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) {
432-
$app->system->exec_safe('rm -rf ?', $old_maildir_path);
433-
$app->log('Deleted the Maildir: '.$data['old']['maildir'], LOGLEVEL_DEBUG);
432+
if ($mail_config['mailbox_safe_delete'] == 'n') {
433+
$app->system->exec_safe('rm -rf ?', $old_maildir_path);
434+
$app->log('Deleted the Maildir: '.$data['old']['maildir'], LOGLEVEL_DEBUG);
435+
} else {
436+
// Move it, adding a date based suffix. A cronjob should purge or archive.
437+
$thrash_maildir_path = $old_maildir_path . '-' . date("YmdHis");
438+
$app->system->exec_safe('mv ? ?', $old_maildir_path, $thrash_maildir_path);
439+
$app->log('Renamed the Maildir: ' . $data['old']['maildir'] . ' to ' . $thrash_maildir_path, LOGLEVEL_DEBUG);
440+
}
434441
$maildir_path_deleted = true;
435442
} else {
436443
$app->log('Possible security violation when deleting the maildir: '.$data['old']['maildir'], LOGLEVEL_ERROR);

0 commit comments

Comments
 (0)