Skip to content

Commit

Permalink
Add option to purge deleted mails older than 30, 60 or 90 days (#5493)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecpl committed Aug 29, 2021
1 parent cb37d14 commit d7338a4
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@
- Dropped support for strftime-like format (with % sign) in date and time format configuration
- Replace Endroid QrCode with BaconQrCode (#8173)
- Support responses (snippets) in HTML format (#5315)
- Add option to purge deleted mails older than 30, 60 or 90 days (#5493)
- Support displaying RTF content (including encapsulated HTML) from a TNEF attachment
- Newmail_notifier: Improved the notification sound (#8155)
- Add option to control links handling behavior on html to text conversion (#6485)
Expand Down
3 changes: 2 additions & 1 deletion config/defaults.inc.php
Expand Up @@ -1317,7 +1317,8 @@
// Set to -1 if messages should not be marked as read
$config['mail_read_time'] = 0;

// Clear Trash on logout
// Clear Trash on logout. Remove all messages or only older than N days.
// Supported values: false, true, 30, 60, 90. Default: false.
$config['logout_purge'] = false;

// Compact INBOX on logout
Expand Down
20 changes: 18 additions & 2 deletions program/actions/settings/index.php
Expand Up @@ -1416,11 +1416,27 @@ public static function user_prefs($current = null)
}

$field_id = 'rcmfd_logout_purge';
$input = new html_checkbox(['name' => '_logout_purge', 'id' => $field_id, 'value' => 1]);
$select = new html_select([
'name' => '_logout_purge',
'id' => $field_id,
'class' => 'custom-select'
]);

$select->add($rcmail->gettext('never'), 'never');
$select->add($rcmail->gettext('allmessages'), 'all');

foreach ([30, 60, 90] as $days) {
$select->add($rcmail->gettext(['name' => 'olderxdays', 'vars' => ['x' => $days]]), (string) $days);
}

$purge = (string) $config['logout_purge'];
if (!is_numeric($purge)) {
$purge = empty($purge) ? 'never' : 'all';
}

$blocks['maintenance']['options']['logout_purge'] = [
'title' => html::label($field_id, rcube::Q($rcmail->gettext('logoutclear'))),
'content' => $input->show($config['logout_purge']?1:0),
'content' => $select->show($purge),
];
}

Expand Down
9 changes: 8 additions & 1 deletion program/actions/settings/prefs_save.php
Expand Up @@ -134,7 +134,7 @@ public function run($args = [])
'skip_deleted' => isset($_POST['_skip_deleted']),
'flag_for_deletion' => isset($_POST['_flag_for_deletion']),
'delete_junk' => isset($_POST['_delete_junk']),
'logout_purge' => isset($_POST['_logout_purge']),
'logout_purge' => self::prefs_input('logout_purge', '/^(all|never|30|60|90)$/'),
'logout_expunge' => isset($_POST['_logout_expunge']),
];

Expand Down Expand Up @@ -235,6 +235,13 @@ public function run($args = [])

$storage->set_special_folders($specials);

break;

case 'server':
if (isset($a_user_prefs['logout_purge']) && !is_numeric($a_user_prefs['logout_purge'])) {
$a_user_prefs['logout_purge'] = $a_user_prefs['logout_purge'] !== 'never';
}

break;
}

Expand Down
12 changes: 11 additions & 1 deletion program/include/rcmail.php
Expand Up @@ -1039,7 +1039,17 @@ public function logout_actions()
$trash_mbox = $this->config->get('trash_mbox');

if ($logout_purge && !empty($trash_mbox)) {
$storage->clear_folder($trash_mbox);
$messages = '*';

if (is_numeric($logout_purge)) {
$now = new DateTime('now');
$interval = new DateInterval('P' . intval($logout_purge) . 'D');

$index = $storage->search_once($trash_mbox, 'BEFORE ' . $now->sub($interval)->format('j-M-Y'));
$messages = $index->get_compressed();
}

$storage->delete_message($messages, $trash_mbox);
}

if ($logout_expunge) {
Expand Down
2 changes: 1 addition & 1 deletion program/lib/Roundcube/rcube_storage.php
Expand Up @@ -713,7 +713,7 @@ public function expunge_folder($folder = null, $clear_cache = true)
}

/**
* Remove all messages in a folder..
* Remove all messages in a folder.
*
* @param string $folder Folder name
*
Expand Down
2 changes: 2 additions & 0 deletions program/localization/en_US/labels.inc
Expand Up @@ -630,6 +630,8 @@ $labels['asattachment'] = 'as attachment';
$labels['replyallmode'] = 'Default action of [Reply all] button';
$labels['replyalldefault'] = 'reply to all';
$labels['replyalllist'] = 'reply to mailing list only (if found)';
$labels['allmessages'] = 'all messages';
$labels['olderxdays'] = 'older than $x days';

$labels['folder'] = 'Folder';
$labels['folders'] = 'Folders';
Expand Down
16 changes: 12 additions & 4 deletions tests/Browser/Settings/Preferences/ServerTest.php
Expand Up @@ -20,7 +20,7 @@ public function testServer()
'flag_for_deletion' => false,
'skip_deleted' => false,
'delete_junk' => false,
'logout_purge' => false,
'logout_purge' => 'never',
'logout_expunge' => false,
];

Expand Down Expand Up @@ -74,8 +74,11 @@ public function testServer()
$browser->assertSeeIn('legend', 'Maintenance');

$browser->assertSeeIn('label[for=rcmfd_logout_purge]', 'Clear Trash on logout')
->assertCheckboxState('_logout_purge', $this->settings['logout_purge'])
->setCheckboxState('_logout_purge', $this->settings['logout_purge'] = !$this->settings['logout_purge']);
->assertVisible('select[name=_logout_purge]')
->assertSelected('select[name=_logout_purge]', $this->settings['logout_purge']);

$this->settings['logout_purge'] = '30';
$browser->select('select[name=_logout_purge]', '30');

$browser->assertSeeIn('label[for=rcmfd_logout_expunge]', 'Compact Inbox on logout')
->assertCheckboxState('_logout_expunge', $this->settings['logout_expunge'])
Expand All @@ -97,7 +100,12 @@ public function testServer()
// Verify if every option has been updated
$browser->withinFrame('#preferences-frame', function ($browser) {
foreach ($this->settings as $key => $value) {
$browser->assertCheckboxState('_' . $key, $value);
if (is_bool($value)) {
$browser->assertCheckboxState('_' . $key, $value);
}
else {
$browser->assertValue("[name=_{$key}]", $value);
}
}
});
});
Expand Down

0 comments on commit d7338a4

Please sign in to comment.