Asif Bacchus 2019-06-28 04:42:01 -06:00
parent 703bdc0926
commit d222214521

48
1.-mail_cleanup.sh.md Normal file

@ -0,0 +1,48 @@
# mail_cleanup.sh
## Purpose
This script deletes messages in the *Junk* and *Trash* folders for all users that are older than a specified number of days. Different timeframes can be specified for the following three scenarios:
1. Messages that are read but are still in the JUNK folder.
2. Messages in the JUNK folder regardless of their status (read, unread, etc.)
3. Messages in the TRASH folder, regardless of their status.
## Usage
The script accepts 4 parameters with 3 being mandatory. The basic usage is as follows:
```
./mail_cleanup.sh --junk-read x --junk-all y --trash z [-p|--path|--mailcow-path path]
```
In the above:
| variable | meaning |
| -------- | -------- |
| x | Delete messages in the JUNK folder that are read but older than this number of days |
| y | Delete messages in the JUNK folder, regardless of their status, that are older than this number of days |
| z | Delete messages in the TRASH folder, regardless of status, that are older than this number of days |
| path | The path to your *mailcow-dockerized* installation directory. By default, this is */opt/mailcow-dockerized* |
Please note that when specifying the path to your *mailcow-dockerized* installation, you can use any of the switches *-p*, *--path* or *--mailcow-path*
## Examples
Delete read messages in the junk folder that are older than 7 days, all messages in the junk folder that are older than 14 days and all messages in the trash folder that are older than 30 days:
```
./mail_cleanup.sh --junk-read 7 --junk-all 14 --trash 30
```
Same as above, but *mailcow-dockerized* is located in a non-default location, say */var/mailcow*:
```
./mail_cleanup.sh --junk-read 7 --junk-all 14 --trash 30 --path /var/mailcow
```
## Script notes
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.