Issue :

Emails older than a year need to be deleted automatically.

Solution
:

You can use ‘find’ against the standard mail folders :

find -P /home/*/mail/*/*/cur -mtime ‘+365’
find -P /home/*/mail/*/*/new -mtime ‘+365’

Note : 365 is the number of days in a year. You can change this number as per your requirement.

This will give you a list of old mails which can be piped into a file. Then have a script parse this file.
A simple example :

#!/bin/bash
IFS=”$”

cd /home

find -P /home/*/mail/*/*/* -mindepth 1 -maxdepth 1 -mtime ‘+365’ | while read EMAIL; do
echo “Deleting ${EMAIL} …”
rm -f “${OLDMAIL}”
done

You can remove the ‘echo’ line and add the code to a cronjob to have your server delete old emails automatically.


Shares
Contact Us On WhatsApp