From d2222145214efff155495dd765c6e239233674a1 Mon Sep 17 00:00:00 2001 From: Asif Bacchus Date: Fri, 28 Jun 2019 04:42:01 -0600 Subject: [PATCH] --- 1.-mail_cleanup.sh.md | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 1.-mail_cleanup.sh.md diff --git a/1.-mail_cleanup.sh.md b/1.-mail_cleanup.sh.md new file mode 100644 index 0000000..bb6bc9b --- /dev/null +++ b/1.-mail_cleanup.sh.md @@ -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.