scripts/cleanmaildir.sh

25 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