diff options
author | Aleksander Machniak <alec@alec.pl> | 2021-10-09 17:55:28 +0300 |
---|---|---|
committer | Aleksander Machniak <alec@alec.pl> | 2021-10-09 17:55:28 +0300 |
commit | 81cc8ac0e0bc3b524122f62c3d024ed843c3bb2b (patch) | |
tree | e9806822c060264eb4a66f9ff8323ce3a815273c /program/include | |
parent | 318d6d08597bbfe481e01bf989150faa8c0403e5 (diff) |
Purge also subfolders of Trash (and/or messages in them) on logout (#1037)
Diffstat (limited to 'program/include')
-rw-r--r-- | program/include/rcmail.php | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/program/include/rcmail.php b/program/include/rcmail.php index 117df750e..f88626570 100644 --- a/program/include/rcmail.php +++ b/program/include/rcmail.php @@ -1039,17 +1039,40 @@ class rcmail extends rcube $trash_mbox = $this->config->get('trash_mbox'); if ($logout_purge && !empty($trash_mbox)) { - $messages = '*'; + $getMessages = function ($folder) use ($logout_purge, $storage) { + if (is_numeric($logout_purge)) { + $now = new DateTime('now'); + $interval = new DateInterval('P' . intval($logout_purge) . 'D'); - if (is_numeric($logout_purge)) { - $now = new DateTime('now'); - $interval = new DateInterval('P' . intval($logout_purge) . 'D'); + return $storage->search_once($folder, 'BEFORE ' . $now->sub($interval)->format('j-M-Y')); + } - $index = $storage->search_once($trash_mbox, 'BEFORE ' . $now->sub($interval)->format('j-M-Y')); - $messages = $index->get_compressed(); - } + return '*'; + }; + + $storage->delete_message($getMessages($trash_mbox), $trash_mbox); + + // Trash subfolders + $delimiter = $storage->get_hierarchy_delimiter(); + $subfolders = array_reverse($storage->list_folders('', $trash_mbox . $delimiter . '*')); + $last = ''; - $storage->delete_message($messages, $trash_mbox); + foreach ($subfolders as $folder) { + $messages = $getMessages($folder); + + // Delete the folder if in all-messages mode, or all existing messages are to-be-removed, + // but not if there's a subfolder + if ( + ($messages === '*' || $messages->count() == $storage->count($folder, 'ALL', false, false)) + && strpos($last, $folder . $delimiter) !== 0 + ) { + $storage->delete_folder($folder); + } + else { + $storage->delete_message($messages, $folder); + $last = $folder; + } + } } if ($logout_expunge) { |