Below is some code I have been playing with in a test environment. It will move unread email that is older then x number of days to the users /Trash folder for the system to clean up later.
I use three mailbox servers so I have designed the code to run on all three machines.
I strongly suggest making a backup before running. Use the following code at your own risk. I take no responsibility. You have been warned.
Code:
#!/bin/bash
#Move unread mail older then givendate from users mailboxes to /Trash
#Make a backup before running.
#
#USE AT YOUR OWN RISK!
#
emaildomain="enter_email_domain_here"
days=$(date -d $1' days ago' '+%D')
hn=`hostname`"."`dnsdomainname`
who=`whoami`
if [ "$who" != "zimbra" ]
then
echo
echo "Please su to the zimbra user before running this script"
echo
exit
fi
if [ -z "$1" ]; then
echo
echo -e "\nUsage: deletemail <number of days ago>"
echo
exit
fi
echo "Deleting messages older then $days"
echo "Building user list for $hn"
zmprov gqu $hn | grep $emaildomain |cut -f 1 -d' '> /tmp/del-$hn.tmp
echo "Moving mail to /Trash"
for x in $(tail -1 /tmp/del-$hn.tmp)
do
echo "Currently working on: $x"
for y in $(zmmailbox -z -m $x search -t message -l 9999 "(before:$days)(is:unread)"|awk {'print $2'}|grep [0-9]|grep -v ,)
do
zmmailbox -z -m $x mm $y "/Trash"
zmmailbox -z -m $x fm $y 1
done
done