Wednesday, November 12, 2014

Zimbra email retention under 30 days

Normally, zimbra COS can allocate only at least 30 Days and more of email retention, and if lower than 30 days is required, COS is not capable. (Well, you may correct my if I am wrong)

Below is a sample script to do the Job.

1. Create a zimbra distro list that will become the bases of user list that have a threshold. For example, 7days_users@list.example.com is the distro, member of this will have a retention of 7 days.

2. The script.

#!/bin/bash
#Generate the members of 7days_users and pipe it on a temp file.
zmprov gdlm 7days_users@list.example.com |egrep -v '^#|members' > /tmp/_TMP7days
#
for USER in `cat /tmp/_TMP7days`
do
zmmailbox -z -m $USER s -t message -l 1000  "before:`date +%x --date="7 days ago"`" |grep mess |awk '{print $2}' > /tmp/7days_$USER
done
##delete ID
for UserName in `cat /tmp/_TMP7days`
do
for MAILID in `cat /tmp/7days_$UserName`
do
zmmailbox -z -m $UserName dm $MAILID
done
done
#end of script