Asif Bacchus 2019-06-28 04:52:20 -06:00
parent d222214521
commit 2e6829cbea
1 changed files with 44 additions and 0 deletions

44
2.-mail_prune.sh.md Normal file

@ -0,0 +1,44 @@
## Purpose
This script deletes messages in **all** folders for all users that are older than a specified number of days *except* for those messages that are either *unread* and/or *flagged*.
## Usage
The script accepts 2 parameters with 1 being mandatory. The basic usage is as follows:
```
./mail_prune.sh -d|--days x [-p|--path|--mailcow-path path]
```
In the above:
| variable | meaning |
| -------- | --------|
| -d<br>--days | Delete messages older than this many days |
| path | The path to your *mailcow-dockerized* installation directory. By default, this is */opt/mailcow-dockerized* |
**Please note:**
* When specifying the number of days, you can use any of the switches *-d* or *--days*
* When specifying the path to your *mailcow-dockerized* installation, you can use any of the switches *-p*, *--path* or *--mailcow-path*
## Examples
Delete messages that are read and unflagged for all users in all folders that are older than 366 days:
```
./mail_prune.sh --days 366
```
Same as above, but *mailcow-dockerized* is located in a non-default location, say */var/mailcow*:
```
./mail_prune.sh --days 366 --path /var/mailcow
```
## Script notes
**Most important: Regardless of age, this script will not remove any message that is either *unread* or *flagged*.**
Because this script is meant to run via CRON, there is not much in the way of error-trapping or user feedback. Specifically, any failures in the *doveadm* command will not be logged to the console or otherwise stop the script from executing. You would have to check the docker container logs for details on any errors. The script only checks that all parameters have values and that it is possible to change to your specified *mailcow-dockerized* directory -- not that it is necessarily the correct directory.
Because of this lack of error-checking, you may want to run this script manually and check the results in the docker container logs before running it as a cron job.