scripts/cleanmaildir.sh
2023-08-10 21:47:21 +02:00

24 lines
652 B
Bash
Executable file

#!/bin/sh
#
# simple shell script to clean some subdirectories of a maildir
#
# format of $etcfile is:
# dirname1,maxdays
# dirname2,maxdays
# etc...
# (one line by subdir to clean)
#
# were dirname* is the name of the subdirectory to clean,
# and maxdays is the maximum number of days before a message is deleted
#
# put it in the user's crontab:
# 50 * * * * /path/to/cleanmaildir
etcfile=/usr/local/etc/cleanmaildir.conf
grep -v '^#' < $etcfile | while IFS= read -r i
do
dir=$(echo "$i" | cut -f 1 -d ,)
time=$(echo "$i" | cut -f 2 -d ,)
find "$HOME/Maildir/$dir/cur/" -type f -mtime +$(( time - 1)) -exec rm '{}' \;
done